-
Notifications
You must be signed in to change notification settings - Fork 24
/
jquery-video-lightning.min.js
9 lines (9 loc) · 4.54 KB
/
jquery-video-lightning.min.js
1
2
3
4
5
6
7
8
9
/*
* jQuery Video Lightning - v1.1.0
* Simple jQuery plugin that turns any element into a lightbox / popover link for Youtube and Vimeo videos.
* https://github.com/musocrat/jquery-video-lightning
*
* Made by Andrew Carpenter
* Under MIT License
*/
!function(a,b,c){function d(b,c){this.element=b,this.base_settings=a.extend({},f,c),this.init()}var e="jqueryVideoLightning",f={id:"y-dQw4w9WgXcQ",width:"640px",height:"390px",autoplay:0,autohide:2,controls:1,iv_load_policy:1,loop:0,modestbranding:0,playlist:"",related:0,showinfo:1,start_time:0,theme:"dark",color:"",byline:1,portrait:1,effect_in:"fadeIn",ease_in:300,ease_out:0,backdrop_color:"#000",backdrop_opacity:1,glow:0,glow_color:"#fff",rick_roll:0,cover:0};return d.prototype={init:function(){function b(){a(this.player(c,e,f))}var c,d,e,f;c=a(this.element).wrap("<span class='video-target'></span>").parent(".video-target"),c.css("cursor","pointer"),d=this.settings(),e=d.videoId.substring(2),f="v"===d.videoId.charAt(0).toLowerCase()?"vimeo":"youtube",a("style:contains('.video-wrapper')").length<1&&a("<style type='text/css'>.video-wrapper{ display: none; position: fixed; min-width: 100%; min-height: 100%; top: 0; bottom: 0; left: 0; z-index: 21000; } </style>").appendTo("head"),1===d.videoCover&&this.coverImage(f,e,c),c.on("click",a.proxy(b,this))},player:function(a,b,c){var d;d=this.settings();{if(!a.find(".video-wrapper").is(":visible"))return a.append('<div class="video-wrapper"><div class="video-frame"><div class="video"></div></div></div>'),a.find(".video-wrapper").css({backgroundColor:"rgba("+this.colorConverter(d.videoBackdropColor).red+","+this.colorConverter(d.videoBackdropColor).blue+","+this.colorConverter(d.videoBackdropColor).green+","+d.videoBackdropOpacity+")"}),a.find(".video-frame").css({position:"absolute",top:"50%",left:"50%",width:d.videoWidth,height:d.videoHeight,marginTop:"-"+d.videoHeight/2+"px",marginLeft:"-"+d.videoWidth/2+"px",boxShadow:"0px 0px "+d.videoGlow+"px "+d.videoGlow/5+"px "+this.fullHex(d.videoGlowColor)}),a.find(".video-wrapper")[d.videoEffectIn](d.videoEaseIn),a.find(".video").append(this[c+"Player"](d,b));if(1!==d.videoRickRoll)return this.destroy(a)}},settings:function(){function b(b){return a.each(b,a.proxy(function(b,c){f="video"+b.toLowerCase().charAt(0).toUpperCase()+b.slice(1).replace(/_([a-z])/g,function(a,b){return b.toUpperCase()}),a(this).data(f,c)},this)),a(this).data()}var d,e,f,g;return d=a(this.element),e=this.base_settings,e=d.extend({},b(e),d.data()),e.videoWidth=parseInt(e.videoWidth,10),e.videoHeight=parseInt(e.videoHeight,10),g=e.videoHeight/e.videoWidth,e.videoWidth>a(c).width()-30&&(e.videoWidth=a(c).width()-30,e.videoHeight=g*e.videoWidth),e},colorConverter:function(a){var b,c,d;return b=parseInt(this.prepHex(a).substring(0,2),16),d=parseInt(this.prepHex(a).substring(2,4),16),c=parseInt(this.prepHex(a).substring(4,6),16),{red:b,blue:d,green:c}},prepHex:function(a){return a="#"===a.charAt(0)?a.split("#")[1]:a,3===a.length&&(a+=a),a},fullHex:function(a){return a="#"+this.prepHex(a)},coverImage:function(b,c,d){var e,f;e="http://www.vimeo.com/api/v2/video/"+c+".json?callback=?",f="http://img.youtube.com/vi/"+c+"/hqdefault.jpg","youtube"===b?a("<img class='video-cover'>").attr("src",f).appendTo(d):a.getJSON(e,{format:"jsonp"}).done(function(b){a("<img class='video-cover'>").attr("src",b[0].thumbnail_large).appendTo(d)})},youtubePlayer:function(b,c){return a('<iframe src="https://www.youtube.com/embed/'+c+"?autoplay="+b.videoAutoplay+"&autohide="+b.videoAutohide+"&controls="+b.videoControls+"&iv_load_policy="+b.videoIvLoadPolicy+"&loop="+b.videoLoop+"&modestbranding="+b.videoModestbranding+"&playlist="+b.videoPlaylist+"&rel="+b.videoRelated+"&showinfo="+b.videoShowinfo+"&start="+b.videoStartTime+"&theme="+b.videoTheme+"&color="+b.videoColor+'" width="'+b.videoWidth+'"px height="'+b.videoHeight+'"px frameborder="0" allowfullscreen></iframe>')},vimeoPlayer:function(b,c){return a('<iframe src="http://player.vimeo.com/video/'+c+"?autoplay="+b.videoAutoplay+"&loop="+b.videoLoop+"&title="+b.videoShowinfo+"&byline="+b.videoByline+"&portrait="+b.videoPortrait+"&color="+this.prepHex(b.videoColor)+'" width="'+b.videoWidth+'"px height="'+b.videoHeight+'"px frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>')},destroy:function(b){b.find(".video").remove(),b.find(".video-wrapper").hide(this.settings().videoEaseOut),b.find(".video-wrapper").remove(),a(this).off(),a(this).removeData()}},a.fn[e]=function(b){return this.each(function(){a.data(this,"plugin_"+e)||a.data(this,"plugin_"+e,new d(this,b))})},this}(jQuery,window,document);