jquery.mb.YTPlayer.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. /*
  2. * ******************************************************************************
  3. * jquery.mb.components
  4. * file: jquery.mb.YTPlayer.js
  5. *
  6. * Copyright (c) 2001-2013. Matteo Bicocchi (Pupunzi);
  7. * Open lab srl, Firenze - Italy
  8. * email: matteo@open-lab.com
  9. * site: http://pupunzi.com
  10. * blog: http://pupunzi.open-lab.com
  11. * http://open-lab.com
  12. *
  13. * Licences: MIT, GPL
  14. * http://www.opensource.org/licenses/mit-license.php
  15. * http://www.gnu.org/licenses/gpl.html
  16. *
  17. * last modified: 23/11/13 21.05
  18. * *****************************************************************************
  19. */
  20. if(typeof ytp != "object")
  21. ytp ={};
  22. function onYouTubePlayerAPIReady() {
  23. if(ytp.YTAPIReady)
  24. return;
  25. ytp.YTAPIReady=true;
  26. jQuery(document).trigger("YTAPIReady");
  27. }
  28. (function (jQuery, ytp) {
  29. ytp.isDevice = 'ontouchstart' in window;
  30. /*Browser detection patch*/
  31. if (!jQuery.browser) {
  32. jQuery.browser = {};
  33. jQuery.browser.mozilla = !1;
  34. jQuery.browser.webkit = !1;
  35. jQuery.browser.opera = !1;
  36. jQuery.browser.msie = !1;
  37. var nAgt = navigator.userAgent;
  38. jQuery.browser.ua = nAgt;
  39. jQuery.browser.name = navigator.appName;
  40. jQuery.browser.fullVersion = "" + parseFloat(navigator.appVersion);
  41. jQuery.browser.majorVersion = parseInt(navigator.appVersion, 10);
  42. var nameOffset, verOffset, ix;
  43. if (-1 != (verOffset = nAgt.indexOf("Opera")))jQuery.browser.opera = !0, jQuery.browser.name = "Opera", jQuery.browser.fullVersion = nAgt.substring(verOffset + 6), -1 != (verOffset = nAgt.indexOf("Version")) && (jQuery.browser.fullVersion = nAgt.substring(verOffset + 8)); else if (-1 != (verOffset = nAgt.indexOf("MSIE")))jQuery.browser.msie = !0, jQuery.browser.name = "Microsoft Internet Explorer", jQuery.browser.fullVersion = nAgt.substring(verOffset + 5); else if (-1 != nAgt.indexOf("Trident")) {
  44. jQuery.browser.msie = !0;
  45. jQuery.browser.name = "Microsoft Internet Explorer";
  46. var start = nAgt.indexOf("rv:") + 3, end = start + 4;
  47. jQuery.browser.fullVersion = nAgt.substring(start, end)
  48. } else-1 != (verOffset = nAgt.indexOf("Chrome")) ? (jQuery.browser.webkit = !0, jQuery.browser.name = "Chrome", jQuery.browser.fullVersion = nAgt.substring(verOffset + 7)) : -1 != (verOffset = nAgt.indexOf("Safari")) ? (jQuery.browser.webkit = !0, jQuery.browser.name = "Safari", jQuery.browser.fullVersion = nAgt.substring(verOffset + 7), -1 != (verOffset = nAgt.indexOf("Version")) && (jQuery.browser.fullVersion = nAgt.substring(verOffset + 8))) : -1 != (verOffset = nAgt.indexOf("AppleWebkit")) ? (jQuery.browser.webkit = !0, jQuery.browser.name = "Safari", jQuery.browser.fullVersion = nAgt.substring(verOffset + 7), -1 != (verOffset = nAgt.indexOf("Version")) && (jQuery.browser.fullVersion = nAgt.substring(verOffset + 8))) : -1 != (verOffset = nAgt.indexOf("Firefox")) ? (jQuery.browser.mozilla = !0, jQuery.browser.name = "Firefox", jQuery.browser.fullVersion = nAgt.substring(verOffset + 8)) : (nameOffset = nAgt.lastIndexOf(" ") + 1) < (verOffset = nAgt.lastIndexOf("/")) && (jQuery.browser.name = nAgt.substring(nameOffset, verOffset), jQuery.browser.fullVersion = nAgt.substring(verOffset + 1), jQuery.browser.name.toLowerCase() == jQuery.browser.name.toUpperCase() && (jQuery.browser.name = navigator.appName));
  49. -1 != (ix = jQuery.browser.fullVersion.indexOf(";")) && (jQuery.browser.fullVersion = jQuery.browser.fullVersion.substring(0, ix));
  50. -1 != (ix = jQuery.browser.fullVersion.indexOf(" ")) && (jQuery.browser.fullVersion = jQuery.browser.fullVersion.substring(0, ix));
  51. jQuery.browser.majorVersion = parseInt("" + jQuery.browser.fullVersion, 10);
  52. isNaN(jQuery.browser.majorVersion) && (jQuery.browser.fullVersion = "" + parseFloat(navigator.appVersion), jQuery.browser.majorVersion = parseInt(navigator.appVersion, 10));
  53. jQuery.browser.version = jQuery.browser.majorVersion
  54. }
  55. /*******************************************************************************
  56. * jQuery.mb.components: jquery.mb.CSSAnimate
  57. ******************************************************************************/
  58. jQuery.fn.CSSAnimate=function(a,b,k,l,f){return this.each(function(){var c=jQuery(this);if(0!==c.length&&a){"function"==typeof b&&(f=b,b=jQuery.fx.speeds._default);"function"==typeof k&&(f=k,k=0);"function"==typeof l&&(f=l,l="cubic-bezier(0.65,0.03,0.36,0.72)");if("string"==typeof b)for(var j in jQuery.fx.speeds)if(b==j){b=jQuery.fx.speeds[j];break}else b=null;if(jQuery.support.transition){var e="",h="transitionEnd";jQuery.browser.webkit?(e="-webkit-",h="webkitTransitionEnd"):jQuery.browser.mozilla? (e="-moz-",h="transitionend"):jQuery.browser.opera?(e="-o-",h="otransitionend"):jQuery.browser.msie&&(e="-ms-",h="msTransitionEnd");j=[];for(d in a){var g=d;"transform"===g&&(g=e+"transform",a[g]=a[d],delete a[d]);"transform-origin"===g&&(g=e+"transform-origin",a[g]=a[d],delete a[d]);j.push(g);c.css(g)||c.css(g,0)}d=j.join(",");c.css(e+"transition-property",d);c.css(e+"transition-duration",b+"ms");c.css(e+"transition-delay",k+"ms");c.css(e+"transition-timing-function",l);c.css(e+"backface-visibility", "hidden");setTimeout(function(){c.css(a)},0);setTimeout(function(){c.called||!f?c.called=!1:f()},b+20);c.on(h,function(a){c.off(h);c.css(e+"transition","");a.stopPropagation();"function"==typeof f&&(c.called=!0,f());return!1})}else{for(var d in a)"transform"===d&&delete a[d],"transform-origin"===d&&delete a[d],"auto"===a[d]&&delete a[d];if(!f||"string"===typeof f)f="linear";c.animate(a,b,f)}}})}; jQuery.fn.CSSAnimateStop=function(){var a="",b="transitionEnd";jQuery.browser.webkit?(a="-webkit-",b="webkitTransitionEnd"):jQuery.browser.mozilla?(a="-moz-",b="transitionend"):jQuery.browser.opera?(a="-o-",b="otransitionend"):jQuery.browser.msie&&(a="-ms-",b="msTransitionEnd");jQuery(this).css(a+"transition","");jQuery(this).off(b)}; jQuery.support.transition=function(){var a=(document.body||document.documentElement).style;return void 0!==a.transition||void 0!==a.WebkitTransition||void 0!==a.MozTransition||void 0!==a.MsTransition||void 0!==a.OTransition}();
  59. /*
  60. * Metadata - jQuery plugin for parsing metadata from elements
  61. * Copyright (c) 2006 John Resig, Yehuda Katz, Jörn Zaefferer, Paul McLanahan
  62. * Dual licensed under the MIT and GPL licenses:
  63. * http://www.opensource.org/licenses/mit-license.php
  64. * http://www.gnu.org/licenses/gpl.html
  65. */
  66. (function(c){c.extend({metadata:{defaults:{type:"class",name:"metadata",cre:/({.*})/,single:"metadata"},setType:function(b,c){this.defaults.type=b;this.defaults.name=c},get:function(b,f){var d=c.extend({},this.defaults,f);d.single.length||(d.single="metadata");var a=c.data(b,d.single);if(a)return a;a="{}";if("class"==d.type){var e=d.cre.exec(b.className);e&&(a=e[1])}else if("elem"==d.type){if(!b.getElementsByTagName)return;e=b.getElementsByTagName(d.name);e.length&&(a=c.trim(e[0].innerHTML))}else void 0!= b.getAttribute&&(e=b.getAttribute(d.name))&&(a=e);0>a.indexOf("{")&&(a="{"+a+"}");a=eval("("+a+")");c.data(b,d.single,a);return a}}});c.fn.metadata=function(b){return c.metadata.get(this[0],b)}})(jQuery);
  67. String.prototype.getVideoID=function(){
  68. var movieURL;
  69. if(this.substr(0,16)=="http://youtu.be/"){
  70. movieURL= this.replace("http://youtu.be/","");
  71. }else if(this.indexOf("http")>-1){
  72. movieURL = this.match(/[\\?&]v=([^&#]*)/)[1];
  73. }else{
  74. movieURL = this
  75. }
  76. return movieURL;
  77. };
  78. jQuery.mbYTPlayer = {
  79. name : "jquery.mb.YTPlayer",
  80. version : "2.6.0",
  81. author : "Matteo Bicocchi",
  82. defaults : {
  83. containment : "body",
  84. ratio : "4/3",
  85. showYTLogo : false,
  86. videoURL : null,
  87. startAt : 0,
  88. autoPlay : true,
  89. vol :100,
  90. addRaster : false,
  91. opacity : 1,
  92. quality : "default", //or “small”, “medium”, “large”, “hd720”, “hd1080”, “highres”
  93. mute : false,
  94. loop : true,
  95. showControls : true,
  96. showAnnotations : false,
  97. printUrl : true,
  98. stopMovieOnClick :false,
  99. realfullscreen :true,
  100. onReady : function (player) {},
  101. onStateChange : function (player) {},
  102. onPlaybackQualityChange: function (player) {},
  103. onError : function (player) {}
  104. },
  105. controls : {
  106. play : "P",
  107. pause : "p",
  108. mute : "M",
  109. unmute: "A",
  110. onlyYT: "O",
  111. showSite: "R",
  112. ytLogo: "Y"
  113. },
  114. rasterImg : "images/raster.png",
  115. rasterImgRetina: "images/raster@2x.png",
  116. locationProtocol: location.protocol != "file:" ? location.protocol : "http:",
  117. buildPlayer: function (options) {
  118. return this.each(function () {
  119. var YTPlayer = this;
  120. var $YTPlayer = jQuery(YTPlayer);
  121. YTPlayer.loop = 0;
  122. YTPlayer.opt = {};
  123. var property = {};
  124. $YTPlayer.addClass("mb_YTVPlayer");
  125. if (jQuery.metadata) {
  126. jQuery.metadata.setType("class");
  127. property = $YTPlayer.metadata();
  128. }
  129. if (jQuery.isEmptyObject(property))
  130. property = $YTPlayer.data("property") && typeof $YTPlayer.data("property") == "string" ? eval('(' + $YTPlayer.data("property") + ')') : $YTPlayer.data("property");
  131. jQuery.extend(YTPlayer.opt, jQuery.mbYTPlayer.defaults, options, property);
  132. var canGoFullscreen = !(jQuery.browser.msie || jQuery.browser.opera || self.location.href != top.location.href);
  133. if(!canGoFullscreen)
  134. YTPlayer.opt.realfullscreen = false;
  135. if (!$YTPlayer.attr("id"))
  136. $YTPlayer.attr("id", "id_" + new Date().getTime());
  137. YTPlayer.opt.id = YTPlayer.id;
  138. YTPlayer.isAlone = false;
  139. /*to maintain back compatibility
  140. * ***********************************************************/
  141. if (YTPlayer.opt.isBgndMovie)
  142. YTPlayer.opt.containment = "body";
  143. if (YTPlayer.opt.isBgndMovie && YTPlayer.opt.isBgndMovie.mute != undefined)
  144. YTPlayer.opt.mute = YTPlayer.opt.isBgndMovie.mute;
  145. if (!YTPlayer.opt.videoURL)
  146. YTPlayer.opt.videoURL = $YTPlayer.attr("href");
  147. /************************************************************/
  148. var playerID = "mbYTP_" + YTPlayer.id;
  149. var videoID = this.opt.videoURL ? this.opt.videoURL.getVideoID() : $YTPlayer.attr("href") ? $YTPlayer.attr("href").getVideoID() : false;
  150. YTPlayer.videoID = videoID;
  151. YTPlayer.opt.showAnnotations = (YTPlayer.opt.showAnnotations) ? '0' : '3';
  152. var playerVars = { 'autoplay': 0, 'modestbranding': 1, 'controls': 0, 'showinfo': 0, 'rel': 0, 'enablejsapi': 1, 'version': 3, 'playerapiid': playerID, 'origin': '*', 'allowfullscreen': true, 'wmode': "transparent", 'iv_load_policy': YTPlayer.opt.showAnnotations};
  153. var canPlayHTML5 = false;
  154. var v = document.createElement('video');
  155. if (v.canPlayType ) { // && !jQuery.browser.msie
  156. canPlayHTML5 = true;
  157. }
  158. if (canPlayHTML5) // && !(YTPlayer.isPlayList && jQuery.browser.msie)
  159. jQuery.extend(playerVars, {'html5': 1});
  160. if(jQuery.browser.msie && jQuery.browser.version < 9 ){
  161. this.opt.opacity = 1;
  162. }
  163. var playerBox = jQuery("<div/>").attr("id", playerID).addClass("playerBox");
  164. var overlay = jQuery("<div/>").css({position: "absolute", top: 0, left: 0, width: "100%", height: "100%"}).addClass("YTPOverlay"); //YTPlayer.isBackground ? "fixed" :
  165. YTPlayer.opt.containment = YTPlayer.opt.containment == "self" ? jQuery(this) : jQuery(YTPlayer.opt.containment);
  166. YTPlayer.isBackground = YTPlayer.opt.containment.get(0).tagName.toLowerCase() == "body";
  167. if (ytp.isDevice && YTPlayer.isBackground){
  168. $YTPlayer.hide();
  169. return;
  170. }
  171. if (YTPlayer.opt.addRaster) {
  172. var retina = (window.retina || window.devicePixelRatio > 1);
  173. overlay.addClass(retina ? "raster retina" : "raster");
  174. }else{
  175. overlay.removeClass("raster retina");
  176. }
  177. var wrapper = jQuery("<div/>").addClass("mbYTP_wrapper").attr("id", "wrapper_" + playerID);
  178. wrapper.css({position: "absolute", zIndex: 0, minWidth: "100%", minHeight: "100%",left:0, top:0, overflow: "hidden", opacity: 0});
  179. playerBox.css({position: "absolute", zIndex: 0, width: "100%", height: "100%", top: 0, left: 0, overflow: "hidden", opacity: this.opt.opacity});
  180. wrapper.append(playerBox);
  181. if (YTPlayer.isBackground && ytp.isInit)
  182. return;
  183. YTPlayer.opt.containment.children().each(function () {
  184. if (jQuery(this).css("position") == "static")
  185. jQuery(this).css("position", "relative");
  186. });
  187. if (YTPlayer.isBackground) {
  188. jQuery("body").css({position: "relative", minWidth: "100%", minHeight: "100%", zIndex: 1, boxSizing: "border-box"});
  189. wrapper.css({position: "fixed", top: 0, left: 0, zIndex: 0});
  190. $YTPlayer.hide();
  191. YTPlayer.opt.containment.prepend(wrapper);
  192. } else
  193. YTPlayer.opt.containment.prepend(wrapper);
  194. YTPlayer.wrapper = wrapper;
  195. playerBox.css({opacity: 1});
  196. if (!ytp.isDevice){
  197. playerBox.after(overlay);
  198. YTPlayer.overlay = overlay;
  199. }
  200. if(!YTPlayer.isBackground){
  201. overlay.on("mouseenter",function(){
  202. $YTPlayer.find(".mb_YTVPBar").addClass("visible");
  203. }).on("mouseleave",function(){
  204. $YTPlayer.find(".mb_YTVPBar").removeClass("visible");
  205. })
  206. }
  207. // add YT API to the header
  208. //jQuery("#YTAPI").remove();
  209. if(!ytp.YTAPIReady){
  210. var tag = document.createElement('script');
  211. tag.src = jQuery.mbYTPlayer.locationProtocol+"//www.youtube.com/player_api";
  212. tag.id = "YTAPI";
  213. var firstScriptTag = document.getElementsByTagName('script')[0];
  214. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  215. }else{
  216. setTimeout(function(){
  217. jQuery(document).trigger("YTAPIReady");
  218. }, 200)
  219. }
  220. jQuery(document).on("YTAPIReady", function () {
  221. if ((YTPlayer.isBackground && ytp.isInit) || YTPlayer.opt.isInit)
  222. return;
  223. if(YTPlayer.isBackground && YTPlayer.opt.stopMovieOnClick)
  224. jQuery(document).off("mousedown.ytplayer").on("mousedown,.ytplayer",function(e){
  225. var target = jQuery(e.target);
  226. if(target.is("a") || target.parents().is("a")){
  227. $YTPlayer.pauseYTP();
  228. }
  229. });
  230. if (YTPlayer.isBackground)
  231. ytp.isInit = true;
  232. YTPlayer.opt.isInit = true;
  233. YTPlayer.opt.vol = YTPlayer.opt.vol ? YTPlayer.opt.vol : 100;
  234. jQuery.mbYTPlayer.getDataFromFeed(YTPlayer.videoID, YTPlayer);
  235. jQuery(document).on("getVideoInfo_" + YTPlayer.opt.id, function () {
  236. if(ytp.isDevice && !YTPlayer.isBackground){
  237. new YT.Player(playerID, {
  238. height: '100%',
  239. width: '100%',
  240. videoId: YTPlayer.videoID,
  241. events: {
  242. 'onReady': function(){
  243. $YTPlayer.optimizeDisplay();
  244. playerBox.css({opacity: 1});
  245. YTPlayer.wrapper.css({opacity: 1});
  246. $YTPlayer.optimizeDisplay();
  247. },
  248. 'onStateChange': function(){}
  249. }
  250. });
  251. return;
  252. }
  253. new YT.Player(playerID, {
  254. videoId : YTPlayer.videoID.toString(),
  255. playerVars: playerVars,
  256. events : {
  257. 'onReady': function (event) {
  258. YTPlayer.player = event.target;
  259. if(YTPlayer.isReady)
  260. return;
  261. YTPlayer.isReady = true;
  262. YTPlayer.playerEl = YTPlayer.player.getIframe();
  263. $YTPlayer.optimizeDisplay();
  264. YTPlayer.videoID = videoID;
  265. jQuery(window).on("resize.YTP",function () {
  266. $YTPlayer.optimizeDisplay();
  267. });
  268. if (YTPlayer.opt.showControls)
  269. jQuery(YTPlayer).buildYTPControls();
  270. YTPlayer.player.setPlaybackQuality(YTPlayer.opt.quality);
  271. if (YTPlayer.opt.startAt > 0)
  272. YTPlayer.player.seekTo(parseFloat(YTPlayer.opt.startAt), true);
  273. if (!YTPlayer.opt.autoPlay) {
  274. // $YTPlayer.stopYTP();
  275. YTPlayer.player.pauseVideo();
  276. YTPlayer.checkForStartAt = setInterval(function () {
  277. if (YTPlayer.player.getCurrentTime() >= YTPlayer.opt.startAt) {
  278. clearInterval(YTPlayer.checkForStartAt);
  279. //YTPlayer.wrapper.CSSAnimate({opacity: YTPlayer.isAlone ? 1 : YTPlayer.opt.opacity}, 2000);
  280. if (YTPlayer.opt.mute) {
  281. jQuery(YTPlayer).muteYTPVolume();
  282. }else{
  283. jQuery(YTPlayer).unmuteYTPVolume();
  284. }
  285. }
  286. }, 1);
  287. } else {
  288. $YTPlayer.playYTP();
  289. YTPlayer.player.setVolume(YTPlayer.opt.vol);
  290. if (YTPlayer.opt.mute) {
  291. jQuery(YTPlayer).muteYTPVolume();
  292. }else{
  293. jQuery(YTPlayer).unmuteYTPVolume();
  294. }
  295. }
  296. if (typeof YTPlayer.opt.onReady == "function")
  297. YTPlayer.opt.onReady($YTPlayer);
  298. jQuery.mbYTPlayer.checkForState(YTPlayer);
  299. },
  300. 'onStateChange' : function (event) {
  301. /*
  302. -1 (unstarted)
  303. 0 (ended)
  304. 1 (playing)
  305. 2 (paused)
  306. 3 (buffering)
  307. 5 (video cued).
  308. */
  309. if (typeof event.target.getPlayerState != "function")
  310. return;
  311. var state = event.target.getPlayerState();
  312. if (typeof YTPlayer.opt.onStateChange == "function")
  313. YTPlayer.opt.onStateChange($YTPlayer, state);
  314. var playerBox = jQuery(YTPlayer.playerEl);
  315. var controls = jQuery("#controlBar_" + YTPlayer.id);
  316. var data = YTPlayer.opt;
  317. if (state == 0) { // end
  318. if (YTPlayer.state == state)
  319. return;
  320. YTPlayer.state = state;
  321. YTPlayer.player.pauseVideo();
  322. var startAt = YTPlayer.opt.startAt ? YTPlayer.opt.startAt : 1;
  323. if (data.loop) {
  324. YTPlayer.wrapper.css({opacity: 0});
  325. $YTPlayer.playYTP();
  326. YTPlayer.player.seekTo(startAt,true);
  327. } else if (!YTPlayer.isBackground) {
  328. YTPlayer.player.seekTo(startAt, true);
  329. $YTPlayer.playYTP();
  330. setTimeout(function () {
  331. $YTPlayer.pauseYTP();
  332. }, 10);
  333. }
  334. if (!data.loop && YTPlayer.isBackground)
  335. YTPlayer.wrapper.CSSAnimate({opacity: 0}, 2000);
  336. else if (data.loop) {
  337. YTPlayer.wrapper.css({opacity: 0});
  338. YTPlayer.loop++;
  339. }
  340. controls.find(".mb_YTVPPlaypause").html(jQuery.mbYTPlayer.controls.play);
  341. jQuery(YTPlayer).trigger("YTPEnd");
  342. }
  343. if (state == 3) { // buffering
  344. if (YTPlayer.state == state)
  345. return;
  346. YTPlayer.state = state;
  347. controls.find(".mb_YTVPPlaypause").html(jQuery.mbYTPlayer.controls.play);
  348. jQuery(YTPlayer).trigger("YTPBuffering");
  349. }
  350. if (state == -1) { // unstarted
  351. if (YTPlayer.state == state)
  352. return;
  353. YTPlayer.state = state;
  354. YTPlayer.wrapper.css({opacity:0});
  355. jQuery(YTPlayer).trigger("YTPUnstarted");
  356. }
  357. if (state == 1) { // play
  358. if (YTPlayer.state == state)
  359. return;
  360. YTPlayer.state = state;
  361. YTPlayer.player.setPlaybackQuality(YTPlayer.opt.quality);
  362. if(YTPlayer.opt.mute){
  363. $YTPlayer.muteYTPVolume();
  364. YTPlayer.opt.mute = false;
  365. }
  366. if (YTPlayer.opt.autoPlay && YTPlayer.loop == 0) {
  367. YTPlayer.wrapper.CSSAnimate({opacity: YTPlayer.isAlone ? 1 : YTPlayer.opt.opacity}, 2000);
  368. } else if(!YTPlayer.isBackground) {
  369. YTPlayer.wrapper.css({opacity: YTPlayer.isAlone ? 1 : YTPlayer.opt.opacity});
  370. $YTPlayer.css({background: "rgba(0,0,0,0.5)"});
  371. }else{
  372. setTimeout(function () {
  373. jQuery(YTPlayer.playerEl).CSSAnimate({opacity: 1}, 2000);
  374. YTPlayer.wrapper.CSSAnimate({opacity: YTPlayer.opt.opacity}, 2000);
  375. }, 1000);
  376. }
  377. controls.find(".mb_YTVPPlaypause").html(jQuery.mbYTPlayer.controls.pause);
  378. jQuery(YTPlayer).trigger("YTPStart");
  379. if (typeof _gaq != "undefined")
  380. _gaq.push(['_trackEvent', 'YTPlayer', 'Play', (YTPlayer.title || YTPlayer.videoID.toString())]);
  381. }
  382. if (state == 2) { // pause
  383. if (YTPlayer.state == state)
  384. return;
  385. YTPlayer.state = state;
  386. controls.find(".mb_YTVPPlaypause").html(jQuery.mbYTPlayer.controls.play);
  387. jQuery(YTPlayer).trigger("YTPPause");
  388. }
  389. },
  390. 'onPlaybackQualityChange': function (e) {
  391. if (typeof YTPlayer.opt.onPlaybackQualityChange == "function")
  392. YTPlayer.opt.onPlaybackQualityChange($YTPlayer);
  393. },
  394. 'onError' : function (err) {
  395. if(err.data == 2 && YTPlayer.isPlayList)
  396. jQuery(YTPlayer).playNext();
  397. if (typeof YTPlayer.opt.onError == "function")
  398. YTPlayer.opt.onError($YTPlayer, err);
  399. }
  400. }
  401. });
  402. });
  403. })
  404. });
  405. },
  406. getDataFromFeed: function (videoID, YTPlayer) {
  407. //Get video info from FEEDS API
  408. YTPlayer.videoID = videoID;
  409. if (!jQuery.browser.msie) { //!(jQuery.browser.msie && jQuery.browser.version<9)
  410. jQuery.getJSON(jQuery.mbYTPlayer.locationProtocol+'//gdata.youtube.com/feeds/api/videos/' + videoID + '?v=2&alt=jsonc', function (data, status, xhr) {
  411. YTPlayer.dataReceived = true;
  412. var videoData = data.data;
  413. YTPlayer.title = videoData.title;
  414. YTPlayer.videoData = videoData;
  415. if (YTPlayer.opt.ratio == "auto")
  416. if (videoData.aspectRatio && videoData.aspectRatio === "widescreen")
  417. YTPlayer.opt.ratio = "16/9";
  418. else
  419. YTPlayer.opt.ratio = "4/3";
  420. if(!YTPlayer.isInit){
  421. YTPlayer.isInit = true;
  422. if (!YTPlayer.isBackground) {
  423. var bgndURL = YTPlayer.videoData.thumbnail.hqDefault;
  424. jQuery(YTPlayer).css({background: "rgba(0,0,0,0.5) url(" + bgndURL + ") center center", backgroundSize: "cover"});
  425. }
  426. jQuery(document).trigger("getVideoInfo_" + YTPlayer.opt.id);
  427. }
  428. jQuery(YTPlayer).trigger("YTPChanged");
  429. });
  430. setTimeout(function(){
  431. if(!YTPlayer.dataReceived && !YTPlayer.isInit){
  432. YTPlayer.isInit = true;
  433. jQuery(document).trigger("getVideoInfo_" + YTPlayer.opt.id);
  434. }
  435. },2500)
  436. } else {
  437. YTPlayer.opt.ratio == "auto" ? YTPlayer.opt.ratio = "16/9" : YTPlayer.opt.ratio;
  438. if(!YTPlayer.isInit){
  439. YTPlayer.isInit = true;
  440. setTimeout(function(){
  441. jQuery(document).trigger("getVideoInfo_" + YTPlayer.opt.id);
  442. },100)
  443. }
  444. jQuery(YTPlayer).trigger("YTPChanged");
  445. }
  446. },
  447. getVideoID: function(){
  448. var YTPlayer = this.get(0);
  449. return YTPlayer.videoID || false ;
  450. },
  451. setVideoQuality: function(quality){
  452. var YTPlayer = this.get(0);
  453. YTPlayer.player.setPlaybackQuality(quality);
  454. },
  455. YTPlaylist : function(videos, shuffle, callback){
  456. var YTPlayer = this.get(0);
  457. YTPlayer.isPlayList = true;
  458. if(shuffle)
  459. videos = jQuery.shuffle(videos);
  460. if(!YTPlayer.videoID){
  461. YTPlayer.videos = videos;
  462. YTPlayer.videoCounter = 0;
  463. YTPlayer.videoLength = videos.length;
  464. jQuery(YTPlayer).data("property", videos[0]);
  465. jQuery(YTPlayer).mb_YTPlayer();
  466. }
  467. if(typeof callback == "function")
  468. jQuery(YTPlayer).on("YTPChanged",function(){
  469. callback(YTPlayer);
  470. });
  471. jQuery(YTPlayer).on("YTPEnd", function(){
  472. jQuery(YTPlayer).playNext();
  473. });
  474. },
  475. playNext: function(){
  476. var YTPlayer = this.get(0);
  477. YTPlayer.videoCounter++;
  478. if(YTPlayer.videoCounter>=YTPlayer.videoLength)
  479. YTPlayer.videoCounter = 0;
  480. jQuery(YTPlayer.playerEl).css({opacity:0});
  481. jQuery(YTPlayer).changeMovie(YTPlayer.videos[YTPlayer.videoCounter]);
  482. },
  483. playPrev: function(){
  484. var YTPlayer = this.get(0);
  485. YTPlayer.videoCounter--;
  486. if(YTPlayer.videoCounter<=0)
  487. YTPlayer.videoCounter = YTPlayer.videoLength;
  488. jQuery(YTPlayer.playerEl).css({opacity:0});
  489. jQuery(YTPlayer).changeMovie(YTPlayer.videos[YTPlayer.videoCounter]);
  490. },
  491. changeMovie: function (opt) {
  492. var YTPlayer = this.get(0);
  493. var data = YTPlayer.opt;
  494. if (opt) {
  495. jQuery.extend(data, opt);
  496. }
  497. YTPlayer.videoID = data.videoURL.getVideoID();
  498. jQuery(YTPlayer).pauseYTP();
  499. var timer = jQuery.browser.msie ? 1000 : 0;
  500. jQuery(YTPlayer).getPlayer().cueVideoByUrl(encodeURI(jQuery.mbYTPlayer.locationProtocol+"//www.youtube.com/v/" + YTPlayer.videoID) , 5 , YTPlayer.opt.quality);
  501. setTimeout(function(){
  502. jQuery(YTPlayer).playYTP();
  503. jQuery(YTPlayer).one("YTPStart", function(){
  504. jQuery(YTPlayer.playerEl).CSSAnimate({opacity:1},2000);
  505. });
  506. },timer)
  507. if (YTPlayer.opt.mute) {
  508. jQuery(YTPlayer).muteYTPVolume();
  509. }else{
  510. jQuery(YTPlayer).unmuteYTPVolume();
  511. }
  512. if (YTPlayer.opt.addRaster) {
  513. var retina = (window.retina || window.devicePixelRatio > 1);
  514. YTPlayer.overlay.addClass(retina ? "raster retina" : "raster");
  515. }else{
  516. YTPlayer.overlay.removeClass("raster");
  517. YTPlayer.overlay.removeClass("retina");
  518. }
  519. jQuery("#controlBar_" + YTPlayer.id).remove();
  520. if (YTPlayer.opt.showControls)
  521. jQuery(YTPlayer).buildYTPControls();
  522. jQuery.mbYTPlayer.getDataFromFeed(YTPlayer.videoID, YTPlayer);
  523. jQuery(YTPlayer).optimizeDisplay();
  524. jQuery.mbYTPlayer.checkForState(YTPlayer);
  525. },
  526. getPlayer: function () {
  527. return jQuery(this).get(0).player;
  528. },
  529. playerDestroy: function () {
  530. var YTPlayer = this.get(0);
  531. ytp.YTAPIReady = false;
  532. ytp.isInit = false;
  533. YTPlayer.opt.isInit = false;
  534. YTPlayer.videoID = null;
  535. var playerBox = YTPlayer.wrapper;
  536. playerBox.remove();
  537. jQuery("#controlBar_" + YTPlayer.id).remove();
  538. },
  539. fullscreen: function(real) {
  540. var YTPlayer = this.get(0);
  541. var controls = jQuery("#controlBar_" + YTPlayer.id);
  542. var fullScreenBtn = controls.find(".mb_OnlyYT");
  543. var videoWrapper = jQuery(YTPlayer.wrapper);
  544. if(real){
  545. var fullscreenchange = jQuery.browser.mozilla ? "mozfullscreenchange" : jQuery.browser.webkit ? "webkitfullscreenchange" : "fullscreenchange";
  546. jQuery(document).off(fullscreenchange);
  547. jQuery(document).on(fullscreenchange, function() {
  548. var isFullScreen = RunPrefixMethod(document, "IsFullScreen") || RunPrefixMethod(document, "FullScreen");
  549. if (!isFullScreen) {
  550. jQuery(YTPlayer).removeClass("fullscreen");
  551. YTPlayer.isAlone = false;
  552. fullScreenBtn.html(jQuery.mbYTPlayer.controls.onlyYT)
  553. jQuery(YTPlayer).setVideoQuality(YTPlayer.opt.quality);
  554. if (YTPlayer.isBackground){
  555. jQuery("body").after(controls);
  556. }else{
  557. YTPlayer.wrapper.before(controls);
  558. }
  559. jQuery(window).resize();
  560. }else{
  561. jQuery(YTPlayer).setVideoQuality("default");
  562. }
  563. });
  564. }
  565. if (!YTPlayer.isAlone) {
  566. if(YTPlayer.player.getPlayerState() != 1 && YTPlayer.player.getPlayerState() != 2)
  567. jQuery(YTPlayer).playYTP();
  568. if(real){
  569. YTPlayer.wrapper.append(controls);
  570. jQuery(YTPlayer).addClass("fullscreen");
  571. launchFullscreen(videoWrapper.get(0));
  572. } else
  573. videoWrapper.css({zIndex: 10000}).CSSAnimate({opacity: 1}, 1000, 0);
  574. jQuery(YTPlayer).trigger("YTPFullScreenStart");
  575. fullScreenBtn.html(jQuery.mbYTPlayer.controls.showSite)
  576. YTPlayer.isAlone = true;
  577. } else {
  578. if(real){
  579. cancelFullscreen();
  580. } else{
  581. videoWrapper.CSSAnimate({opacity: YTPlayer.opt.opacity}, 500);
  582. }
  583. jQuery(YTPlayer).trigger("YTPFullScreenEnd");
  584. videoWrapper.css({zIndex: -1});
  585. fullScreenBtn.html(jQuery.mbYTPlayer.controls.onlyYT)
  586. YTPlayer.isAlone = false;
  587. }
  588. function RunPrefixMethod(obj, method) {
  589. var pfx = ["webkit", "moz", "ms", "o", ""];
  590. var p = 0, m, t;
  591. while (p < pfx.length && !obj[m]) {
  592. m = method;
  593. if (pfx[p] == "") {
  594. m = m.substr(0,1).toLowerCase() + m.substr(1);
  595. }
  596. m = pfx[p] + m;
  597. t = typeof obj[m];
  598. if (t != "undefined") {
  599. pfx = [pfx[p]];
  600. return (t == "function" ? obj[m]() : obj[m]);
  601. }
  602. p++;
  603. }
  604. }
  605. function launchFullscreen(element) {
  606. RunPrefixMethod(element, "RequestFullScreen");
  607. }
  608. function cancelFullscreen() {
  609. if (RunPrefixMethod(document, "FullScreen") || RunPrefixMethod(document, "IsFullScreen")) {
  610. RunPrefixMethod(document, "CancelFullScreen");
  611. }
  612. }
  613. },
  614. playYTP: function () {
  615. var YTPlayer = this.get(0);
  616. var controls = jQuery("#controlBar_" + YTPlayer.id);
  617. var playBtn = controls.find(".mb_YTVPPlaypause");
  618. playBtn.html(jQuery.mbYTPlayer.controls.pause);
  619. YTPlayer.player.playVideo();
  620. YTPlayer.wrapper.CSSAnimate({opacity: YTPlayer.opt.opacity}, 2000);
  621. jQuery(YTPlayer).on("YTPStart", function(){
  622. jQuery(YTPlayer).css("background", "none");
  623. })
  624. },
  625. toggleLoops: function () {
  626. var YTPlayer = this.get(0);
  627. var data = YTPlayer.opt;
  628. if (data.loop == 1) {
  629. data.loop = 0;
  630. } else {
  631. if(data.startAt) {
  632. YTPlayer.player.seekTo(data.startAt);
  633. } else {
  634. YTPlayer.player.playVideo();
  635. }
  636. data.loop = 1;
  637. }
  638. },
  639. stopYTP: function () {
  640. var YTPlayer = this.get(0);
  641. var controls = jQuery("#controlBar_" + YTPlayer.id);
  642. var playBtn = controls.find(".mb_YTVPPlaypause");
  643. playBtn.html(jQuery.mbYTPlayer.controls.play);
  644. YTPlayer.player.stopVideo();
  645. },
  646. pauseYTP: function () {
  647. var YTPlayer = this.get(0);
  648. var data = YTPlayer.opt;
  649. var controls = jQuery("#controlBar_" + YTPlayer.id);
  650. var playBtn = controls.find(".mb_YTVPPlaypause");
  651. playBtn.html(jQuery.mbYTPlayer.controls.play);
  652. YTPlayer.player.pauseVideo();
  653. },
  654. seekToYTP: function(val) {
  655. var YTPlayer = this.get(0);
  656. YTPlayer.player.seekTo(val,true);
  657. },
  658. setYTPVolume: function (val) {
  659. var YTPlayer = this.get(0);
  660. if (!val && !YTPlayer.opt.vol && player.getVolume() == 0)
  661. jQuery(YTPlayer).unmuteYTPVolume();
  662. else if ((!val && YTPlayer.player.getVolume() > 0) || (val && YTPlayer.player.getVolume() == val))
  663. jQuery(YTPlayer).muteYTPVolume();
  664. else
  665. YTPlayer.opt.vol = val;
  666. YTPlayer.player.setVolume(YTPlayer.opt.vol);
  667. },
  668. muteYTPVolume: function () {
  669. var YTPlayer = this.get(0);
  670. YTPlayer.opt.vol = YTPlayer.player.getVolume() || 50;
  671. YTPlayer.player.mute();
  672. YTPlayer.player.setVolume(0);
  673. var controls = jQuery("#controlBar_" + YTPlayer.id);
  674. var muteBtn = controls.find(".mb_YTVPMuteUnmute");
  675. muteBtn.html(jQuery.mbYTPlayer.controls.unmute);
  676. },
  677. unmuteYTPVolume: function () {
  678. var YTPlayer = this.get(0);
  679. YTPlayer.player.unMute();
  680. YTPlayer.player.setVolume(YTPlayer.opt.vol);
  681. var controls = jQuery("#controlBar_" + YTPlayer.id);
  682. var muteBtn = controls.find(".mb_YTVPMuteUnmute");
  683. muteBtn.html(jQuery.mbYTPlayer.controls.mute);
  684. },
  685. manageYTPProgress: function () {
  686. var YTPlayer = this.get(0);
  687. var controls = jQuery("#controlBar_" + YTPlayer.id);
  688. var progressBar = controls.find(".mb_YTVPProgress");
  689. var loadedBar = controls.find(".mb_YTVPLoaded");
  690. var timeBar = controls.find(".mb_YTVTime");
  691. var totW = progressBar.outerWidth();
  692. var currentTime = Math.floor(YTPlayer.player.getCurrentTime());
  693. var totalTime = Math.floor(YTPlayer.player.getDuration());
  694. var timeW = (currentTime * totW) / totalTime;
  695. var startLeft = 0;
  696. var loadedW = YTPlayer.player.getVideoLoadedFraction() * 100;
  697. loadedBar.css({left: startLeft, width: loadedW + "%"});
  698. timeBar.css({left: 0, width: timeW});
  699. return {totalTime: totalTime, currentTime: currentTime};
  700. },
  701. buildYTPControls: function () {
  702. var YTPlayer = this.get(0);
  703. var data = YTPlayer.opt;
  704. if(jQuery("#controlBar_"+ YTPlayer.id).length)
  705. return;
  706. var controlBar = jQuery("<span/>").attr("id", "controlBar_" + YTPlayer.id).addClass("mb_YTVPBar").css({whiteSpace: "noWrap", position: YTPlayer.isBackground ? "fixed" : "absolute", zIndex: YTPlayer.isBackground ? 10000 : 1000}).hide();
  707. var buttonBar = jQuery("<div/>").addClass("buttonBar");
  708. var playpause = jQuery("<span>" + jQuery.mbYTPlayer.controls.play + "</span>").addClass("mb_YTVPPlaypause ytpicon").click(function () {
  709. if (YTPlayer.player.getPlayerState() == 1)
  710. jQuery(YTPlayer).pauseYTP();
  711. else
  712. jQuery(YTPlayer).playYTP();
  713. });
  714. var MuteUnmute = jQuery("<span>" + jQuery.mbYTPlayer.controls.mute + "</span>").addClass("mb_YTVPMuteUnmute ytpicon").click(function () {
  715. if (YTPlayer.player.getVolume()==0) {
  716. jQuery(YTPlayer).unmuteYTPVolume();
  717. } else {
  718. jQuery(YTPlayer).muteYTPVolume();
  719. }
  720. });
  721. var idx = jQuery("<span/>").addClass("mb_YTVPTime");
  722. var vURL = data.videoURL;
  723. if(vURL.indexOf("http") < 0)
  724. vURL = jQuery.mbYTPlayer.locationProtocol+"//www.youtube.com/watch?v="+data.videoURL;
  725. var movieUrl = jQuery("<span/>").html(jQuery.mbYTPlayer.controls.ytLogo).addClass("mb_YTVPUrl ytpicon").attr("title", "view on YouTube").on("click", function () {window.open(vURL, "viewOnYT")});
  726. var onlyVideo = jQuery("<span/>").html(jQuery.mbYTPlayer.controls.onlyYT).addClass("mb_OnlyYT ytpicon").on("click",function () {jQuery(YTPlayer).fullscreen(data.realfullscreen);});
  727. var progressBar = jQuery("<div/>").addClass("mb_YTVPProgress").css("position", "absolute").click(function (e) {
  728. timeBar.css({width: (e.clientX - timeBar.offset().left)});
  729. YTPlayer.timeW = e.clientX - timeBar.offset().left;
  730. controlBar.find(".mb_YTVPLoaded").css({width: 0});
  731. var totalTime = Math.floor(YTPlayer.player.getDuration());
  732. YTPlayer.goto = (timeBar.outerWidth() * totalTime) / progressBar.outerWidth();
  733. YTPlayer.player.seekTo(parseFloat(YTPlayer.goto), true);
  734. controlBar.find(".mb_YTVPLoaded").css({width: 0});
  735. });
  736. var loadedBar = jQuery("<div/>").addClass("mb_YTVPLoaded").css("position", "absolute");
  737. var timeBar = jQuery("<div/>").addClass("mb_YTVTime").css("position", "absolute");
  738. progressBar.append(loadedBar).append(timeBar);
  739. buttonBar.append(playpause).append(MuteUnmute).append(idx);
  740. if (data.printUrl){
  741. buttonBar.append(movieUrl);
  742. }
  743. if (YTPlayer.isBackground || (YTPlayer.opt.realfullscreen && !YTPlayer.isBackground))
  744. buttonBar.append(onlyVideo);
  745. controlBar.append(buttonBar).append(progressBar);
  746. if (!YTPlayer.isBackground) {
  747. controlBar.addClass("inlinePlayer");
  748. YTPlayer.wrapper.before(controlBar);
  749. } else {
  750. jQuery("body").after(controlBar);
  751. }
  752. controlBar.fadeIn();
  753. },
  754. checkForState:function(YTPlayer){
  755. var controlBar = jQuery("#controlBar_" + YTPlayer.id);
  756. var data = YTPlayer.opt;
  757. var startAt = YTPlayer.opt.startAt ? YTPlayer.opt.startAt : 1;
  758. YTPlayer.getState = setInterval(function () {
  759. var prog = jQuery(YTPlayer).manageYTPProgress();
  760. controlBar.find(".mb_YTVPTime").html(jQuery.mbYTPlayer.formatTime(prog.currentTime) + " / " + jQuery.mbYTPlayer.formatTime(prog.totalTime));
  761. if (parseFloat(YTPlayer.player.getDuration() - 3) < YTPlayer.player.getCurrentTime() && YTPlayer.player.getPlayerState() == 1 && !YTPlayer.isPlayList) {
  762. if(!data.loop){
  763. YTPlayer.player.pauseVideo();
  764. YTPlayer.wrapper.CSSAnimate({opacity: 0}, 2000,function(){
  765. YTPlayer.player.seekTo(startAt, true);
  766. if (!YTPlayer.isBackground) {
  767. var bgndURL = YTPlayer.videoData.thumbnail.hqDefault;
  768. jQuery(YTPlayer).css({background: "rgba(0,0,0,0.5) url(" + bgndURL + ") center center", backgroundSize: "cover"});
  769. }
  770. });
  771. }else
  772. YTPlayer.player.seekTo(startAt);
  773. jQuery(YTPlayer).trigger("YTPEnd");
  774. }
  775. }, 1);
  776. },
  777. formatTime : function (s) {
  778. var min = Math.floor(s / 60);
  779. var sec = Math.floor(s - (60 * min));
  780. return (min < 9 ? "0" + min : min) + " : " + (sec < 9 ? "0" + sec : sec);
  781. }
  782. };
  783. jQuery.fn.toggleVolume = function () {
  784. var YTPlayer = this.get(0);
  785. if (!YTPlayer)
  786. return;
  787. if (YTPlayer.player.isMuted()) {
  788. jQuery(YTPlayer).unmuteYTPVolume();
  789. return true;
  790. } else {
  791. jQuery(YTPlayer).muteYTPVolume();
  792. return false;
  793. }
  794. };
  795. jQuery.fn.optimizeDisplay = function () {
  796. var YTPlayer = this.get(0);
  797. var data = YTPlayer.opt;
  798. var playerBox = jQuery(YTPlayer.playerEl);
  799. var win = {};
  800. var el = !YTPlayer.isBackground ? data.containment : jQuery(window);
  801. win.width = el.width();
  802. win.height = el.height();
  803. var margin = 24;
  804. var vid = {};
  805. vid.width = win.width + ((win.width * margin) / 100);
  806. vid.height = data.ratio == "16/9" ? Math.ceil((9 * win.width) / 16) : Math.ceil((3 * win.width) / 4);
  807. vid.marginTop = -((vid.height - win.height) / 2);
  808. vid.marginLeft = -((win.width * (margin / 2)) / 100);
  809. if (vid.height < win.height) {
  810. vid.height = win.height + ((win.height * margin) / 100);
  811. vid.width = data.ratio == "16/9" ? Math.floor((16 * win.height) / 9) : Math.floor((4 * win.height) / 3);
  812. vid.marginTop = -((win.height * (margin / 2)) / 100);
  813. vid.marginLeft = -((vid.width - win.width) / 2);
  814. }
  815. playerBox.css({width: vid.width, height: vid.height, marginTop: vid.marginTop, marginLeft: vid.marginLeft});
  816. };
  817. jQuery.shuffle = function(arr) {
  818. var newArray = arr.slice();
  819. var len = newArray.length;
  820. var i = len;
  821. while (i--) {
  822. var p = parseInt(Math.random()*len);
  823. var t = newArray[i];
  824. newArray[i] = newArray[p];
  825. newArray[p] = t;
  826. }
  827. return newArray;
  828. };
  829. jQuery.fn.mb_YTPlayer = jQuery.mbYTPlayer.buildPlayer;
  830. jQuery.fn.YTPlaylist = jQuery.mbYTPlayer.YTPlaylist;
  831. jQuery.fn.playNext = jQuery.mbYTPlayer.playNext;
  832. jQuery.fn.playPrev = jQuery.mbYTPlayer.playPrev;
  833. jQuery.fn.changeMovie = jQuery.mbYTPlayer.changeMovie;
  834. jQuery.fn.getVideoID = jQuery.mbYTPlayer.getVideoID;
  835. jQuery.fn.getPlayer = jQuery.mbYTPlayer.getPlayer;
  836. jQuery.fn.playerDestroy = jQuery.mbYTPlayer.playerDestroy;
  837. jQuery.fn.fullscreen = jQuery.mbYTPlayer.fullscreen;
  838. jQuery.fn.buildYTPControls = jQuery.mbYTPlayer.buildYTPControls;
  839. jQuery.fn.playYTP = jQuery.mbYTPlayer.playYTP;
  840. jQuery.fn.toggleLoops = jQuery.mbYTPlayer.toggleLoops;
  841. jQuery.fn.stopYTP = jQuery.mbYTPlayer.stopYTP;
  842. jQuery.fn.pauseYTP = jQuery.mbYTPlayer.pauseYTP;
  843. jQuery.fn.seekToYTP = jQuery.mbYTPlayer.seekToYTP;
  844. jQuery.fn.muteYTPVolume = jQuery.mbYTPlayer.muteYTPVolume;
  845. jQuery.fn.unmuteYTPVolume = jQuery.mbYTPlayer.unmuteYTPVolume;
  846. jQuery.fn.setYTPVolume = jQuery.mbYTPlayer.setYTPVolume;
  847. jQuery.fn.setVideoQuality = jQuery.mbYTPlayer.setVideoQuality;
  848. jQuery.fn.manageYTPProgress = jQuery.mbYTPlayer.manageYTPProgress;
  849. })(jQuery, ytp);