-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtubepopup.js
executable file
·6 lines (6 loc) · 3.15 KB
/
youtubepopup.js
1
2
3
4
5
6
/*!
* jQuery YouTube Popup Player Plugin v2.3
* http://lab.abhinayrathore.com/jquery_youtube/
* https://github.com/abhinayrathore/jQuery-YouTube-Popup-Player-Plugin
*/
(function(h,g){var b=null;var f={};var d={init:function(i){i=h.extend({},h.fn.YouTubePopup.defaults,i);if(b==null){b=h("<div>").css({display:"none",padding:0});h("body").append(b);b.dialog({autoOpen:false,resizable:false,draggable:i.draggable,modal:i.modal,dialogClass:i.cssClass,create:function(){f.backgroundImage=h(".ui-dialog").css("background-image");f.border=h(".ui-dialog").css("border");f.backgroundColor=h(".ui-dialog").css("background-color")},close:function(){b.html("");h(".ui-dialog-titlebar").show();h(".ui-dialog").css({"background-image":f.backgroundImage,border:f.border,"background-color":f.backgroundColor})}})}return this.each(function(){var k=h(this);var j=k.data("YouTube");if(!j){k.data("YouTube",{target:k});h(k).bind("click.YouTubePopup",function(){var o=i.youtubeId;if(h.trim(o)==""&&k.is("a")){o=c(k.attr("href"))}if(h.trim(o)==""||o===false){o=k.attr(i.idAttribute)}var m=h.trim(i.title);if(m==""){if(i.useYouTubeTitle){a(o)}else{m=k.attr("title")}}var n=g.location.protocol+"//www.youtube.com/embed/"+o+"?rel=0&showsearch=0&autohide="+i.autohide;n+="&autoplay="+i.autoplay+"&controls="+i.controls+"&fs="+i.fs+"&loop="+i.loop;n+="&showinfo="+i.showinfo+"&color="+i.color+"&theme="+i.theme;b.html(e(n,i.width,i.height));b.dialog({width:"auto",height:"auto"});b.dialog({minWidth:i.width,minHeight:i.height,title:m});b.dialog("open");h(".ui-widget-overlay").fadeTo("fast",i.overlayOpacity);var l=h(".ui-dialog-titlebar");if(i.hideTitleBar&&i.modal){l.hide();h(".ui-widget-overlay").click(function(){b.dialog("close")})}if(i.clickOutsideClose&&i.modal){h(".ui-widget-overlay").click(function(){b.dialog("close")})}l.removeClass("ui-corner-all").addClass("ui-corner-top");if(!i.showBorder){h(".ui-dialog").css({"background-image":"none",border:"none","background-color":"transparent"})}return false})}})},destroy:function(){return this.each(function(){h(this).unbind(".YouTubePopup");h(this).removeData("YouTube")})}};function e(j,l,i){var k='<iframe title="YouTube video player" style="margin:0; padding:0;" width="'+l+'" ';k+='height="'+i+'" src="'+j+'" frameborder="0" allowfullscreen></iframe>';return k}function a(j){var i="https://gdata.youtube.com/feeds/api/videos/"+j+"?v=2&alt=json";h.ajax({url:i,dataType:"jsonp",cache:true,success:function(k){b.dialog({title:k.entry.title.$t})}})}function c(i){var k=/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;var j=i.match(k);if(j&&j[2].length==11){return j[2]}else{return false}}h.fn.YouTubePopup=function(i){if(d[i]){return d[i].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof i==="object"||!i){return d.init.apply(this,arguments)}else{h.error("Method "+i+" does not exist on jQuery.YouTubePopup")}}};h.fn.YouTubePopup.defaults={youtubeId:"",title:"",useYouTubeTitle:true,idAttribute:"rel",cssClass:"YouTubeDialog",draggable:false,modal:true,width:640,height:480,hideTitleBar:false,clickOutsideClose:false,overlayOpacity:0.5,autohide:2,autoplay:1,color:"red",controls:1,fs:1,loop:0,showinfo:0,theme:"light",showBorder:true}})(jQuery,window);