1function AdSlot(_name, _type, _time, _zone) { 2 this.name = _name; 3 this.type = _type; 4 this.time = _time; 5 this.zone = _zone; 6 this.source = ""; 7 this.seen = false; 8 this.playOnce = true; 9} 10 11 12 13function convertTimeFormat(hhmmss) { 14 var _time = hhmmss.substr(0, 1) * 3600 + hhmmss.substr(3, 2) * 60 + hhmmss.substr(6, 2) * 1; 15 return _time 16} 17 18function constructAdList(responseObj) { 19 for (v in AdList) { 20 if (AdList[v].type.indexOf("roll") + 1) { 21 var adElement = responseObj.getElementById(AdList[v].name); 22 MediaFiles = adElement.getElementsByTagName("MediaFiles"); 23 URL = MediaFiles[0].getElementsByTagName("URL"); 24 if (URL[0] == undefined) { 25 URL = MediaFiles[0].getElementsByTagName("MediaFile"); 26 } 27 AdList[v].source = URL[0].childNodes[0].data; 28 } 29 } 30 videoTag.addEventListener('timeupdate', showAdSlots, false); 31} 32 33 34// Loading ads data from defined server 35AdsRequest = function(AdObj, cc) { 36 37 var http_request = new XMLHttpRequest(); 38 var script = "bannerTypeHtml:vastInlineBannerTypeHtml:vastInlineHtml"; 39 40 //constructing list for further populating and sorting 41 42 var i1 = 0; 43 var i2 = 0; 44 var i3 = 0; 45 var i4 = 0; 46 var zones = ""; 47 for (v in AdObj.schedule) { 48 switch (AdObj.schedule[v].position) { 49 case "pre-roll": 50 var a = new AdSlot("pre-roll-" + i1, "pre-roll", 0, AdObj.schedule[v].zone); 51 i1++; 52 AdList.push(a); 53 54 break 55 case "mid-roll": 56 var a = new AdSlot("mid-roll-" + i2, "mid-roll", convertTimeFormat(AdObj.schedule[v].startTime), AdObj.schedule[v].zone); 57 i2++; 58 AdList.push(a); 59 break 60 case "post-roll": 61 var a = new AdSlot("post-roll-" + i3, "post-roll", 0, AdObj.schedule[v].zone); 62 i3++; 63 AdList.push(a); 64 break 65 case "auto:bottom": 66 var a = new AdSlot("auto:bottom-" + i4, "auto:bottom", convertTimeFormat(AdObj.schedule[v].startTime), AdObj.schedule[v].zone); 67 i4++; 68 AdList.push(a); 69 break 70 default: 71 break 72 } 73 } 74 videoTag.addEventListener("canplay", setPostRollTime, false); 75 videoTag.load(); 76 77 for (v in AdList) { 78 zones += AdList[v].name + "=" + AdList[v].zone + "|"; 79 } 80 zones = zones.substr(0, zones.length - 1) 81 console.log(zones); 82 83 var nz = "1"; 84 var format = "vast"; 85 var charset = "UTF-8"; 86 var params = "script=" + script + "&zones=" + encodeURIComponent(zones) + "&nz=" + nz + "&format=" + format + "&charset=" + charset; 87 88 http_request.open("GET", AdObj.servers[0]["apiAddress" + cc], true); 89 http_request.send(null); 90 http_request.onreadystatechange = function() { 91 if (http_request.readyState == 4) { 92 if (http_request.status == 200) { 93 var xml = http_request.responseXML; 94 constructAdList(xml); 95 } 96 http_request = null; 97 } 98 } 99 100}; 101 102 103 104function showSlot(slot) { 105 if ($("#videoads1").val() && moment($('#videoads1-exp').val()).isAfter(moment().format('MM/DD/YYYY'))) { 106 $(".skipBtn").show().addClass("disabled"); 107 videoTag.src = $("#videoads1").val(); 108 videoTag.play(); 109 var intervalAd = setInterval(function() { 110 if ($('#example_video_1').get(0).currentTime > 1) { 111 $(".regisBtn").removeClass("disabled"); 112 $(".regisBtn").attr("href", $("#videoads1-link").val()); 113 114 } 115 if ($('#example_video_1').get(0).currentTime > $("#timeskip").val()) { 116 $(".skipBtn").removeClass("disabled"); 117 $(".skipBtn").click(function() { 118 if ($("#videoads2").val()) { 119 showSlot2(); 120 } else { 121 resumePlayBackAfterSlotShow(); 122 } 123 }); 124 clearInterval(intervalAd); 125 } 126 }, 100); 127 // console.log(slot); 128 if ($("#videoads2").val()) { 129 videoTag.addEventListener('ended', showSlot2, false); 130 } else { 131 videoTag.addEventListener('ended', resumePlayBackAfterSlotShow, false); 132 } 133 134 } else { 135 if ($("#videoads2").val()) { 136 showSlot2(); 137 } else { 138 videoTag.addEventListener('ended', resumePlayBackAfterSlotShow, false); 139 } 140 } 141} 142 143function showSlot2() { 144 if ($("#videoads2").val() && moment($('#videoads2-exp').val()).isAfter(moment().format('MM/DD/YYYY'))) { 145 $(".skipBtn").show().addClass("disabled"); 146 videoTag.src = $("#videoads2").val(); 147 videoTag.play(); 148 var intervalAd = setInterval(function() { 149 if ($('#example_video_1').get(0).currentTime > 1) { 150 $(".regisBtn").removeClass("disabled"); 151 $(".regisBtn").attr("href", $("#videoads2-link").val()); 152 153 } 154 if ($('#example_video_1').get(0).currentTime > $("#timeskip").val()) { 155 $(".skipBtn").removeClass("disabled"); 156 $(".skipBtn").click(function() { 157 if ($("#videoads3").val()) { 158 showSlot3(); 159 } else { 160 resumePlayBackAfterSlotShow(); 161 } 162 }); 163 clearInterval(intervalAd); 164 } 165 }, 100); 166 // console.log(slot); 167 if ($("#videoads3").val()) { 168 videoTag.addEventListener('ended', showSlot3, false); 169 } else { 170 videoTag.addEventListener('ended', resumePlayBackAfterSlotShow, false); 171 } 172 173 } else { 174 if ($("#videoads3").val()) { 175 showSlot3(); 176 } else { 177 videoTag.addEventListener('ended', resumePlayBackAfterSlotShow, false); 178 } 179 } 180 181} 182 183function showSlot3() { 184 if ($("#videoads3").val() && moment($('#videoads3-exp').val()).isAfter(moment().format('MM/DD/YYYY'))) { 185 $(".skipBtn").show().addClass("disabled"); 186 videoTag.src = $("#videoads3").val(); 187 videoTag.play(); 188 var intervalAd = setInterval(function() { 189 if ($('#example_video_1').get(0).currentTime > 1) { 190 $(".regisBtn").removeClass("disabled"); 191 $(".regisBtn").attr("href", $("#videoads3-link").val()); 192 193 } 194 if ($('#example_video_1').get(0).currentTime > $("#timeskip").val()) { 195 $(".skipBtn").removeClass("disabled"); 196 $(".skipBtn").click(function() { 197 if ($("#videoads4").val()) { 198 showSlot4(); 199 } else { 200 resumePlayBackAfterSlotShow(); 201 } 202 }); 203 clearInterval(intervalAd); 204 } 205 }, 100); 206 // console.log(slot); 207 if ($("#videoads4").val()) { 208 videoTag.addEventListener('ended', showSlot4, false); 209 } else { 210 videoTag.addEventListener('ended', resumePlayBackAfterSlotShow, false); 211 } 212 213 } else { 214 if ($("#videoads4").val()) { 215 showSlot4(); 216 } else { 217 videoTag.addEventListener('ended', resumePlayBackAfterSlotShow, false); 218 } 219 } 220} 221 222function showSlot4() { 223 if ($("#videoads4").val() && moment($('#videoads4-exp').val()).isAfter(moment().format('MM/DD/YYYY'))) { 224 $(".skipBtn").show().addClass("disabled"); 225 videoTag.src = $("#videoads4").val(); 226 videoTag.play(); 227 var intervalAd = setInterval(function() { 228 if ($('#example_video_1').get(0).currentTime > 1) { 229 $(".regisBtn").removeClass("disabled"); 230 $(".regisBtn").attr("href", $("#videoads4-link").val()); 231 232 } 233 if ($('#example_video_1').get(0).currentTime > $("#timeskip").val()) { 234 $(".skipBtn").removeClass("disabled"); 235 $(".skipBtn").click(function() { 236 237 resumePlayBackAfterSlotShow(); 238 239 }); 240 clearInterval(intervalAd); 241 } 242 }, 100); 243 // console.log(slot); 244 245 videoTag.addEventListener('ended', resumePlayBackAfterSlotShow, false); 246 247 248 } else { 249 250 videoTag.addEventListener('ended', resumePlayBackAfterSlotShow, false); 251 252 } 253 254} 255 256
257function initAdsFor(videoID) { 258 window.tempTime = 0; 259 260 window.counterOfStreams = 0; 261 window.videoTag = document.getElementById(videoID); 262 videoTag.mainTrack = videoTag.src; 263 window.AdList = new Array; 264 265 266 window.AdObj = parseAdsParameters(videoTag.getAttribute('ads')); 267 window.AdObj2 = parseAdsParameters(videoTag.getAttribute('ads2')); 268 window.AdObj3 = parseAdsParameters(videoTag.getAttribute('ads3')); 269 window.AdObj4 = parseAdsParameters(videoTag.getAttribute('ads4')); 270 271 window.AdsRequest(AdObj, 1); 272 // window.AdsRequest(AdObj2, 2); 273 // window.AdsRequest(AdObj2); 274 // window.AdsRequest(AdObj3); 275 // window.AdsRequest(AdObj4); 276 277} 278//Parsing parameters from video tag 279parseAdsParameters = function(input) { 280 var AdObj = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(input.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + input + ')'); 281 return AdObj; 282} 283 284function enforcePrecision(n, nDecimalDigits) { 285 return +(n).toFixed(nDecimalDigits); 286} 287 288function seekToOriginalPoint() { 289 videoTag.removeEventListener('canplaythrough', seekToOriginalPoint, false); 290 videoTag.removeEventListener('load', seekToOriginalPoint, false); 291 videoTag.currentTime = enforcePrecision(tempTime, 1); 292 videoTag.play(); 293 videoTag.addEventListener('timeupdate', showAdSlots, false); 294} 295 296function resumePlayBackAfterSlotShow() { 297 videoTag.removeEventListener('ended', resumePlayBackAfterSlotShow, false); 298 $(".skipBtn").hide(); 299 $(".regisBtn").hide(); 300 videoTag.src = videoTag.mainTrack; 301 videoTag.play(); 302 303 if (videoTag.readyState !== 4) { //HAVE_ENOUGH_DATA 304 videoTag.addEventListener('canplaythrough', seekToOriginalPoint, false); 305 videoTag.addEventListener('load', seekToOriginalPoint, false); //add load event as well to avoid errors, sometimes 'canplaythrough' won't dispatch. 306 videoTag.pause(); 307 } 308} 309 310 311function slotForCurrentTime(currentTime) { 312 for (v in AdList) { 313 if (!AdList[v].seen) { 314 if (AdList[v].time == currentTime) { 315 return AdList[v]; 316 } 317 } 318 } 319 return null; 320 321} 322 323function showAdSlots() { 324 325 var slot = slotForCurrentTime(Math.floor(videoTag.currentTime)); 326 if (slot) { 327 slot.seen = true; 328 tempTime = videoTag.currentTime; 329 videoTag.removeEventListener('timeupdate', showAdSlots, false); 330 showSlot(slot); 331 332 333 } 334 335} 336 337function setPostRollTime() { 338 videoTag.removeEventListener("canplay", setPostRollTime, false); 339 for (v in AdList) { 340 if (AdList[v].type == "post-roll") { 341 AdList[v].time = Math.floor(videoTag.duration); 342 } 343 } 344}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.