Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated min file with latest changes

  • Loading branch information...
commit 188652925753dd2946af4a39e7f955e804107e0b 1 parent ff054f8
@badsyntax badsyntax authored
Showing with 33 additions and 1 deletion.
  1. +33 −1 js/jquery.youtube.player.min.js
View
34 js/jquery.youtube.player.min.js
@@ -1,8 +1,40 @@
/*
- * jquery.youtube.min.js v1 - a jquery youtube player
+ * jquery.youtube.min.js v0.1a1 - a jquery youtube player
* Copyright (c) 2010 Richard Willis
* MIT license : http://www.opensource.org/licenses/mit-license.php
* Project : http://github.com/badsyntax/jquery-youtube-player
* Contact : willis.rh@gmail.com | badsyntax.co.uk
* Build time : Tue Nov 2 22:42:07 GMT 2010
*/
+(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('<div class="youtube-player"></div>');b=e('<div class="youtube-player-video"></div>').appendTo(this.element);e('<div class="youtube-player-object"></div>').appendTo(b);e('<ol class="youtube-player-playlist"><li></li></ol>').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()._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._trigger(f,"onPlayerReady",[i]);f.loadVideo(false,true);f.elements.toolbar.container.animate(f.options.toolbarAnimation,f.options.toolbarSpeed,function(){f._trigger(f,"onReady",[i])});f._showPlaylist(function(){f.keys.play&&f.playVideo()})}function b(){f._trigger(this,"onVideoPaused",[f._getVideo()])}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",[f._getVideo()])}function h(){f._updatePlaylist();f._addState("play");f.elements.toolbar.updateStates();f._updateTime();f._trigger(this,"onVideoPlay",[f._getVideo()])}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(this.options.width);this.elements.playerVideo.height(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("<ul />").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("<li></li>").addClass("ui-state-default ui-corner-all").append('<span class="ui-icon '+d.icon+'"></span>').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("<span />").appendTo(this.options.timeAppendTo):e("<li />").addClass("youtube-player-time").appendTo(this.elements.toolbar.container);this.elements.toolbar.timeCurrent=e("<span />").html("0:00").appendTo(this.elements.toolbar.time);this.elements.toolbar.timeDuration=e("<span />").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;if(!d){b.elements.playlist.empty();b.videoIds=[]}e.each(g,function(){b.videoIds.push(this.id);e("<li />").data("video",this).append(b.options.videoThumbs?'<img alt="'+this.title+'" title="'+this.title+'" src="http://img.youtube.com/vi/'+
+this.id+'/2.jpg" />':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")};this._bindPlaylistClickHandler=function(d){d.items.click(function(){b._trigger(this,a,arguments);b._trigger(b,"playlistBuilderClickHandler",arguments)})};var c;if(e.isFunction(this.options.playlistBuilder))c=this.options.playlistBuilder;
+else{b.elements.playlist=b.elements.playlist||e("<ol />").addClass("youtube-player-playlist ui-helper-reset");b.elements.playlistContainer=b.elements.playlistContainer||e("<div />").addClass("youtube-player-playlist-container ui-widget-content ui-corner-all").html(b.elements.playlist);this._addVideosToPlaylist();this.options.playlistAppendTo?this.elements.playlistContainer.appendTo(this.options.playlistAppendTo):this.elements.toolbar.container.after(this.elements.playlistContainer);c=function(){return{items:b.elements.playlist.find("li"),
+container:b.elements.playlistContainer}}}e.each(this.options.playlist.videos,function(){b.videoIds.push(this.id)});c=c.call(this,this.options.playlist.videos);this.elements.playlistContainer=c.container;this._bindPlaylistClickHandler(c);return this},_updateTime:function(){function a(d){var g=Math.floor(d/60);d=(d%60).toFixed(0);return g+":"+(d<10?"0"+d:d)}if(this.options.showTime){var b=this,c=Number(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){a=typeof a==="string"?this._states[a]:a;this._removeStates([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},_getVideo:function(){return this.options.playlist.videos[this.keys.video]},_findVideo:function(a){var b=-1;e.each(this.options.playlist.videos,function(c,d){if(a==d.id){b=c;return false}});
+return b},_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(),element:this})})}}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){var b=
+this.options.showPlaylist;b&&this.elements.playlistContainer.show();this.elements.playlist.height();var c=this.elements.playlist.css("height","auto").height(),d=this.elements.playlist.find("li:first").outerHeight()*this.options.playlistHeight;c=d<c?d:c;b&&this.elements.playlistContainer.hide();if(this.elements.playlist.children().length){if(c){this.elements.playlist.height(c);this.options.showPlaylist||b?this.elements.playlistContainer.animate(this.options.playlistAnimation,this.options.playlistSpeed,
+a):this._trigger(this,a)}}else{this.elements.playlistContainer.hide();this._trigger(this,a)}},loadVideo:function(a,b){function c(h){b?d.cueVideo(h):d.youtubePlayer.loadVideoById(h,0);d._trigger(d,"onVideoLoad",[d._getVideo()])}var d=this;if(a&&a.id){a={id:a.id,title:a.title};this.videoIds=b?this.videoIds:[];if(b)this.options.playlist.videos.push(a);else this.options.playlist.videos=a.title?[a]:[];this._addVideosToPlaylist(b);!b&&c(a.id)}else if(a){var g=this._findVideo(a);if(g!==-1){this.keys.video=
+g;c(a)}}else c(this.options.playlist.videos[this.keys.video].id)},loadPlaylist:function(a,b,c,d){c=c===l?true:c;if(a)this.options.playlist=a;this._getPlaylistData(function(){this.keys.video=this.options.randomStart?this.randomVideo():0;this._trigger(this,d);this._createPlaylist();c&&this._showPlaylist()},function(){this.elements.playerObject.html("There was an error loading the playlist.");this._trigger(this,"onError",["There was an error loading the playlist."])})},pauseVideo:function(){this.youtubePlayer.pauseVideo()},
+shufflePlaylist:function(){this.randomVideo();this.playVideo()},muteVideo:function(){this._state("mute")?this.youtubePlayer.unMute():this.youtubePlayer.mute()},repeat:function(){this.options.repeat=1},playVideo:function(){this.youtubePlayer.playVideo()},cueVideo:function(a,b){return this.youtubePlayer.cueVideoById(a||this.options.playlist.videos[this.keys.video].id,b||0)},randomVideo:function(){this.keys.video=Math.floor(Math.random()*this.options.playlist.videos.length);return this.keys.video},prevVideo:function(){if(this.keys.video>
+0)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<this.options.playlist.videos.length-1)this._setVideoKey(++this.keys.video);else if(this.options.repeatPlaylist){this._trigger(this,"onEndPlaylist");this._setVideoKey(0)}else return;this.loadVideo(null,this._state("play")||this.options.autoPlay?false:true)},
+playlistToggle:function(){this.elements.playlistContainer.find("li").length&&this.elements.playlistContainer.animate({height:"toggle",opacity:"toggle"},this.options.playlistSpeed)},plugin:function(){return this},state:function(){var a=this,b=[];e.each(this._activeStates,function(c,d){e.each(a._states,function(g,h){d===h&&b.push(g)})});return b},videos:function(){return this.options.playlist.videos},videoIndex:function(){return this.keys.video},destroy:function(){clearInterval(this.timeInterval);this.element.removeClass("ui-widget").removeAttr("style");
+this.elements.playerVideo.removeAttr("style");this.elements.playlistContainer.remove();this.elements.toolbar.container.remove();this.options.swfobject.removeSWF(this.elements.playerObject[0].id);this.elements.playerObjectClone.appendTo(this.elements.playerVideo);e.removeData(this.element[0],this._pluginName)}};o.prototype.defaultToolbarButtons={play:{text:"Play",icon:"ui-icon-play",toggleButton:{text:"Pause",icon:"ui-icon-pause",action:function(){this.pauseVideo()}},action:function(){this.playVideo()}},
+prev:{text:"Prev",icon:"ui-icon-seek-prev",action:function(){this.prevVideo()}},next:{text:"Next",icon:"ui-icon-seek-next",action:function(){this.nextVideo()}},shuffle:{text:"Shuffle/Random",icon:"ui-icon-shuffle",toggle:1,action:function(){this.shufflePlaylist()}},repeat:{text:"Repeat playlist",icon:"ui-icon-refresh",toggle:1,action:function(){this.repeat()}},mute:{text:"Mute",icon:"ui-icon-volume-on",toggle:1,action:function(a){this.muteVideo(a)}},playlistToggle:{text:"Toggle playlist",icon:"ui-icon-script",
+action:function(){this.playlistToggle()}}}})(this.jQuery,this,document);
Please sign in to comment.
Something went wrong with that request. Please try again.