1(function(){ 2 3 // Check for jquery 4 if(jQuery == undefined){ 5 console.log("Jquery not included!"); 6 return; 7 } 8 9 if(Modernizr.video == undefined){ 10 console.log("Modernizr not included!"); 11 return; 12 } 13 14 var $ = jQuery; 15 16 //IS IE 17 function isIE_fun () { 18 var myNav = navigator.userAgent.toLowerCase(); 19 return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false; 20 } 21 var isIE = isIE_fun(); 22 23 var players = 0; 24 var youtube_api_state = 0; 25 26 //Jquery extend ensure load for images (caching issue) 27 jQuery.fn.extend({ 28 ensureLoad: function(handler) { 29 return this.each(function() { 30 if(this.complete || this.readyState === 4) { 31 handler.call(this); 32 } 33 // Check if data URI images is supported, fire 'error' event if not 34 else if ( this.readyState === 'uninitialized' && this.src.indexOf('data:') === 0 ) { 35 $(this).trigger('error'); 36 handler.call(this); 37 } 38 else { 39 $(this).one("load", handler); 40 41 if(isIE && this.src != undefined && this.src.indexOf("?") == -1){ 42 this.src = this.src+ "?" + new Date().getTime(); 43 } 44 45 } 46 }); 47 } 48 }); 49 50 51 // Video Background call 52 video_background = function($holder, in_parameters){ 53 this.hidden = false; 54 this.$holder = $holder; 55 56 this.id = "video_background_video_"+players; 57 players++; 58 59 60 // Parameters 61 this.parameters = { 62 "position": "absolute", 63 "z-index": "-1", 64 "video_ratio": false, 65 "loop": true, 66 "autoplay": true, 67 "muted": false, 68 "mp4": false, 69 "webm": false, 70 "ogg": false, 71 "flv": false, 72 "youtube": false, 73 "priority": "html5", // flash || html5 74 "fallback_image": false, 75 "sizing": "fill", // fill || adjust 76 "start": 0 77 }; 78 79 //Over ride parameters from user options 80 $.each(in_parameters, $.proxy(function(index, obj){ 81 this.parameters[index] = obj; 82 }, this)); 83 84 85 86 //video holder 87 this.$video_holder = $('<div id="'+this.id+'"></div>').appendTo($holder).css({ 88 "z-index": this.parameters["z-index"], 89 "position": this.parameters.position, 90 "top":0, "left": 0, "right": 0, "bottom": 0, 91 "overflow": "hidden" 92 }); 93 94 95 this.ismobile=navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i); 96 97 var flash_version = swfobject.getFlashPlayerVersion(); 98 this.supports_flash = flash_version["major"] > 9 && (this.parameters.mp4 !== false || this.parameters.flv !== false); 99 this.supports_video = Modernizr.video && ( (Modernizr.video.h264 && this.parameters.mp4 !== false) || 100 (Modernizr.video.ogg && this.parameters.ogg !== false) || 101 (Modernizr.video.webm && this.parameters.webm !== false) ); 102 103 this.decision = "image"; 104 105 //Decide what to use 106 if(!this.ismobile && (this.supports_flash || this.supports_video || this.parameters.youtube !== false)){ 107 this.decision = this.parameters.priority; 108 if(this.parameters.youtube !== false){ 109 this.decision = "youtube"; 110 } 111 else if(this.parameters.priority == "flash" && this.supports_flash){ 112 this.decision = "flash"; 113 } 114 else if(this.parameters.priority == "html5" && this.supports_video){ 115 this.decision = "html5"; 116 } 117 else if(this.supports_flash){ 118 this.decision = "flash"; 119 } 120 else if(this.supports_video){ 121 this.decision = "html5"; 122 } 123 } 124 125 126 //Image Fallback 127 if(this.decision == "image"){ 128 this.make_image(); 129 } 130 131 //Youtube 132 else if(this.decision == "youtube"){ 133 this.make_youtube(); 134 } 135 136 //Video 137 else{ 138 //Html5 video 139 if(this.decision == "html5"){ 140 this.make_video(); 141 } 142 //Flash 143 else{ 144 this.make_flash(); 145 } 146 } 147 148 return this; 149 } 150 151 video_background.prototype = { 152 153 // Make html5 video 154 make_video: function(){ 155 var parameters = (this.parameters.autoplay ? "autoplay " : "") + (this.parameters.loop ? 'loop onended="this.play()" ' : ""); 156 157 var str = '<video width="100%" height="100%" '+parameters+'>'; 158 159 //mp4 160 if(this.parameters.mp4 !== false){ 161 str += '<source src="'+this.parameters.mp4+'" type="video/mp4"></source>'; 162 } 163 164 //webm 165 if(this.parameters.webm !== false){ 166 str += '<source src="'+this.parameters.webm+'" type="video/webm"></source>'; 167 } 168 169 //mp4 170 if(this.parameters.ogg !== false){ 171 str += '<source src="'+this.parameters.ogg+'" type="video/ogg"></source>'; 172 } 173 str += "</video>"; 174 175 //html5 video tag 176 this.$video = $(str).css({ 177 "position": "absolute" 178 }); 179 180 this.$video_holder.append(this.$video); 181 182 this.video = this.$video.get(0); 183 184 //Fill resize 185 if(this.parameters.video_ratio !== false){ 186 this.resize_timeout = false; 187 188 //On window resize 189 $(window).resize( $.proxy(function(){ 190 clearTimeout(this.resize_timeout); 191 this.resize_timeout = setTimeout($.proxy(this.video_resize, this) , 10); 192 }, this) ) ; 193 194 this.video_resize(); 195 } 196 197 if(this.parameters.muted){ 198 this.mute(); 199 } 200 }, 201 202 video_resize: function(){ 203 var w = this.$video_holder.width(); 204 var h = this.$video_holder.height(); 205 206 var new_width = w; 207 var new_height = w / this.parameters.video_ratio; 208 209 if( new_height < h ){ 210 new_height = h; 211 new_width = h * this.parameters.video_ratio; 212 } 213 214 //Round
215 new_height = Math.ceil(new_height); 216 new_width = Math.ceil(new_width); 217 218 //adjust 219 var top = Math.round( h/2 - new_height/2 ); 220 var left = Math.round( w/2 - new_width/2 ); 221 222 this.$video.attr("width", new_width); 223 this.$video.attr("height", new_height); 224 225 this.$video.css({ 226 "top": top+"px", 227 "left": left+"px" 228 }); 229 }, 230 231 232 233 234 //Make youtube 235 make_youtube: function(){ 236 var $html = $("html"); 237 this.$video = $('<div id="'+this.id+'_yt"></div>').appendTo(this.$video_holder).css({ 238 "position": "absolute" 239 }); 240 241 this.youtube_ready = false; 242 243 if(youtube_api_state == 0){ 244 //Load it 245 var tag = document.createElement('script'); 246 247 tag.src = "https://www.youtube.com/iframe_api"; 248 var firstScriptTag = document.getElementsByTagName('script')[0]; 249 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 250 251 youtube_api_state = 1; 252 253 window.onYouTubeIframeAPIReady = $.proxy(function() { 254 $html.trigger("yt_loaded"); 255 this.build_youtube(); 256 257 youtube_api_state = 2; 258 }, this); 259 } 260 else if(youtube_api_state == 1){ 261 $html.bind("yt_loaded", $.proxy(this.build_youtube, this)); 262 } 263 else if(youtube_api_state == 2){ 264 this.build_youtube(); 265 } 266 267 }, 268 269 build_youtube: function(){ 270 var pars = { 'loop': this.parameters.loop ? 1 : 0, 'start': this.parameters.start, 'autoplay': this.parameters.autoplay ? 1 : 0, 'controls': 0, 'showinfo': 0, 'wmode': 'transparent', 'iv_load_policy': 3, 'modestbranding':1, 'rel':0}; 271 272 if(this.parameters.loop){ 273 pars['playlist'] = this.parameters.youtube; 274 } 275 276 this.player = new YT.Player(this.id+"_yt", { 277 height: '100%', 278 width: '100%', 279 playerVars: pars, 280 videoId: this.parameters.youtube, 281 events: { 282 'onReady': $.proxy(this.youtube_ready_fun, this) 283 } 284 }); 285 }, 286 287 youtube_ready_fun: function(event) { 288 this.youtube_ready = true; 289 290 this.$video = $("#"+this.id+"_yt"); 291 292 //Fill resize 293 if(this.parameters.video_ratio !== false){ 294 this.resize_timeout = false; 295 296 //On window resize 297 $(window).resize( $.proxy(function(){ 298 clearTimeout(this.resize_timeout); 299 this.resize_timeout = setTimeout($.proxy(this.video_resize, this) , 10); 300 }, this) ) ; 301 302 this.video_resize(); 303 } 304 305 306 if(this.parameters.muted){ 307 this.mute(); 308 } 309 310 //this.player.setPlaybackQuality("highres"); 311 }, 312 313 314 315 316 317 // Make flash video 318 make_flash: function(){ 319 var flashvars = { 320 "url" : (this.parameters.mp4 != false ? this.parameters.mp4 : this.parameters.flv), 321 "loop" : this.parameters.loop, 322 "autoplay" : this.parameters.autoplay, 323 "muted" : this.parameters.muted 324 }; 325 326 this.$video_holder.append('<div id="'+this.id+'_flash"></div>'); 327 328 swfobject.embedSWF("flash/video.swf", this.id+"_flash", "100%", "100%", "9.0", null, flashvars, {allowfullscreen:true, allowScriptAccess:"always", wmode:"transparent"}, { name:"background-video-swf" }, $.proxy(this.flash_callback, this)); 329 }, 330 331 flash_callback: function(e) { 332 this.video = $(e.target).get(0);//document.getElementById(e.id); 333 334 if(this.parameters.muted){ 335 this.mute(); 336 } 337 }, 338 339 340 341 // Make image 342 make_image: function(){ 343 if(this.parameters.fallback_image === false){ 344 return; 345 } 346 347 // Make image fallback 348 this.$video_holder.css('background-image', 'url('+this.parameters.fallback_image+')').addClass('fallback-img'); 349 // //Make image 350 // this.$img = $('<img src="'+this.parameters.fallback_image+'" alt=""/>').appendTo(this.$video_holder).css({ 351 // "position":"absolute" 352 // }); 353 354 // // On Image load 355 // this.$img.ensureLoad( $.proxy(this.image_loaded, this) ); 356 }, 357 358 image_loaded: function(){ 359 this.original_width = this.$img.width(); 360 this.original_height = this.$img.height(); 361 362 this.resize_timeout = false; 363 364 //On window resize 365 $(window).resize( $.proxy(function(){ 366 clearTimeout(this.resize_timeout); 367 this.resize_timeout = setTimeout($.proxy(this.image_resize, this) , 10); 368 }, this) ) ; 369 370 this.image_resize(); 371 }, 372 373 image_resize: function(){ 374 var w = this.$video_holder.width(); 375 var h = this.$video_holder.height(); 376 377 var new_width = w; 378 var new_height = this.original_height / ( this.original_width / w ); 379 380 if( (this.parameters.sizing == "adjust" && new_height > h) || (this.parameters.sizing == "fill" && new_height < h) ){ 381 new_height = h; 382 new_width = this.original_width / ( this.original_height / h ); 383 } 384 385 //Round
386 new_height = Math.ceil(new_height); 387 new_width = Math.ceil(new_width); 388 389 //adjust 390 var top = Math.round( h/2 - new_height/2 ); 391 var left = Math.round( w/2 - new_width/2 ); 392 393 this.$img.css({ 394 "width": new_width+"px", 395 "height": new_height+"px", 396 "top": top+"px", 397 "left": left+"px" 398 }); 399 }, 400 401 402 403 404 // User Callable Functions 405 406 isPlaying: function(){ 407 if(this.decision == "html5") 408 return !this.video.paused; 409 else if(this.decision == "flash") 410 return video.isPlaying(); 411 else if(this.decision =="youtube" && this.youtube_ready) 412 return this.player.getPlayerState() === 1; 413 414 return false; 415 }, 416 417 // Play 418 play: function(){ 419 if(this.decision == "html5") 420 this.video.play(); 421 else if(this.decision == "flash") 422 this.video.resume(); 423 else if(this.decision =="youtube" && this.youtube_ready) 424 this.player.playVideo(); 425 }, 426 427 // Pause 428 pause: function(){ 429 if(this.decision == "html5" || this.decision == "flash") 430 this.video.pause(); 431 else if(this.decision =="youtube" && this.youtube_ready) 432 this.player.pauseVideo(); 433 }, 434 435 // Toogle play 436 toggle_play: function(){ 437 if(this.isPlaying()) 438 this.pause(); 439 else 440 this.play(); 441 }, 442 443 // Is mute 444 isMuted: function(){ 445 if(this.decision == "html5") 446 return !(this.video.volume); 447 else if(this.decision == "flash") 448 return video.isMute(); 449 else if(this.decision =="youtube" && this.youtube_ready) 450 return this.player.isMuted(); 451 452 return false; 453 }, 454 455 // Mute 456 mute: function(){ 457 if(this.decision == "html5") 458 this.video.volume = 0; 459 else if(this.decision == "flash") 460 this.video.mute(); 461 else if(this.decision =="youtube" && this.youtube_ready) 462 this.player.mute(); 463 }, 464 465 //Unmute 466 unmute: function(){ 467 if(this.decision == "html5") 468 this.video.volume = 1; 469 else if(this.decision == "flash") 470 this.video.unmute(); 471 else if(this.decision =="youtube" && this.youtube_ready) 472 this.player.unMute(); 473 }, 474 475 //Toogle mute 476 toggle_mute: function(){ 477 if(this.isMuted()) 478 this.unmute(); 479 else 480 this.mute(); 481 }, 482 483 //Hide 484 hide: function(){ 485 //Pause 486 this.pause(); 487 488 this.$video_holder.stop().fadeTo(700, 0); 489 this.hidden = true; 490 }, 491 492 //Show 493 show: function(){ 494 this.play(); 495 496 this.$video_holder.stop().fadeTo(700, 1); 497 this.hidden = false; 498 }, 499 500 //Toogle Hidden 501 toogle_hidden: function(){ 502 if(this.hidden) 503 this.show(); 504 else 505 this.hide(); 506 }, 507 508 //Rewind 509 rewind: function(){ 510 if(this.decision == "html5") 511 this.video.currentTime = 0; 512 else if(this.decision == "flash") 513 this.video.rewind();
514 else if(this.decision =="youtube" && this.youtube_ready) 515 this.player.seekTo(0); 516 } 517 }; 518 519 520})(undefined);
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.