diff --git a/js/jquery.youtube.player.min.js b/js/jquery.youtube.player.min.js index 1c480eb..6ba3970 100644 --- a/js/jquery.youtube.player.min.js +++ b/js/jquery.youtube.player.min.js @@ -5,4 +5,34 @@ * Project : http://github.com/badsyntax/jquery-youtube-player * Contact : willis.rh@gmail.com | badsyntax.co.uk */ - +(function(e,k,n,l){function o(a,b,c){var d=this;this._pluginName=c;this.element=e(a).addClass("ui-widget");this.options=e.extend({width:425,height:356,swfobject:k.swfobject,playlist:{},showPlaylist:1,showTime:1,videoThumbs:0,randomStart:0,autoStart:0,autoPlay:0,repeat:1,repeatPlaylist:0,shuffle:0,chromeless:1,highDef:0,playlistHeight:5,playlistBuilder:null,playlistBuilderClickHandler:null,playlistAnimation:{height:"show",opacity:"show"},playlistSpeed:550,toolbarAppendTo:null,playlistAppendTo:null, +timeAppendTo:null,videoParams:{allowfullscreen:"true",allowScriptAccess:"always",wmode:"transparent"},showToolbar:null,toolbarButtons:{},toolbar:"play,prev,next,shuffle,repeat,mute,playlistToggle",toolbarAnimation:{opacity:1},toolbarSpeed:500},b);if(!this.options.chromeless&&this.options.showToolbar!=true)this.options.showToolbar=0;this._states={unstarted:-1,ended:0,play:1,paused:2,buffering:3,cued:5};this._youtubeIdExp=/^[^v]+v.(.{11}).*/;this.buttons=e.extend({},this.defaultToolbarButtons,this.options.toolbarButtons); +if(this.element.is("a")){a=this.element;this.element=e('
');b=e('
').appendTo(this.element);e('
').appendTo(b);e('
').find("li").append(a.clone()).end().appendTo(this.element);a.after(this.element).hide()}this.elements={player:this.element,playerVideo:this.element.find(".youtube-player-video"),playerObject:this.element.find(".youtube-player-object")}; +this.elements.playerObjectClone=this.elements.playerObject.clone();this.keys={video:0};do a="jqueryyoutubeplayer"+Math.floor(Math.random()*101).toString();while(n.getElementById(a));this.elements.playerObject[0].id=a;this.options.swfobject.getFlashPlayerVersion().major>=8&&this.loadPlaylist(null,null,null,function(){d._bindYoutubeEventHandlers()._createToolbar()._createTimeArea()._createPlaylist()._createPlayer()})}e.fn.player=function(a){var b=arguments,c=l;this.each(function(){var d=e.data(this, +"jquery-youtube-player");if(d&&d[a]){c=d[a].apply(d,Array.prototype.slice.call(b,1));c=a=="plugin"?c:l}else if(!d&&(typeof a==="object"||!a))e.data(this,"jquery-youtube-player",new o(this,a,"jquery-youtube-player"))});return c||this};o.prototype={_activeStates:[],timer:{},videoIds:[],_trigger:function(a,b,c){var d=typeof b;c=c||[];if(d==="string"&&this.options[b]&&e.isFunction(this.options[b]))return this.options[b].apply(a,c);else d==="function"&&b.apply(a,c)},_bindYoutubeEventHandlers:function(){function a(i){f.youtubePlayer= +n.getElementById(i);f.loadVideo(false,true);f.elements.toolbar.container.animate(f.options.toolbarAnimation,f.options.toolbarSpeed,function(){f._trigger(f,"onReady",[i])});f._showPlaylist(f.options.showPlaylist);f.keys.play&&f.playVideo()}function b(){f._trigger(this,"onVideoPaused",arguments)}function c(i){switch(i){case 100:msg="This video has been removed from Youtube.";break;case 101:case 150:msg="This video does not allow playback outside of Youtube.";break;default:msg="Unknown error"}f._trigger(this, +"onError",[msg])===l&&alert("There was an error loading this video. "+msg)}function d(){f._updatePlaylist();f.elements.toolbar.updateStates();f._trigger(this,"onVideoCue",arguments)}function g(){f._trigger(this,"onBuffer",arguments)}function h(){f._updatePlaylist();f._addState("play");f.elements.toolbar.updateStates();f._updateTime();f._trigger(this,"onVideoPlay",arguments)}var f=this,j=this.elements.playerObject[0].id;k["onytplayerStateChange"+j]=function(i){f._removeStates([-1,0,1,2,3,5,100,101, +150,9]);f._addState(i,true);switch(i){case 0:f.buttons.play.element&&f.buttons.play.element.trigger("off");f.options.repeat&&f.nextVideo();break;case 1:h();break;case 2:b();break;case 3:g();break;case 9:a(j);break;case 5:d();break;case 100:case 101:case 150:c(i)}f._trigger(f,"onYoutubeStateChange",[i])};if(!k.onYouTubePlayerReady)k.onYouTubePlayerReady=function(i){var m=n.getElementById(i);m.addEventListener("onStateChange","onytplayerStateChange"+i);m.addEventListener("onError","onytplayerStateChange"+ +i);k["onytplayerStateChange"+i](9)};return this},_createPlayer:function(){this.elements.player.width(parseInt(this.options.width));this.elements.playerVideo.height(parseInt(this.options.height));var a=this.options.playlist.videos[this.keys.video].id,b=this.elements.playerObject[0].id;a=this.options.chromeless?"http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid="+b+"&hd="+this.options.highDef+"&showinfo=0":"http://www.youtube.com/v/"+a+"?enablejsapi=1&playerapiid="+b+"&version=3"; +this._trigger(this,"onBeforePlayerBuild");this.options.swfobject.embedSWF(a,this.elements.playerObject[0].id,"100%","100%","8",null,null,this.options.videoParams);return this},_createToolbar:function(){var a=this;this.elements.toolbar={container:e("").addClass("youtube-player-toolbar ui-widget ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all").css("opacity",0),updateStates:function(){a.elements.toolbar.container.find("li").each(function(){var b=e(this).removeClass("ui-state-active").data("button"); +if(!b)return true;a._state(b.val)&&b.toggle&&e(this).addClass("ui-state-active");a._state(b.val)&&b.toggleButton&&e(this).trigger("on")})}};this.options.showToolbar!=null&&!this.options.showToolbar&&this.elements.toolbar.container.hide();e.each(this.options.toolbar.split(","),function(b,c){var d=a.buttons[c];if(!d||!d.text)return true;d.val=c;a._states[c]=a._states[c]||c;e("
  • ").addClass("ui-state-default ui-corner-all").append('').attr("title",d.text).data("button", +d).bind("mouseenter mouseleave",function(){e(this).toggleClass("ui-state-hover")}).bind("off",function(){var g=e(this),h=g.data("button");g.data("toggle",1);a._removeState(c);g.find(".ui-icon").removeClass(h.toggleButton.icon).addClass(h.icon).end().attr("title",h.text);a._trigger(a,h.toggleButton.action,[h])}).bind("on",function(){var g=e(this),h=g.data("button");g.data("toggle",0);a._addState(c);g.find(".ui-icon").removeClass(h.icon).addClass(h.toggleButton.icon).end().attr("title",h.toggleButton.text); +a._trigger(a,h.action,[h])}).bind("toggle",function(){var g=e(this).data("toggle");g||g==l?e(this).trigger("on"):e(this).trigger("off")}).click(function(){var g=e(this).data("button"),h=a._state(c);if(g.toggleButton)e(this).trigger("toggle");else{a._trigger(a,g.action,[g]);!g.toggle||g.toggle&&h?a._removeState(c):a._addState(c);a.elements.toolbar.updateStates()}}).appendTo(a.elements.toolbar.container)});this.options.toolbarAppendTo?this.elements.toolbar.container.appendTo(this.options.toolbarAppendTo): +this.elements.playerVideo.after(this.elements.toolbar.container);return this},_createTimeArea:function(){this.elements.toolbar.time=this.options.timeAppendTo?e("").appendTo(this.options.timeAppendTo):e('
  • ').appendTo(this.elements.toolbar.container);this.elements.toolbar.timeCurrent=e("").html("0:00").appendTo(this.elements.toolbar.time);this.elements.toolbar.timeDuration=e("").appendTo(this.elements.toolbar.time);return this},_createPlaylist:function(){function a(){var d= +e(this).data("video");if(d){b.keys.video=e.inArray(d.id,b.videoIds);b._removeState("play");b._updatePlaylist();b.loadVideo();b.playVideo()}}var b=this;this._addVideosToPlaylist=function(d){var g=d?[b.options.playlist.videos[b.options.playlist.videos.length-1]]:b.options.playlist.videos;!d&&b.elements.playlist.empty();b.videoIds=[];e.each(g,function(){b.videoIds.push(this.id);e("
  • ").data("video",this).append(b.options.videoThumbs?''+this.title+'':this.title).addClass("ui-state-default").addClass(b.options.videoThumbs?"youtube-player-thumb":"").bind("mouseenter mouseleave",function(){e(this).toggleClass("ui-state-hover")}).appendTo(b.elements.playlist)});b._trigger(b,"onAfterVideosAddedToPlaylist")};if(!e.isFunction(this.options.playlistBuilder)){b.elements.playlist=b.elements.player.find(".youtube-player-playlist").length?b.elements.player.find(".youtube-player-playlist"):e("
      ").addClass("youtube-player-playlist ui-helper-reset"); +b.elements.playlistContainer=e("
      ").addClass("youtube-player-playlist-container ui-widget-content ui-corner-all").append(b.elements.playlist);this._addVideosToPlaylist();this.options.playlistAppendTo?this.elements.playlistContainer.appendTo(this.options.playlistAppendTo):this.elements.toolbar.container.after(this.elements.playlistContainer);this.options.playlistBuilder=function(){return{items:b.elements.playlist.find("li"),container:b.elements.playlistContainer}}}e.each(this.options.playlist.videos, +function(){b.videoIds.push(this.id)});var c=this.options.playlistBuilder.call(this,this.options.playlist.videos);c.items.click(function(){b._trigger(this,a,arguments);b._trigger(b,"playlistBuilderClickHandler",arguments)});this.elements.playlistContainer=c.container;return this},_updateTime:function(){function a(d){d=Number(d);var g=Math.floor(d/3600),h=Math.floor(d%3600/60);d=Math.floor(d%3600%60);return(g>0?g+":":"")+(h>0?(g>0&&h<10?"0":"")+h+":":"0:")+(d<10?"0":"")+d}if(this.options.showTime){var b= +this,c=this.youtubePlayer.getDuration();this.elements.toolbar.timeDuration.html(" / "+a(c));this.elements.toolbar.time.fadeIn();this.timeInterval=setInterval(function(){!b.youtubePlayer.getCurrentTime?clearInterval(b.timeInterval):b.elements.toolbar.timeCurrent.html(a(b.youtubePlayer.getCurrentTime()))},100)}},_removeStates:function(a){var b=[];e.each(this._activeStates,function(c,d){e.inArray(d,a)===-1&&e.inArray(d,b)===-1&&b.push(d)});this._activeStates=b},_removeState:function(a){this._removeStates([this._states[a]])}, +_state:function(a){a=this._states[a];return e.inArray(a,this._activeStates)!==-1?true:false},_addState:function(a,b){if(b)e.inArray(a,this._activeStates)===-1&&this._activeStates.push(a);else this._states[a]&&e.inArray(this._states[a],this._activeStates)===-1&&this._activeStates.push(this._states[a])},_setVideoKey:function(a){this.keys.video=this.options.shuffle?this.options.randomVideo():a||0},_getPlaylistData:function(a,b){var c=this,d=this.options.playlist;if(d.user||d.playlist){var g=function(j){if(j){c.options.playlist= +{title:j.feed.title.$t,id:d,videos:[]};e.each(j.feed.entry,function(i,m){c.options.playlist.videos.push({id:m.link[0].href.replace(c._youtubeIdExp,"$1"),title:m.title.$t})});c.elements.playerObject.fadeOut(180,function(){a.call(c)})}else b.call(c)},h=d.user?"http://gdata.youtube.com/feeds/api/videos":"http://gdata.youtube.com/feeds/api/playlists/"+d.playlist;h+="?callback=?";var f={alt:"json",format:"5"};if(d.user)f.author=d.user;this._trigger(this,"onBeforePlaylistLoaded",[d]);e.ajax({type:"GET", +url:h,data:f,dataType:"json",error:function(){c._trigger(c,"onAfterPlaylistLoaded",[d]);c._trigger(c,b)},success:function(){c._trigger(c,"onAfterPlaylistLoaded",[d]);c._trigger(c,g,arguments)}})}else{if(!d.videos){h=this.elements.player.find(".youtube-player-playlist li a");if(h.length){c.options.playlist.videos=[];h.each(function(){c.options.playlist.videos.push({id:this.href.replace(c._youtubeIdExp,"$1"),title:e(this).html()})})}}c._trigger(c,"onAfterPlaylistLoaded",[d]);c._trigger(c,a)}},_updatePlaylist:function(){var a= +this;this.elements.playlist&&this.elements.playlist.find("li").removeClass("ui-state-active").each(function(b){if(a.options.playlist.videos[a.keys.video].id==e(this).data("video").id){var c=e(this).addClass("ui-state-active").outerHeight();a.options.videoThumbs||a.elements.playlist.scrollTop(b*c-Math.floor(a.options.playlistHeight/2)*c);return false}})},_showPlaylist:function(a){(a=a===l?true:a)&&this.elements.playlistContainer.show();this.elements.playlist.height();var b=this.elements.playlist.css("height", +"auto").height(),c=this.elements.playlist.find("li:first").outerHeight()*this.options.playlistHeight;b=c0)this._setVideoKey(--this.keys.video);else if(this.options.repeatPlaylist)this._setVideoKey(this.videoIds.length-1);else return;this.loadVideo(null,this._state("play")|| +this.options.autoPlay?false:true)},nextVideo:function(){if(this.keys.video