|
1 | | -<script src="mraid.js" type="text/javascript"></script> |
| 1 | +<!-- This IAB MRAID test creative was built by Adam Schuetz, currently Senior Director of Engineering at AdMarvel on 04/14/2014 --> |
| 2 | + |
| 3 | +<script src="mraid.js"></script> |
| 4 | + |
2 | 5 | <div id="container" style="width:100%;height:100%;background-color:#000000;"> |
3 | | - <video id="adVideo" webkit-playsinline src="http://once.unicornmedia.com/now/od/auto/d8371d05-0b04-42fc-892f-b0e9ad6db2b5/6fd31a0f-775a-49ca-849b-228d70b5f9ac/87c56e71-2005-473c-a8da-2d45053413a9/578-1588-iab-video-small.mp4"></video> |
| 6 | + <video id="adVideo" webkit-playsinline src="http://once.unicornmedia.com/now/od/auto/d8371d05-0b04-42fc-892f-b0e9ad6db2b5/6fd31a0f-775a-49ca-849b-228d70b5f9ac/87c56e71-2005-473c-a8da-2d45053413a9/578-1588-iab-video-small.mp4"></video> |
4 | 7 | </div> |
5 | 8 |
|
6 | 9 | <style type="text/css"> |
|
12 | 15 |
|
13 | 16 | <script language="javascript" type="text/javascript"> |
14 | 17 | document.getElementById("container").addEventListener('touchmove', function(event) { event.preventDefault(); }, false); |
| 18 | +</script> |
15 | 19 |
|
| 20 | +<script> |
16 | 21 | function mraidIsReady() |
17 | 22 | { |
18 | 23 | mraid.removeEventListener("ready", mraidIsReady); |
@@ -110,43 +115,44 @@ function viewableChangeAfterDisplay(visible) |
110 | 115 |
|
111 | 116 | function showMyAd() |
112 | 117 | { |
113 | | - // Adjust dimensions for device using current orientation to find landscape values |
114 | | - var screenSize = mraid.getScreenSize(); |
115 | | - logMRAIDMessage("Reported screen size: width = " + screenSize.width + ", height = " + screenSize.height); |
116 | | - var screenLandscapeWidth = screenSize.width; |
117 | | - var screenLandscapeHeight = screenSize.height; |
118 | | - document.getElementById("container").style.width = screenLandscapeWidth + "px"; |
119 | | - document.getElementById("container").style.height = screenLandscapeHeight + "px"; |
| 118 | + // Adjust dimensions to current position width/height. Since this is being called on display this should represent the size of the ad after locking to landscape orientation. |
| 119 | + var currentPosition = mraid.getCurrentPosition(); |
| 120 | + var landscapeWidth = currentPosition.width; |
| 121 | + var landscapeHeight = currentPosition.height; |
| 122 | + logMRAIDMessage("Reported current ad size: width = " + landscapeWidth + ", height = " + landscapeHeight); |
| 123 | + |
| 124 | + document.getElementById("container").style.width = landscapeWidth + "px"; |
| 125 | + document.getElementById("container").style.height = landscapeHeight + "px"; |
120 | 126 |
|
121 | 127 | // First video to fit full width and and then scale height |
122 | 128 | var videoWidth = 320; |
123 | 129 | var videoHeight = 180; |
124 | 130 | var videoRatio = videoWidth/videoHeight; |
125 | 131 | var newWidth = videoWidth; |
126 | 132 | var newHeight = videoHeight; |
127 | | - if(videoWidth > screenLandscapeWidth) |
| 133 | + if(videoWidth > landscapeWidth) |
128 | 134 | { |
129 | | - newWidth = screenLandscapeWidth; |
| 135 | + newWidth = landscapeWidth; |
130 | 136 | newHeight = newWidth/videoRatio; |
131 | 137 | } |
132 | 138 | else |
133 | 139 | { |
134 | | - newWidth = Math.max(screenLandscapeWidth, videoWidth); |
| 140 | + newWidth = Math.max(landscapeWidth, videoWidth); |
135 | 141 | newHeight = newWidth/videoRatio; |
136 | 142 | } |
137 | 143 |
|
138 | 144 | // If scaled height too big then scale back until it fits |
139 | | - if (newHeight > screenLandscapeHeight) |
| 145 | + if (newHeight > landscapeHeight) |
140 | 146 | { |
141 | 147 | videoRatio = videoHeight/videoWidth; |
142 | 148 |
|
143 | | - newHeight = screenLandscapeHeight; |
| 149 | + newHeight = landscapeHeight; |
144 | 150 | newWidth = newHeight/videoRatio; |
145 | 151 | } |
146 | 152 |
|
147 | 153 | // Calculate margins to center |
148 | | - var topBottomMargins = (screenLandscapeHeight - newHeight)/2.0; |
149 | | - var leftRightMargins = (screenLandscapeWidth - newWidth)/2.0; |
| 154 | + var topBottomMargins = (landscapeHeight - newHeight)/2.0; |
| 155 | + var leftRightMargins = (landscapeWidth - newWidth)/2.0; |
150 | 156 |
|
151 | 157 | // Update video dimensions |
152 | 158 | var video = document.getElementById("adVideo"); |
|
0 commit comments