Livemesh SiteOrigin Widgets - Version 2.5.9

Version Description

  • Tweak - Enabled lazy load for all the widgets except for the Posts Grid addon. Posts Grid utilizes the popular Isotope library for laying out grid elements and Isotope library is not compatible with lazy loading of images.
  • Updated - Freemius SDK 2.3.2 with Opt-In / Out Enhancements, User Change, and More.
Download this release

Release Info

Developer livemesh
Plugin Icon 128x128 Livemesh SiteOrigin Widgets
Version 2.5.9
Comparing to
See all releases

Code changes from version 2.5.7 to 2.5.9

Files changed (124) hide show
  1. admin/views/documentation.php +9 -0
  2. assets/css/jquery.mb.YTPlayer.min.css +45 -0
  3. assets/js/jquery.mb.YTPlayer.js +1403 -1403
  4. assets/js/jquery.mb.YTPlayer.min.js +6 -6
  5. freemius/.codeclimate.yml +0 -19
  6. freemius/.travis.yml +0 -11
  7. freemius/README.md +0 -253
  8. freemius/assets/css/admin/account.css +1 -1
  9. freemius/assets/css/admin/common.css +2 -2
  10. freemius/assets/css/admin/connect.css +1 -1
  11. freemius/assets/css/admin/deactivation-feedback.css +0 -2
  12. freemius/assets/css/admin/debug.css +1 -1
  13. freemius/assets/css/admin/dialog-boxes.css +1 -1
  14. freemius/assets/css/admin/license-activation.css +0 -2
  15. freemius/assets/css/admin/plugins.css +1 -0
  16. freemius/assets/css/customizer.css +1 -1
  17. freemius/assets/img/addons-for-beaver-builder.png +0 -0
  18. freemius/assets/img/addons-for-elementor.png +0 -0
  19. freemius/assets/img/livemesh-siteorigin-widgets.png +0 -0
  20. freemius/assets/js/nojquery.ba-postmessage.min.js +1 -12
  21. freemius/assets/js/nojquery.ba-postmessage.min.min.js +1 -0
  22. freemius/assets/js/nojquery.ba-postmessage.min.min.min.js +1 -0
  23. freemius/assets/js/postmessage.min.min.js +1 -0
  24. freemius/assets/scss/_colors.scss +0 -79
  25. freemius/assets/scss/_functions.scss +0 -0
  26. freemius/assets/scss/_load.scss +0 -4
  27. freemius/assets/scss/_mixins.scss +0 -270
  28. freemius/assets/scss/_start.scss +0 -4
  29. freemius/assets/scss/_vars.scss +0 -6
  30. freemius/assets/scss/admin/_ajax-loader.scss +0 -49
  31. freemius/assets/scss/admin/_auto-install.scss +0 -33
  32. freemius/assets/scss/admin/_buttons.scss +0 -28
  33. freemius/assets/scss/admin/_deactivation-feedback.scss +0 -55
  34. freemius/assets/scss/admin/_gdpr-consent.scss +0 -81
  35. freemius/assets/scss/admin/_license-activation.scss +0 -47
  36. freemius/assets/scss/admin/_license-key-resend.scss +0 -68
  37. freemius/assets/scss/admin/_modal-common.scss +0 -194
  38. freemius/assets/scss/admin/_multisite-options.scss +0 -40
  39. freemius/assets/scss/admin/_plugin-upgrade-notice.scss +0 -8
  40. freemius/assets/scss/admin/_subscription-cancellation.scss +0 -30
  41. freemius/assets/scss/admin/_themes.scss +0 -21
  42. freemius/assets/scss/admin/_tooltip.scss +0 -66
  43. freemius/assets/scss/admin/account.scss +0 -302
  44. freemius/assets/scss/admin/add-ons.scss +0 -449
  45. freemius/assets/scss/admin/affiliation.scss +0 -97
  46. freemius/assets/scss/admin/checkout.scss +0 -5
  47. freemius/assets/scss/admin/common.scss +0 -220
  48. freemius/assets/scss/admin/connect.scss +0 -548
  49. freemius/assets/scss/admin/debug.scss +0 -135
  50. freemius/assets/scss/admin/dialog-boxes.scss +0 -10
  51. freemius/assets/scss/admin/gdpr-optin-notice.scss +0 -17
  52. freemius/assets/scss/admin/index.php +0 -3
  53. freemius/assets/scss/customizer.scss +0 -125
  54. freemius/assets/scss/index.php +0 -3
  55. freemius/composer.json +0 -10
  56. freemius/gulpfile.js +0 -167
  57. freemius/gulpfile.min.js +0 -1
  58. freemius/includes/class-freemius.php +1589 -281
  59. freemius/includes/class-fs-plugin-updater.php +32 -2
  60. freemius/includes/class-fs-storage.php +45 -40
  61. freemius/includes/customizer/class-fs-customizer-upsell-control.php +5 -1
  62. freemius/includes/entities/class-fs-entity.php +10 -0
  63. freemius/includes/entities/class-fs-plugin-license.php +33 -0
  64. freemius/includes/entities/class-fs-plugin.php +5 -0
  65. freemius/includes/entities/class-fs-pricing.php +16 -0
  66. freemius/includes/entities/class-fs-site.php +3 -3
  67. freemius/includes/entities/class-fs-subscription.php +136 -114
  68. freemius/includes/fs-core-functions.php +282 -217
  69. freemius/includes/fs-essential-functions.php +5 -1
  70. freemius/includes/fs-plugin-info-dialog.php +27 -6
  71. freemius/includes/managers/class-fs-admin-menu-manager.php +53 -32
  72. freemius/includes/managers/class-fs-cache-manager.php +1 -1
  73. freemius/includes/managers/class-fs-option-manager.php +35 -11
  74. freemius/includes/managers/class-fs-plugin-manager.php +3 -3
  75. freemius/languages/freemius-cs_CZ.mo +0 -0
  76. freemius/languages/freemius-cs_CZ.po +2546 -0
  77. freemius/languages/freemius-da_DK.mo +0 -0
  78. freemius/languages/freemius-da_DK.po +727 -901
  79. freemius/languages/freemius-en.mo +0 -0
  80. freemius/languages/freemius-en.po +415 -379
  81. freemius/languages/freemius-es_ES.mo +0 -0
  82. freemius/languages/freemius-es_ES.po +508 -470
  83. freemius/languages/freemius-fr_FR.mo +0 -0
  84. freemius/languages/freemius-fr_FR.po +492 -454
  85. freemius/languages/freemius-he_IL.mo +0 -0
  86. freemius/languages/freemius-he_IL.po +491 -453
  87. freemius/languages/freemius-hu_HU.mo +0 -0
  88. freemius/languages/freemius-hu_HU.po +491 -453
  89. freemius/languages/freemius-it_IT.mo +0 -0
  90. freemius/languages/freemius-it_IT.po +542 -503
  91. freemius/languages/freemius-ja.mo +0 -0
  92. freemius/languages/{freemius-ja_JP.po → freemius-ja.po} +855 -604
  93. freemius/languages/freemius-ja_JP.mo +0 -0
  94. freemius/languages/freemius-nl_NL.mo +0 -0
  95. freemius/languages/freemius-nl_NL.po +492 -454
  96. freemius/languages/freemius-ru_RU.mo +0 -0
  97. freemius/languages/freemius-ru_RU.po +491 -453
  98. freemius/languages/freemius-ta.mo +0 -0
  99. freemius/languages/freemius-ta.po +2548 -0
  100. freemius/languages/freemius.pot +560 -451
  101. freemius/package.json +0 -27
  102. freemius/start.php +1 -1
  103. freemius/templates/account.php +225 -121
  104. freemius/templates/account/partials/addon.php +123 -84
  105. freemius/templates/account/partials/site.php +45 -29
  106. freemius/templates/add-ons.php +501 -440
  107. freemius/templates/connect.php +79 -25
  108. freemius/templates/debug.php +759 -726
  109. freemius/templates/debug/scheduled-crons.php +1 -1
  110. freemius/templates/forms/data-debug-mode.php +213 -0
  111. freemius/templates/forms/deactivation/form.php +1 -1
  112. freemius/templates/forms/license-activation.php +865 -700
  113. freemius/templates/forms/optout.php +329 -267
  114. freemius/templates/forms/subscription-cancellation.php +1 -1
  115. freemius/templates/forms/user-change.php +296 -0
  116. freemius/templates/powered-by.php +5 -2
  117. freemius/templates/pricing.php +1 -0
  118. freemius/templates/tabs.php +2 -2
  119. includes/helper-functions.php +10 -0
  120. includes/widgets/lsow-hero-image-widget/lsow-hero-image-widget.php +2 -2
  121. includes/widgets/lsow-portfolio-widget/tpl/default.php +7 -2
  122. livemesh-siteorigin-widgets.php +2 -2
  123. plugin.php +2 -2
  124. readme.txt +14 -5
admin/views/documentation.php CHANGED
@@ -1322,6 +1322,15 @@ else {
1322
1323
<h2>Change Log for the Premium Version</h2>
1324
<br>
1325
<h3>2.5.7</h3>
1326
<ul>
1327
<li>Fixed - The taxonomy chosen dropdown displaying superfluous taxonomies in the dropdown for Posts Grid/Posts Block.</li>
1322
1323
<h2>Change Log for the Premium Version</h2>
1324
<br>
1325
+ <h3>2.5.9</h3>
1326
+ <ul>
1327
+ <li>Tweak - Enabled lazy load for all the widgets except for the grid/gallery addons - Posts Grid, Video and Image Gallery. The Posts Grid and Gallery addons utilize the popular Isotope library for laying out grid elements and Isotope library is not compatible with lazy loading of images.</li>
1328
+ <li>Updated - Freemius SDK 2.3.2 with Opt-In / Out Enhancements, User Change, and More.</li>
1329
+ </ul>
1330
+ <h3>2.5.8</h3>
1331
+ <ul>
1332
+ <li>Updated - Freemius SDK 2.3.1 with white label mode, URL whitelisting and other features and bug fixes.</li>
1333
+ </ul>
1334
<h3>2.5.7</h3>
1335
<ul>
1336
<li>Fixed - The taxonomy chosen dropdown displaying superfluous taxonomies in the dropdown for Posts Grid/Posts Block.</li>
assets/css/jquery.mb.YTPlayer.min.css ADDED
@@ -0,0 +1,45 @@
1
+ @charset "UTF-8";
2
+ .mb_YTPlayer:focus {outline: 0}
3
+ .YTPWrapper {display: block;transform: translateZ(0) translate3d(0, 0, 0);transform-style: preserve-3d;perspective: 1000;-webkit-backface-visibility: hidden;backface-visibility: hidden;box-sizing: border-box}
4
+ .mb_YTPlayer .loading {position: absolute;top: 10px;right: 10px;font-size: 12px;color: #fff;background: rgba(0, 0, 0, .51);text-align: center;padding: 2px 4px;border-radius: 5px;font-family: "Droid Sans", sans-serif;-webkit-animation: fade .1s infinite alternate;animation: fade .1s infinite alternate}
5
+ @-webkit-keyframes fade {
6
+ 0% {opacity: .5}
7
+ 100% {opacity: 1}
8
+ }
9
+ @keyframes fade {
10
+ 0% {opacity: .5}
11
+ 100% {opacity: 1}
12
+ }
13
+ .YTPFullscreen {display: block !important;position: fixed !important;width: 100% !important;height: 100% !important;top: 0 !important;left: 0 !important;margin: 0 !important;border: none !important;opacity: 1 !important;background-color: #000 !important;padding: 0 !important}
14
+ .inlinePlayButton {font-family: ytpregular;font-size: 45px;color: #fff;text-align: center;border-radius: 100%;background-color: rgba(0, 0, 0, .4);position: absolute;width: 80px;height: 80px;line-height: 80px;top: 0;bottom: 0;left: 0;right: 0;margin: auto;cursor: pointer;opacity: .8;transition: all .4s;transform: scale(1.3)}
15
+ .mb_YTPlayer:hover .inlinePlayButton {opacity: 1;transform: scale(1)}
16
+ .inlinePlayButton:hover {background-color: rgba(0, 0, 0, 1);transform: scale(1.3) !important}
17
+ .mbYTP_wrapper iframe {max-width: 8000px !important}
18
+ .inline_YTPlayer {margin-bottom: 20px;vertical-align: top;position: relative;left: 0;overflow: hidden;border-radius: 4px;box-shadow: 0 0 5px rgba(0, 0, 0, .7);background: rgba(0, 0, 0, .5)}
19
+ .inline_YTPlayer img {border: none !important;margin: 0 !important;padding: 0 !important;transform: none !important}
20
+ .mb_YTPBar, .mb_YTPBar .buttonBar {box-sizing: border-box;left: 0;padding: 5px;width: 100%}
21
+ .mb_YTPBar .ytpicon {font-size: 20px;font-family: ytpregular}
22
+ .mb_YTPBar .mb_YTPUrl.ytpicon {font-size: 30px}
23
+ .mb_YTPBar {transition: opacity .5s;display: block;height: 10px;background: #333;position: fixed;bottom: 0;text-align: left;z-index: 1000;font: 14px/16px sans-serif;color: #fff;opacity: .1}
24
+ .mb_YTPBar.visible, .mb_YTPBar:hover {opacity: 1}
25
+ .mb_YTPBar .buttonBar {transition: all .5s;background: 0 0;font: 12px/14px san-serif;position: absolute;top: -30px;height: 40px}
26
+ .mb_YTPBar:hover .buttonBar {background: rgba(0, 0, 0, .4)}
27
+ .mb_YTPBar span {display: inline-block;font: 16px/20px sans-serif;position: relative;width: 30px;height: 25px;vertical-align: middle}
28
+ .mb_YTPBar span.mb_YTPTime {width: 130px}
29
+ .mb_YTPBar span.mb_OnlyYT, .mb_YTPBar span.mb_YTPUrl {position: absolute;width: auto;display: block;top: 6px;right: 10px;cursor: pointer}
30
+ .mb_YTPBar span.mb_YTPUrl img {width: 60px}
31
+ .mb_YTPBar span.mb_OnlyYT {left: 300px;right: auto}
32
+ .mb_YTPBar span.mb_OnlyYT img {width: 25px}
33
+ .mb_YTPBar span.mb_YTPUrl a {color: #fff}
34
+ .mb_YTPBar .mb_YTPMuteUnmute, .mb_YTPBar .mb_YTPPlayPause, .mb_YTPlayer .mb_YTPBar .mb_YTPPlayPause img {cursor: pointer}
35
+ .mb_YTPBar .mb_YTPProgress {height: 10px;width: 100%;background: #222;bottom: 0;left: 0}
36
+ .mb_YTPBar .mb_YTPLoaded {height: 10px;width: 0;background: #444;left: 0}
37
+ .mb_YTPBar .mb_YTPseekbar {height: 10px;width: 0;background: #bb110e;bottom: 0;left: 0;box-shadow: rgba(82, 82, 82, .47) 1px 1px 3px}
38
+ .mb_YTPBar .YTPOverlay {backface-visibility: hidden;-webkit-backface-visibility: hidden;-webkit-transform-style: "flat";box-sizing: border-box}
39
+ .mb_YTPBar .simpleSlider {position: relative;width: 100px;height: 10px;border: 1px solid #fff;overflow: hidden;box-sizing: border-box;margin-right: 10px;cursor: pointer !important;border-radius: 3px}
40
+ .mb_YTPBar.compact .simpleSlider {width: 40px}
41
+ .mb_YTPBar.compact span.mb_OnlyYT {left: 260px}
42
+ .mb_YTPBar .simpleSlider.muted {opacity: .3}
43
+ .mb_YTPBar .level {position: absolute;left: 0;bottom: 0;background-color: #fff;box-sizing: border-box}
44
+ .mb_YTPBar .level.horizontal {height: 100%;width: 0}
45
+ .mb_YTPBar .level.vertical {height: auto;width: 100%}
assets/js/jquery.mb.YTPlayer.js CHANGED
@@ -21,1437 +21,1437 @@
21
var ytp = ytp || {};
22
23
function onYouTubeIframeAPIReady() {
24
- if( ytp.YTAPIReady ) return;
25
- ytp.YTAPIReady = true;
26
- jQuery( document ).trigger( "YTAPIReady" );
27
}
28
29
var getYTPVideoID = function( url ) {
30
- var videoID, playlistID;
31
- if( url.indexOf( "youtu.be" ) > 0 ) {
32
- videoID = url.substr( url.lastIndexOf( "/" ) + 1, url.length );
33
- playlistID = videoID.indexOf( "?list=" ) > 0 ? videoID.substr( videoID.lastIndexOf( "=" ), videoID.length ) : null;
34
- videoID = playlistID ? videoID.substr( 0, videoID.lastIndexOf( "?" ) ) : videoID;
35
- } else if( url.indexOf( "http" ) > -1 ) {
36
- //videoID = url.match( /([\/&]v\/([^&#]*))|([\\?&]v=([^&#]*))/ )[ 1 ];
37
- videoID = url.match( /[\\?&]v=([^&#]*)/ )[ 1 ];
38
- playlistID = url.indexOf( "list=" ) > 0 ? url.match( /[\\?&]list=([^&#]*)/ )[ 1 ] : null;
39
- } else {
40
- videoID = url.length > 15 ? null : url;
41
- playlistID = videoID ? null : url;
42
- }
43
- return {
44
- videoID: videoID,
45
- playlistID: playlistID
46
- };
47
};
48
49
( function( jQuery, ytp ) {
50
51
- jQuery.mbYTPlayer = {
52
- name: "jquery.mb.YTPlayer",
53
- version: "2.9.5",
54
- build: "{{ build }}",
55
- author: "Matteo Bicocchi",
56
- apiKey: "",
57
- defaults: {
58
- containment: "body",
59
- ratio: "auto", // "auto", "16/9", "4/3"
60
- videoURL: null,
61
- playlistURL: null,
62
- startAt: 0,
63
- stopAt: 0,
64
- autoPlay: true,
65
- vol: 50, // 1 to 100
66
- addRaster: false,
67
- opacity: 1,
68
- quality: "default", //or “small”, “medium”, “large”, “hd720”, “hd1080”, “highres”
69
- mute: false,
70
- loop: true,
71
- showControls: true,
72
- showAnnotations: false,
73
- showYTLogo: true,
74
- stopMovieOnBlur: true,
75
- realfullscreen: true,
76
- gaTrack: true,
77
- optimizeDisplay: true,
78
- onReady: function( player ) {}
79
- },
80
- /* @fontface icons */
81
- controls: {
82
- play: "P",
83
- pause: "p",
84
- mute: "M",
85
- unmute: "A",
86
- onlyYT: "O",
87
- showSite: "R",
88
- ytLogo: "Y"
89
- },
90
- locationProtocol: "https:",
91
- /**
92
- *
93
- * @param options
94
- * @returns [players]
95
- */
96
- buildPlayer: function( options ) {
97
- return this.each( function() {
98
- var YTPlayer = this;
99
- var $YTPlayer = jQuery( YTPlayer );
100
- YTPlayer.loop = 0;
101
- YTPlayer.opt = {};
102
- YTPlayer.state = {};
103
- YTPlayer.filtersEnabled = true;
104
- YTPlayer.filters = {
105
- grayscale: {
106
- value: 0,
107
- unit: "%"
108
- },
109
- hue_rotate: {
110
- value: 0,
111
- unit: "deg"
112
- },
113
- invert: {
114
- value: 0,
115
- unit: "%"
116
- },
117
- opacity: {
118
- value: 0,
119
- unit: "%"
120
- },
121
- saturate: {
122
- value: 0,
123
- unit: "%"
124
- },
125
- sepia: {
126
- value: 0,
127
- unit: "%"
128
- },
129
- brightness: {
130
- value: 0,
131
- unit: "%"
132
- },
133
- contrast: {
134
- value: 0,
135
- unit: "%"
136
- },
137
- blur: {
138
- value: 0,
139
- unit: "px"
140
- }
141
- };
142
- $YTPlayer.addClass( "mb_YTPlayer" );
143
- var property = $YTPlayer.data( "property" ) && typeof $YTPlayer.data( "property" ) == "string" ? eval( '(' + $YTPlayer.data( "property" ) + ')' ) : $YTPlayer.data( "property" );
144
- if( typeof property != "undefined" && typeof property.vol != "undefined" ) property.vol = property.vol === 0 ? property.vol = 1 : property.vol;
145
- jQuery.extend( YTPlayer.opt, jQuery.mbYTPlayer.defaults, options, property );
146
- if( !YTPlayer.hasChanged ) {
147
- YTPlayer.defaultOpt = {};
148
- jQuery.extend( YTPlayer.defaultOpt, jQuery.mbYTPlayer.defaults, options, property );
149
- }
150
- YTPlayer.isRetina = ( window.retina || window.devicePixelRatio > 1 );
151
- var isIframe = function() {
152
- var isIfr = false;
153
- try {
154
- if( self.location.href != top.location.href ) isIfr = true;
155
- } catch( e ) {
156
- isIfr = true;
157
- }
158
- return isIfr;
159
- };
160
- YTPlayer.canGoFullScreen = !( jQuery.browser.msie || jQuery.browser.opera || isIframe() );
161
- if( !YTPlayer.canGoFullScreen ) YTPlayer.opt.realfullscreen = false;
162
- if( !$YTPlayer.attr( "id" ) ) $YTPlayer.attr( "id", "video_" + new Date().getTime() );
163
- var playerID = "mbYTP_" + YTPlayer.id;
164
- YTPlayer.isAlone = false;
165
- YTPlayer.hasFocus = true;
166
- var videoID = this.opt.videoURL ? getYTPVideoID( this.opt.videoURL ).videoID : $YTPlayer.attr( "href" ) ? getYTPVideoID( $YTPlayer.attr( "href" ) ).videoID : false;
167
- var playlistID = this.opt.videoURL ? getYTPVideoID( this.opt.videoURL ).playlistID : $YTPlayer.attr( "href" ) ? getYTPVideoID( $YTPlayer.attr( "href" ) ).playlistID : false;
168
- YTPlayer.videoID = videoID;
169
- YTPlayer.playlistID = playlistID;
170
- YTPlayer.opt.showAnnotations = ( YTPlayer.opt.showAnnotations ) ? '0' : '3';
171
- var playerVars = {
172
- 'autoplay': 0,
173
- 'modestbranding': 1,
174
- 'controls': 0,
175
- 'showinfo': 0,
176
- 'rel': 0,
177
- 'enablejsapi': 1,
178
- 'version': 3,
179
- 'playerapiid': playerID,
180
- 'origin': '*',
181
- 'allowfullscreen': true,
182
- 'wmode': 'transparent',
183
- 'iv_load_policy': YTPlayer.opt.showAnnotations
184
- };
185
- if( document.createElement( 'video' ).canPlayType ) jQuery.extend( playerVars, {
186
- 'html5': 1
187
- } );
188
- if( jQuery.browser.msie && jQuery.browser.version < 9 ) this.opt.opacity = 1;
189
- var playerBox = jQuery( "<div/>" ).attr( "id", playerID ).addClass( "playerBox" );
190
- var overlay = jQuery( "<div/>" ).css( {
191
- position: "absolute",
192
- top: 0,
193
- left: 0,
194
- width: "100%",
195
- height: "100%"
196
- } ).addClass( "YTPOverlay" );
197
- YTPlayer.isSelf = YTPlayer.opt.containment == "self";
198
- YTPlayer.defaultOpt.containment = YTPlayer.opt.containment = YTPlayer.opt.containment == "self" ? jQuery( this ) : jQuery( YTPlayer.opt.containment );
199
- YTPlayer.isBackground = YTPlayer.opt.containment.get( 0 ).tagName.toLowerCase() == "body";
200
- if( YTPlayer.isBackground && ytp.backgroundIsInited ) return;
201
- var isPlayer = YTPlayer.opt.containment.is( jQuery( this ) );
202
- YTPlayer.canPlayOnMobile = isPlayer && jQuery( this ).children().length === 0;
203
- if( !isPlayer ) {
204
- $YTPlayer.hide();
205
- } else {
206
- YTPlayer.isPlayer = true;
207
- }
208
- if( jQuery.browser.mobile && !YTPlayer.canPlayOnMobile ) {
209
- $YTPlayer.remove();
210
- return;
211
- }
212
- var wrapper = jQuery( "<div/>" ).addClass( "mbYTP_wrapper" ).attr( "id", "wrapper_" + playerID );
213
- wrapper.css( {
214
- position: "absolute",
215
- zIndex: 0,
216
- minWidth: "100%",
217
- minHeight: "100%",
218
- left: 0,
219
- top: 0,
220
- overflow: "hidden",
221
- opacity: 0
222
- } );
223
- playerBox.css( {
224
- position: "absolute",
225
- zIndex: 0,
226
- width: "100%",
227
- height: "100%",
228
- top: 0,
229
- left: 0,
230
- overflow: "hidden"
231
- } );
232
- wrapper.append( playerBox );
233
- YTPlayer.opt.containment.children().not( "script, style" ).each( function() {
234
- if( jQuery( this ).css( "position" ) == "static" ) jQuery( this ).css( "position", "relative" );
235
- } );
236
- if( YTPlayer.isBackground ) {
237
- jQuery( "body" ).css( {
238
- boxSizing: "border-box"
239
- } );
240
- wrapper.css( {
241
- position: "fixed",
242
- top: 0,
243
- left: 0,
244
- zIndex: 0
245
- } );
246
- $YTPlayer.hide();
247
- } else if( YTPlayer.opt.containment.css( "position" ) == "static" ) YTPlayer.opt.containment.css( {
248
- position: "relative"
249
- } );
250
- YTPlayer.opt.containment.prepend( wrapper );
251
- YTPlayer.wrapper = wrapper;
252
- playerBox.css( {
253
- opacity: 1
254
- } );
255
- if( !jQuery.browser.mobile ) {
256
- playerBox.after( overlay );
257
- YTPlayer.overlay = overlay;
258
- }
259
- if( !YTPlayer.isBackground ) {
260
- overlay.on( "mouseenter", function() {
261
- if( YTPlayer.controlBar ) YTPlayer.controlBar.addClass( "visible" );
262
- } ).on( "mouseleave", function() {
263
- if( YTPlayer.controlBar ) YTPlayer.controlBar.removeClass( "visible" );
264
- } )
265
- }
266
- if( !ytp.YTAPIReady ) {
267
- jQuery( "#YTAPI" ).remove();
268
- var tag = jQuery( "<script></script>" ).attr( {
269
- "src": jQuery.mbYTPlayer.locationProtocol + "//www.youtube.com/iframe_api?v=" + jQuery.mbYTPlayer.version,
270
- "id": "YTAPI"
271
- } );
272
- jQuery( "head" ).prepend( tag );
273
- } else {
274
- setTimeout( function() {
275
- jQuery( document ).trigger( "YTAPIReady" );
276
- }, 100 )
277
- }
278
- jQuery( document ).on( "YTAPIReady", function() {
279
- if( ( YTPlayer.isBackground && ytp.backgroundIsInited ) || YTPlayer.isInit ) return;
280
- if( YTPlayer.isBackground ) {
281
- ytp.backgroundIsInited = true;
282
- }
283
- YTPlayer.opt.autoPlay = typeof YTPlayer.opt.autoPlay == "undefined" ? ( YTPlayer.isBackground ? true : false ) : YTPlayer.opt.autoPlay;
284
- YTPlayer.opt.vol = YTPlayer.opt.vol ? YTPlayer.opt.vol : 100;
285
- jQuery.mbYTPlayer.getDataFromAPI( YTPlayer );
286
- jQuery( YTPlayer ).on( "YTPChanged", function() {
287
- if( YTPlayer.isInit ) return;
288
- YTPlayer.isInit = true;
289
- //if is mobile && isPlayer fallback to the default YT player
290
- if( jQuery.browser.mobile && YTPlayer.canPlayOnMobile ) {
291
- // Try to adjust the player dimention
292
- if( YTPlayer.opt.containment.outerWidth() > jQuery( window ).width() ) {
293
- YTPlayer.opt.containment.css( {
294
- maxWidth: "100%"
295
- } );
296
- var h = YTPlayer.opt.containment.outerWidth() * .6;
297
- YTPlayer.opt.containment.css( {
298
- maxHeight: h
299
- } );
300
- }
301
- new YT.Player( playerID, {
302
- videoId: YTPlayer.videoID.toString(),
303
- height: '100%',
304
- width: '100%',
305
- events: {
306
- 'onReady': function( event ) {
307
- YTPlayer.player = event.target;
308
- playerBox.css( {
309
- opacity: 1
310
- } );
311
- YTPlayer.wrapper.css( {
312
- opacity: 1
313
- } );
314
- }
315
- }
316
- } );
317
- return;
318
- }
319
- new YT.Player( playerID, {
320
- videoId: YTPlayer.videoID.toString(),
321
- playerVars: playerVars,
322
- events: {
323
- 'onReady': function( event ) {
324
- YTPlayer.player = event.target;
325
- if( YTPlayer.isReady ) return;
326
- YTPlayer.isReady = YTPlayer.isPlayer && !YTPlayer.opt.autoPlay ? false : true;
327
- YTPlayer.playerEl = YTPlayer.player.getIframe();
328
- $YTPlayer.optimizeDisplay();
329
- YTPlayer.videoID = videoID;
330
- jQuery( window ).on( "resize.YTP", function() {
331
- $YTPlayer.optimizeDisplay();
332
- } );
333
- jQuery.mbYTPlayer.checkForState( YTPlayer );
334
- // Trigger state events
335
- var YTPEvent = jQuery.Event( "YTPUnstarted" );
336
- YTPEvent.time = YTPlayer.player.time;
337
- if( YTPlayer.canTrigger ) jQuery( YTPlayer ).trigger( YTPEvent );
338
- },
339
- /**
340
- *
341
- * @param event
342
- *
343
- * -1 (unstarted)
344
- * 0 (ended)
345
- * 1 (playing)
346
- * 2 (paused)
347
- * 3 (buffering)
348
- * 5 (video cued).
349
- *
350
- *
351
- */
352
- 'onStateChange': function( event ) {
353
- if( typeof event.target.getPlayerState != "function" ) return;
354
- var state = event.target.getPlayerState();
355
- if( YTPlayer.state == state ) return;
356
- YTPlayer.state = state;
357
- var eventType;
358
- switch( state ) {
359
- case -1: //------------------------------------------------ unstarted
360
- eventType = "YTPUnstarted";
361
- break;
362
- case 0: //------------------------------------------------ ended
363
- eventType = "YTPEnd";
364
- break;
365
- case 1: //------------------------------------------------ play
366
- eventType = "YTPStart";
367
- if( YTPlayer.controlBar ) YTPlayer.controlBar.find( ".mb_YTPPlaypause" ).html( jQuery.mbYTPlayer.controls.pause );
368
- if( typeof _gaq != "undefined" && eval( YTPlayer.opt.gaTrack ) ) _gaq.push( [ '_trackEvent', 'YTPlayer', 'Play', ( YTPlayer.hasData ? YTPlayer.videoData.title : YTPlayer.videoID.toString() ) ] );
369
- if( typeof ga != "undefined" && eval( YTPlayer.opt.gaTrack ) ) ga( 'send', 'event', 'YTPlayer', 'play', ( YTPlayer.hasData ? YTPlayer.videoData.title : YTPlayer.videoID.toString() ) );
370
- break;
371
- case 2: //------------------------------------------------ pause
372
- eventType = "YTPPause";
373
- if( YTPlayer.controlBar ) YTPlayer.controlBar.find( ".mb_YTPPlaypause" ).html( jQuery.mbYTPlayer.controls.play );
374
- break;
375
- case 3: //------------------------------------------------ buffer
376
- YTPlayer.player.setPlaybackQuality( YTPlayer.opt.quality );
377
- eventType = "YTPBuffering";
378
- if( YTPlayer.controlBar ) YTPlayer.controlBar.find( ".mb_YTPPlaypause" ).html( jQuery.mbYTPlayer.controls.play );
379
- break;
380
- case 5: //------------------------------------------------ cued
381
- eventType = "YTPCued";
382
- break;
383
- default:
384
- break;
385
- }
386
- // Trigger state events
387
- var YTPEvent = jQuery.Event( eventType );
388
- YTPEvent.time = YTPlayer.player.time;
389
- if( YTPlayer.canTrigger ) jQuery( YTPlayer ).trigger( YTPEvent );
390
- },
391
- /**
392
- *
393
- * @param e
394
- */
395
- 'onPlaybackQualityChange': function( e ) {
396
- var quality = e.target.getPlaybackQuality();
397
- var YTPQualityChange = jQuery.Event( "YTPQualityChange" );
398
- YTPQualityChange.quality = quality;
399
- jQuery( YTPlayer ).trigger( YTPQualityChange );
400
- },
401
- /**
402
- *
403
- * @param err
404
- */
405
- 'onError': function( err ) {
406
- if( err.data == 150 ) {
407
- console.log( "Embedding this video is restricted by Youtube." );
408
- if( YTPlayer.isPlayList ) jQuery( YTPlayer ).playNext();
409
- }
410
- if( err.data == 2 && YTPlayer.isPlayList ) jQuery( YTPlayer ).playNext();
411
- if( typeof YTPlayer.opt.onError == "function" ) YTPlayer.opt.onError( $YTPlayer, err );
412
- }
413
- }
414
- } );
415
- } );
416
- } )
417
- } );
418
- },
419
- /**
420
- *
421
- * @param YTPlayer
422
- */
423
- getDataFromAPI: function( YTPlayer ) {
424
- YTPlayer.videoData = jQuery.mbStorage.get( "YTPlayer_data_" + YTPlayer.videoID );
425
- jQuery( YTPlayer ).off( "YTPData.YTPlayer" ).on( "YTPData.YTPlayer", function() {
426
- if( YTPlayer.hasData ) {
427
428
- if( YTPlayer.isPlayer && !YTPlayer.opt.autoPlay ) {
429
- var bgndURL = YTPlayer.videoData.thumb_max || YTPlayer.videoData.thumb_high || YTPlayer.videoData.thumb_medium;
430
- YTPlayer.opt.containment.css( {
431
- background: "rgba(0,0,0,0.5) url(" + bgndURL + ") center center",
432
- backgroundSize: "cover"
433
- } );
434
- YTPlayer.opt.backgroundUrl = bgndURL;
435
- }
436
- }
437
- } );
438
439
- if( YTPlayer.videoData ) {
440
441
- setTimeout( function() {
442
- YTPlayer.opt.ratio = YTPlayer.opt.ratio == "auto" ? "16/9" : YTPlayer.opt.ratio;
443
- YTPlayer.dataReceived = true;
444
- jQuery( YTPlayer ).trigger( "YTPChanged" );
445
- var YTPData = jQuery.Event( "YTPData" );
446
- YTPData.prop = {};
447
- for( var x in YTPlayer.videoData ) YTPData.prop[ x ] = YTPlayer.videoData[ x ];
448
- jQuery( YTPlayer ).trigger( YTPData );
449
- }, 500 );
450
451
- YTPlayer.hasData = true;
452
- } else if( jQuery.mbYTPlayer.apiKey ) {
453
- // Get video info from API3 (needs api key)
454
- // snippet,player,contentDetails,statistics,status
455
- jQuery.getJSON( jQuery.mbYTPlayer.locationProtocol + "//www.googleapis.com/youtube/v3/videos?id=" + YTPlayer.videoID + "&key=" + jQuery.mbYTPlayer.apiKey + "&part=snippet", function( data ) {
456
- YTPlayer.dataReceived = true;
457
- jQuery( YTPlayer ).trigger( "YTPChanged" );
458
459
- function parseYTPlayer_data( data ) {
460
- YTPlayer.videoData = {};
461
- YTPlayer.videoData.id = YTPlayer.videoID;
462
- YTPlayer.videoData.channelTitle = data.channelTitle;
463
- YTPlayer.videoData.title = data.title;
464
- YTPlayer.videoData.description = data.description.length < 400 ? data.description : data.description.substring( 0, 400 ) + " ...";
465
- YTPlayer.videoData.aspectratio = YTPlayer.opt.ratio == "auto" ? "16/9" : YTPlayer.opt.ratio;
466
- YTPlayer.opt.ratio = YTPlayer.videoData.aspectratio;
467
- YTPlayer.videoData.thumb_max = data.thumbnails.maxres ? data.thumbnails.maxres.url : null;
468
- YTPlayer.videoData.thumb_high = data.thumbnails.high ? data.thumbnails.high.url : null;
469
- YTPlayer.videoData.thumb_medium = data.thumbnails.medium ? data.thumbnails.medium.url : null;
470
- jQuery.mbStorage.set( "YTPlayer_data_" + YTPlayer.videoID, YTPlayer.videoData );
471
- }
472
- parseYTPlayer_data( data.items[ 0 ].snippet );
473
- YTPlayer.hasData = true;
474
- var YTPData = jQuery.Event( "YTPData" );
475
- YTPData.prop = {};
476
- for( var x in YTPlayer.videoData ) YTPData.prop[ x ] = YTPlayer.videoData[ x ];
477
- jQuery( YTPlayer ).trigger( YTPData );
478
- } );
479
- } else {
480
- setTimeout( function() {
481
- jQuery( YTPlayer ).trigger( "YTPChanged" );
482
- }, 50 );
483
- if( YTPlayer.isPlayer && !YTPlayer.opt.autoPlay ) {
484
- var bgndURL = jQuery.mbYTPlayer.locationProtocol + "//i.ytimg.com/vi/" + YTPlayer.videoID + "/hqdefault.jpg";
485
- YTPlayer.opt.containment.css( {
486
- background: "rgba(0,0,0,0.5) url(" + bgndURL + ") center center",
487
- backgroundSize: "cover"
488
- } );
489
- YTPlayer.opt.backgroundUrl = bgndURL;
490
- }
491
- YTPlayer.videoData = null;
492
- YTPlayer.opt.ratio = YTPlayer.opt.ratio == "auto" ? "16/9" : YTPlayer.opt.ratio;
493
- }
494
- if( YTPlayer.isPlayer && !YTPlayer.opt.autoPlay ) {
495
- YTPlayer.loading = jQuery( "<div/>" ).addClass( "loading" ).html( "Loading" ).hide();
496
- jQuery( YTPlayer ).append( YTPlayer.loading );
497
- YTPlayer.loading.fadeIn();
498
- }
499
- },
500
- /**
501
- *
502
- */
503
- removeStoredData: function() {
504
- jQuery.mbStorage.remove();
505
- },
506
- /**
507
- *
508
- * @returns {*|YTPlayer.videoData}
509
- */
510
- getVideoData: function() {
511
- var YTPlayer = this.get( 0 );
512
- return YTPlayer.videoData;
513
- },
514
- /**
515
- *
516
- * @returns {*|YTPlayer.videoID|boolean}
517
- */
518
- getVideoID: function() {
519
- var YTPlayer = this.get( 0 );
520
- return YTPlayer.videoID || false;
521
- },
522
- /**
523
- *
524
- * @param quality
525
- */
526
- setVideoQuality: function( quality ) {
527
- var YTPlayer = this.get( 0 );
528
- if( !jQuery.browser.chrome ) YTPlayer.player.setPlaybackQuality( quality );
529
- },
530
- /**
531
- * @param videos
532
- * @param shuffle
533
- * @param callback
534
- * @returns {jQuery.mbYTPlayer}
535
- */
536
- playlist: function( videos, shuffle, callback ) {
537
- var $YTPlayer = this;
538
- var YTPlayer = $YTPlayer.get( 0 );
539
- YTPlayer.isPlayList = true;
540
- if( shuffle ) videos = jQuery.shuffle( videos );
541
- if( !YTPlayer.videoID ) {
542
- YTPlayer.videos = videos;
543
- YTPlayer.videoCounter = 0;
544
- YTPlayer.videoLength = videos.length;
545
- jQuery( YTPlayer ).data( "property", videos[ 0 ] );
546
- jQuery( YTPlayer ).mb_YTPlayer();
547
- }
548
- if( typeof callback == "function" ) jQuery( YTPlayer ).one( "YTPChanged", function() {
549
- callback( YTPlayer );
550
- } );
551
- jQuery( YTPlayer ).on( "YTPEnd", function() {
552
- jQuery( YTPlayer ).playNext();
553
- } );
554
- return $YTPlayer;
555
- },
556
- /**
557
- *
558
- * @returns {jQuery.mbYTPlayer}
559
- */
560
- playNext: function() {
561
- var YTPlayer = this.get( 0 );
562
- YTPlayer.videoCounter++;
563
- if( YTPlayer.videoCounter >= YTPlayer.videoLength ) YTPlayer.videoCounter = 0;
564
- jQuery( YTPlayer ).changeMovie( YTPlayer.videos[ YTPlayer.videoCounter ] );
565
- return this;
566
- },
567
- /**
568
- *
569
- * @returns {jQuery.mbYTPlayer}
570
- */
571
- playPrev: function() {
572
- var YTPlayer = this.get( 0 );
573
- YTPlayer.videoCounter--;
574
- if( YTPlayer.videoCounter < 0 ) YTPlayer.videoCounter = YTPlayer.videoLength - 1;
575
- jQuery( YTPlayer ).changeMovie( YTPlayer.videos[ YTPlayer.videoCounter ] );
576
- return this;
577
- },
578
- /**
579
- *
580
- * @param opt
581
- */
582
- changeMovie: function( opt ) {
583
- var YTPlayer = this.get( 0 );
584
- YTPlayer.opt.startAt = 0;
585
- YTPlayer.opt.stopAt = 0;
586
- YTPlayer.opt.mute = true;
587
- YTPlayer.hasData = false;
588
- YTPlayer.hasChanged = true;
589
- if( opt ) jQuery.extend( YTPlayer.opt, YTPlayer.defaultOpt, opt );
590
- YTPlayer.videoID = getYTPVideoID( YTPlayer.opt.videoURL ).videoID;
591
- jQuery( YTPlayer.playerEl ).CSSAnimate( {
592
- opacity: 0
593
- }, 200, function() {
594
- jQuery( YTPlayer ).YTPGetPlayer().cueVideoByUrl( encodeURI( jQuery.mbYTPlayer.locationProtocol + "//www.youtube.com/v/" + YTPlayer.videoID ), 1, YTPlayer.opt.quality );
595
- jQuery.mbYTPlayer.checkForState( YTPlayer );
596
- jQuery( YTPlayer ).optimizeDisplay();
597
- jQuery.mbYTPlayer.getDataFromAPI( YTPlayer );
598
- return this;
599
- } );
600
- },
601
- /**
602
- *
603
- * @returns {player}
604
- */
605
- getPlayer: function() {
606
- return jQuery( this ).get( 0 ).player;
607
- },
608
- playerDestroy: function() {
609
- var YTPlayer = this.get( 0 );
610
- ytp.YTAPIReady = false;
611
- ytp.backgroundIsInited = false;
612
- YTPlayer.isInit = false;
613
- YTPlayer.videoID = null;
614
- var playerBox = YTPlayer.wrapper;
615
- playerBox.remove();
616
- jQuery( "#controlBar_" + YTPlayer.id ).remove();
617
- clearInterval( YTPlayer.checkForStartAt );
618
- clearInterval( YTPlayer.getState );
619
- return this;
620
- },
621
- /**
622
- *
623
- * @param real
624
- * @returns {jQuery.mbYTPlayer}
625
- */
626
- fullscreen: function( real ) {
627
- var YTPlayer = this.get( 0 );
628
- if( typeof real == "undefined" ) real = YTPlayer.opt.realfullscreen;
629
- real = eval( real );
630
- var controls = jQuery( "#controlBar_" + YTPlayer.id );
631
- var fullScreenBtn = controls.find( ".mb_OnlyYT" );
632
- var videoWrapper = YTPlayer.isSelf ? YTPlayer.opt.containment : YTPlayer.wrapper;
633
- //var videoWrapper = YTPlayer.wrapper;
634
- if( real ) {
635
- var fullscreenchange = jQuery.browser.mozilla ? "mozfullscreenchange" : jQuery.browser.webkit ? "webkitfullscreenchange" : "fullscreenchange";
636
- jQuery( document ).off( fullscreenchange ).on( fullscreenchange, function() {
637
- var isFullScreen = RunPrefixMethod( document, "IsFullScreen" ) || RunPrefixMethod( document, "FullScreen" );
638
- if( !isFullScreen ) {
639
- YTPlayer.isAlone = false;
640
- fullScreenBtn.html( jQuery.mbYTPlayer.controls.onlyYT );
641
- jQuery( YTPlayer ).YTPSetVideoQuality( YTPlayer.opt.quality );
642
- videoWrapper.removeClass( "fullscreen" );
643
- videoWrapper.CSSAnimate( {
644
- opacity: YTPlayer.opt.opacity
645
- }, 500 );
646
- videoWrapper.css( {
647
- zIndex: 0
648
- } );
649
- if( YTPlayer.isBackground ) {
650
- jQuery( "body" ).after( controls );
651
- } else {
652
- YTPlayer.wrapper.before( controls );
653
- }
654
- jQuery( window ).resize();
655
- jQuery( YTPlayer ).trigger( "YTPFullScreenEnd" );
656
- } else {
657
- jQuery( YTPlayer ).YTPSetVideoQuality( "default" );
658
- jQuery( YTPlayer ).trigger( "YTPFullScreenStart" );
659
- }
660
- } );
661
- }
662
- if( !YTPlayer.isAlone ) {
663
- function hideMouse() {
664
- YTPlayer.overlay.css( {
665
- cursor: "none"
666
- } );
667
- }
668
- jQuery( document ).on( "mousemove.YTPlayer", function( e ) {
669
- YTPlayer.overlay.css( {
670
- cursor: "auto"
671
- } );
672
- clearTimeout( YTPlayer.hideCursor );
673
- if( !jQuery( e.target ).parents().is( ".mb_YTPBar" ) ) YTPlayer.hideCursor = setTimeout( hideMouse, 3000 );
674
- } );
675
- hideMouse();
676
- if( real ) {
677
- videoWrapper.css( {
678
- opacity: 0
679
- } );
680
- videoWrapper.addClass( "fullscreen" );
681
- launchFullscreen( videoWrapper.get( 0 ) );
682
- setTimeout( function() {
683
- videoWrapper.CSSAnimate( {
684
- opacity: 1
685
- }, 1000 );
686
- YTPlayer.wrapper.append( controls );
687
- jQuery( YTPlayer ).optimizeDisplay();
688
- YTPlayer.player.seekTo( YTPlayer.player.getCurrentTime() + .1, true );
689
- }, 500 )
690
- } else videoWrapper.css( {
691
- zIndex: 10000
692
- } ).CSSAnimate( {
693
- opacity: 1
694
- }, 1000 );
695
- fullScreenBtn.html( jQuery.mbYTPlayer.controls.showSite );
696
- YTPlayer.isAlone = true;
697
- } else {
698
- jQuery( document ).off( "mousemove.YTPlayer" );
699
- YTPlayer.overlay.css( {
700
- cursor: "auto"
701
- } );
702
- if( real ) {
703
- cancelFullscreen();
704
- } else {
705
- videoWrapper.CSSAnimate( {
706
- opacity: YTPlayer.opt.opacity
707
- }, 500 );
708
- videoWrapper.css( {
709
- zIndex: 0
710
- } );
711
- }
712
- fullScreenBtn.html( jQuery.mbYTPlayer.controls.onlyYT );
713
- YTPlayer.isAlone = false;
714
- }
715
716
- function RunPrefixMethod( obj, method ) {
717
- var pfx = [ "webkit", "moz", "ms", "o", "" ];
718
- var p = 0,
719
- m, t;
720
- while( p < pfx.length && !obj[ m ] ) {
721
- m = method;
722
- if( pfx[ p ] == "" ) {
723
- m = m.substr( 0, 1 ).toLowerCase() + m.substr( 1 );
724
- }
725
- m = pfx[ p ] + m;
726
- t = typeof obj[ m ];
727
- if( t != "undefined" ) {
728
- pfx = [ pfx[ p ] ];
729
- return( t == "function" ? obj[ m ]() : obj[ m ] );
730
- }
731
- p++;
732
- }
733
- }
734
735
- function launchFullscreen( element ) {
736
- RunPrefixMethod( element, "RequestFullScreen" );
737
- }
738
739
- function cancelFullscreen() {
740
- if( RunPrefixMethod( document, "FullScreen" ) || RunPrefixMethod( document, "IsFullScreen" ) ) {
741
- RunPrefixMethod( document, "CancelFullScreen" );
742
- }
743
- }
744
- return this;
745
- },
746
- /**
747
- *
748
- * @returns {jQuery.mbYTPlayer}
749
- */
750
- toggleLoops: function() {
751
- var YTPlayer = this.get( 0 );
752
- var data = YTPlayer.opt;
753
- if( data.loop == 1 ) {
754
- data.loop = 0;
755
- } else {
756
- if( data.startAt ) {
757
- YTPlayer.player.seekTo( data.startAt );
758
- } else {
759
- YTPlayer.player.playVideo();
760
- }
761
- data.loop = 1;
762
- }
763
- return this;
764
- },
765
- /**
766
- *
767
- * @returns {jQuery.mbYTPlayer}
768
- */
769
- play: function() {
770
- var YTPlayer = this.get( 0 );
771
- if( !YTPlayer.isReady ) return;
772
- var controls = jQuery( "#controlBar_" + YTPlayer.id );
773
- var playBtn = controls.find( ".mb_YTPPlaypause" );
774
- playBtn.html( jQuery.mbYTPlayer.controls.pause );
775
- YTPlayer.player.playVideo();
776
- YTPlayer.wrapper.CSSAnimate( {
777
- opacity: YTPlayer.isAlone ? 1 : YTPlayer.opt.opacity
778
- }, 2000 );
779
- jQuery( YTPlayer.playerEl ).CSSAnimate( {
780
- opacity: 1
781
- }, 1000 );
782
- jQuery( YTPlayer ).css( "background-image", "none" );
783
- return this;
784
- },
785
- /**
786
- *
787
- * @param callback
788
- * @returns {jQuery.mbYTPlayer}
789
- */
790
- togglePlay: function( callback ) {
791
- var YTPlayer = this.get( 0 );
792
- if( YTPlayer.state == 1 ) this.YTPPause();
793
- else this.YTPPlay();
794
- if( typeof callback == "function" ) {
795
- callback( YTPlayer.state );
796
- }
797
- return this;
798
- },
799
- /**
800
- *
801
- * @returns {jQuery.mbYTPlayer}
802
- */
803
- stop: function() {
804
- var YTPlayer = this.get( 0 );
805
- var controls = jQuery( "#controlBar_" + YTPlayer.id );
806
- var playBtn = controls.find( ".mb_YTPPlaypause" );
807
- playBtn.html( jQuery.mbYTPlayer.controls.play );
808
- YTPlayer.player.stopVideo();
809
- return this;
810
- },
811
- /**
812
- *
813
- * @returns {jQuery.mbYTPlayer}
814
- */
815
- pause: function() {
816
- var YTPlayer = this.get( 0 );
817
- var controls = jQuery( "#controlBar_" + YTPlayer.id );
818
- var playBtn = controls.find( ".mb_YTPPlaypause" );
819
- playBtn.html( jQuery.mbYTPlayer.controls.play );
820
- YTPlayer.player.pauseVideo();
821
- return this;
822
- },
823
- /**
824
- *
825
- * @param val
826
- * @returns {jQuery.mbYTPlayer}
827
- */
828
- seekTo: function( val ) {
829
- var YTPlayer = this.get( 0 );
830
- YTPlayer.player.seekTo( val, true );
831
- return this;
832
- },
833
- /**
834
- *
835
- * @param val
836
- * @returns {jQuery.mbYTPlayer}
837
- */
838
- setVolume: function( val ) {
839
- var YTPlayer = this.get( 0 );
840
- if( !val && !YTPlayer.opt.vol && YTPlayer.player.getVolume() == 0 ) jQuery( YTPlayer ).YTPUnmute();
841
- else if( ( !val && YTPlayer.player.getVolume() > 0 ) || ( val && YTPlayer.opt.vol == val ) ) {
842
- if( !YTPlayer.isMute ) jQuery( YTPlayer ).YTPMute();
843
- else jQuery( YTPlayer ).YTPUnmute();
844
- } else {
845
- YTPlayer.opt.vol = val;
846
- YTPlayer.player.setVolume( YTPlayer.opt.vol );
847
- if( YTPlayer.volumeBar && YTPlayer.volumeBar.length ) YTPlayer.volumeBar.updateSliderVal( val )
848
- }
849
- return this;
850
- },
851
- /**
852
- *
853
- * @returns {jQuery.mbYTPlayer}
854
- */
855
- mute: function() {
856
- var YTPlayer = this.get( 0 );
857
- if( YTPlayer.isMute ) return;
858
- YTPlayer.player.mute();
859
- YTPlayer.isMute = true;
860
- YTPlayer.player.setVolume( 0 );
861
- if( YTPlayer.volumeBar && YTPlayer.volumeBar.length && YTPlayer.volumeBar.width() > 10 ) {
862
- YTPlayer.volumeBar.updateSliderVal( 0 );
863
- }
864
- var controls = jQuery( "#controlBar_" + YTPlayer.id );
865
- var muteBtn = controls.find( ".mb_YTPMuteUnmute" );
866
- muteBtn.html( jQuery.mbYTPlayer.controls.unmute );
867
- jQuery( YTPlayer ).addClass( "isMuted" );
868
- if( YTPlayer.volumeBar && YTPlayer.volumeBar.length ) YTPlayer.volumeBar.addClass( "muted" );
869
- var YTPEvent = jQuery.Event( "YTPMuted" );
870
- YTPEvent.time = YTPlayer.player.time;
871
- if( YTPlayer.canTrigger ) jQuery( YTPlayer ).trigger( YTPEvent );
872
- return this;
873
- },
874
- /**
875
- *
876
- * @returns {jQuery.mbYTPlayer}
877
- */
878
- unmute: function() {
879
- var YTPlayer = this.get( 0 );
880
- if( !YTPlayer.isMute ) return;
881
- YTPlayer.player.unMute();
882
- YTPlayer.isMute = false;
883
- YTPlayer.player.setVolume( YTPlayer.opt.vol );
884
- if( YTPlayer.volumeBar && YTPlayer.volumeBar.length ) YTPlayer.volumeBar.updateSliderVal( YTPlayer.opt.vol > 10 ? YTPlayer.opt.vol : 10 );
885
- var controls = jQuery( "#controlBar_" + YTPlayer.id );
886
- var muteBtn = controls.find( ".mb_YTPMuteUnmute" );
887
- muteBtn.html( jQuery.mbYTPlayer.controls.mute );
888
- jQuery( YTPlayer ).removeClass( "isMuted" );
889
- if( YTPlayer.volumeBar && YTPlayer.volumeBar.length ) YTPlayer.volumeBar.removeClass( "muted" );
890
- var YTPEvent = jQuery.Event( "YTPUnmuted" );
891
- YTPEvent.time = YTPlayer.player.time;
892
- if( YTPlayer.canTrigger ) jQuery( YTPlayer ).trigger( YTPEvent );
893
- return this;
894
- },
895
- /**
896
- *
897
- * @param filter
898
- * @param value
899
- * @returns {jQuery.mbYTPlayer}
900
- */
901
- applyFilter: function( filter, value ) {
902
- var YTPlayer = this.get( 0 );
903
- YTPlayer.filters[ filter ].value = value;
904
- if( YTPlayer.filtersEnabled ) this.YTPEnableFilters();
905
- return this;
906
- },
907
- /**
908
- *
909
- * @param filters
910
- * @returns {jQuery.mbYTPlayer}
911
- */
912
- applyFilters: function( filters ) {
913
- var YTPlayer = this.get( 0 );
914
- this.on( "YTPReady", function() {
915
- for( var key in filters ) {
916
- YTPlayer.filters[ key ].value = filters[ key ];
917
- jQuery( YTPlayer ).YTPApplyFilter( key, filters[ key ] );
918
- }
919
- jQuery( YTPlayer ).trigger( "YTPFiltersApplied" );
920
- } );
921
- return this;
922
- },
923
- /**
924
- *
925
- * @param filter
926
- * @param value
927
- * @returns {*}
928
- */
929
- toggleFilter: function( filter, value ) {
930
- return this.each( function() {
931
- var YTPlayer = this;
932
- if( !YTPlayer.filters[ filter ].value ) YTPlayer.filters[ filter ].value = value;
933
- else YTPlayer.filters[ filter ].value = 0;
934
- if( YTPlayer.filtersEnabled ) jQuery( this ).YTPEnableFilters();
935
- } )
936
- return this;
937
- },
938
- /**
939
- *
940
- * @param callback
941
- * @returns {*}
942
- */
943
- toggleFilters: function( callback ) {
944
- return this.each( function() {
945
- var YTPlayer = this;
946
- if( YTPlayer.filtersEnabled ) {
947
- jQuery( YTPlayer ).trigger( "YTPDisableFilters" );
948
- jQuery( YTPlayer ).YTPDisableFilters();
949
- } else {
950
- jQuery( YTPlayer ).YTPEnableFilters();
951
- jQuery( YTPlayer ).trigger( "YTPEnableFilters" );
952
- }
953
- if( typeof callback == "function" ) callback( YTPlayer.filtersEnabled );
954
- } )
955
- },
956
- /**
957
- *
958
- * @returns {*}
959
- */
960
- disableFilters: function() {
961
- return this.each( function() {
962
- var YTPlayer = this;
963
- var iframe = jQuery( YTPlayer.playerEl );
964
- iframe.css( "-webkit-filter", "" );
965
- iframe.css( "filter", "" );
966
- YTPlayer.filtersEnabled = false;
967
- } )
968
- },
969
- /**
970
- *
971
- * @returns {*}
972
- */
973
- enableFilters: function() {
974
- return this.each( function() {
975
- var YTPlayer = this;
976
- var iframe = jQuery( YTPlayer.playerEl );
977
- var filterStyle = "";
978
- for( var key in YTPlayer.filters ) {
979
- if( YTPlayer.filters[ key ].value ) filterStyle += key.replace( "_", "-" ) + "(" + YTPlayer.filters[ key ].value + YTPlayer.filters[ key ].unit + ") ";
980
- }
981
- iframe.css( "-webkit-filter", filterStyle );
982
- iframe.css( "filter", filterStyle );
983
- YTPlayer.filtersEnabled = true;
984
- } )
985
- return this;
986
- },
987
- /**
988
- *
989
- * @param filter
990
- * @param callback
991
- * @returns {*}
992
- */
993
- removeFilter: function( filter, callback ) {
994
- return this.each( function() {
995
- if( typeof filter == "function" ) {
996
- callback = filter;
997
- filter = null;
998
- }
999
- var YTPlayer = this;
1000
- if( !filter )
1001
- for( var key in YTPlayer.filters ) {
1002
- jQuery( this ).YTPApplyFilter( key, 0 );
1003
- if( typeof callback == "function" ) callback( key );
1004
- } else {
1005
- jQuery( this ).YTPApplyFilter( filter, 0 );
1006
- if( typeof callback == "function" ) callback( filter );
1007
- }
1008
- } );
1009
- return this;
1010
- },
1011
- /**
1012
- *
1013
- * @returns {{totalTime: number, currentTime: number}}
1014
- */
1015
- manageProgress: function() {
1016
- var YTPlayer = this.get( 0 );
1017
- var controls = jQuery( "#controlBar_" + YTPlayer.id );
1018
- var progressBar = controls.find( ".mb_YTPProgress" );
1019
- var loadedBar = controls.find( ".mb_YTPLoaded" );
1020
- var timeBar = controls.find( ".mb_YTPseekbar" );
1021
- var totW = progressBar.outerWidth();
1022
- var currentTime = Math.floor( YTPlayer.player.getCurrentTime() );
1023
- var totalTime = Math.floor( YTPlayer.player.getDuration() );
1024
- var timeW = ( currentTime * totW ) / totalTime;
1025
- var startLeft = 0;
1026
- var loadedW = YTPlayer.player.getVideoLoadedFraction() * 100;
1027
- loadedBar.css( {
1028
- left: startLeft,
1029
- width: loadedW + "%"
1030
- } );
1031
- timeBar.css( {
1032
- left: 0,
1033
- width: timeW
1034
- } );
1035
- return {
1036
- totalTime: totalTime,
1037
- currentTime: currentTime
1038
- };
1039
- },
1040
- /**
1041
- *
1042
- * @param YTPlayer
1043
- */
1044
- buildControls: function( YTPlayer ) {
1045
- var data = YTPlayer.opt;
1046
- // @data.printUrl: is deprecated; use data.showYTLogo
1047
- data.showYTLogo = data.showYTLogo || data.printUrl;
1048
- if( jQuery( "#controlBar_" + YTPlayer.id ).length ) return;
1049
- YTPlayer.controlBar = jQuery( "<span/>" ).attr( "id", "controlBar_" + YTPlayer.id ).addClass( "mb_YTPBar" ).css( {
1050
- whiteSpace: "noWrap",
1051
- position: YTPlayer.isBackground ? "fixed" : "absolute",
1052
- zIndex: YTPlayer.isBackground ? 10000 : 1000
1053
- } ).hide();
1054
- var buttonBar = jQuery( "<div/>" ).addClass( "buttonBar" );
1055
- /* play/pause button*/
1056
- var playpause = jQuery( "<span>" + jQuery.mbYTPlayer.controls.play + "</span>" ).addClass( "mb_YTPPlaypause ytpicon" ).click( function() {
1057
- if( YTPlayer.player.getPlayerState() == 1 ) jQuery( YTPlayer ).YTPPause();
1058
- else jQuery( YTPlayer ).YTPPlay();
1059
- } );
1060
- /* mute/unmute button*/
1061
- var MuteUnmute = jQuery( "<span>" + jQuery.mbYTPlayer.controls.mute + "</span>" ).addClass( "mb_YTPMuteUnmute ytpicon" ).click( function() {
1062
- if( YTPlayer.player.getVolume() == 0 ) {
1063
- jQuery( YTPlayer ).YTPUnmute();
1064
- } else {
1065
- jQuery( YTPlayer ).YTPMute();
1066
- }
1067
- } );
1068
- /* volume bar*/
1069
- var volumeBar = jQuery( "<div/>" ).addClass( "mb_YTPVolumeBar" ).css( {
1070
- display: "inline-block"
1071
- } );
1072
- YTPlayer.volumeBar = volumeBar;
1073
- /* time elapsed */
1074
- var idx = jQuery( "<span/>" ).addClass( "mb_YTPTime" );
1075
- var vURL = data.videoURL ? data.videoURL : "";
1076
- if( vURL.indexOf( "http" ) < 0 ) vURL = jQuery.mbYTPlayer.locationProtocol + "//www.youtube.com/watch?v=" + data.videoURL;
1077
- var movieUrl = jQuery( "<span/>" ).html( jQuery.mbYTPlayer.controls.ytLogo ).addClass( "mb_YTPUrl ytpicon" ).attr( "title", "view on YouTube" ).on( "click", function() {
1078
- window.open( vURL, "viewOnYT" )
1079
- } );
1080
- var onlyVideo = jQuery( "<span/>" ).html( jQuery.mbYTPlayer.controls.onlyYT ).addClass( "mb_OnlyYT ytpicon" ).on( "click", function() {
1081
- jQuery( YTPlayer ).YTPFullscreen( data.realfullscreen );
1082
- } );
1083
- var progressBar = jQuery( "<div/>" ).addClass( "mb_YTPProgress" ).css( "position", "absolute" ).click( function( e ) {
1084
- timeBar.css( {
1085
- width: ( e.clientX - timeBar.offset().left )
1086
- } );
1087
- YTPlayer.timeW = e.clientX - timeBar.offset().left;
1088
- YTPlayer.controlBar.find( ".mb_YTPLoaded" ).css( {
1089
- width: 0
1090
- } );
1091
- var totalTime = Math.floor( YTPlayer.player.getDuration() );
1092
- YTPlayer.goto = ( timeBar.outerWidth() * totalTime ) / progressBar.outerWidth();
1093
- YTPlayer.player.seekTo( parseFloat( YTPlayer.goto ), true );
1094
- YTPlayer.controlBar.find( ".mb_YTPLoaded" ).css( {
1095
- width: 0
1096
- } );
1097
- } );
1098
- var loadedBar = jQuery( "<div/>" ).addClass( "mb_YTPLoaded" ).css( "position", "absolute" );
1099
- var timeBar = jQuery( "<div/>" ).addClass( "mb_YTPseekbar" ).css( "position", "absolute" );
1100
- progressBar.append( loadedBar ).append( timeBar );
1101
- buttonBar.append( playpause ).append( MuteUnmute ).append( volumeBar ).append( idx );
1102
- if( data.showYTLogo ) {
1103
- buttonBar.append( movieUrl );
1104
- }
1105
- if( YTPlayer.isBackground || ( eval( YTPlayer.opt.realfullscreen ) && !YTPlayer.isBackground ) ) buttonBar.append( onlyVideo );
1106
- YTPlayer.controlBar.append( buttonBar ).append( progressBar );
1107
- if( !YTPlayer.isBackground ) {
1108
- YTPlayer.controlBar.addClass( "inlinePlayer" );
1109
- YTPlayer.wrapper.before( YTPlayer.controlBar );
1110
- } else {
1111
- jQuery( "body" ).after( YTPlayer.controlBar );
1112
- }
1113
- volumeBar.simpleSlider( {
1114
- initialval: YTPlayer.opt.vol,
1115
- scale: 100,
1116
- orientation: "h",
1117
- callback: function( el ) {
1118
- if( el.value == 0 ) {
1119
- jQuery( YTPlayer ).YTPMute();
1120
- } else {
1121
- jQuery( YTPlayer ).YTPUnmute();
1122
- }
1123
- YTPlayer.player.setVolume( el.value );
1124
- if( !YTPlayer.isMute ) YTPlayer.opt.vol = el.value;
1125
- }
1126
- } );
1127
- },
1128
- /**
1129
- *
1130
- *
1131
- * */
1132
- checkForState: function( YTPlayer ) {
1133
- var interval = YTPlayer.opt.showControls ? 100 : 400;
1134
- clearInterval( YTPlayer.getState );
1135
- //Checking if player has been removed from scene
1136
- if( !jQuery.contains( document, YTPlayer ) ) {
1137
- jQuery( YTPlayer ).YTPPlayerDestroy();
1138
- clearInterval( YTPlayer.getState );
1139
- clearInterval( YTPlayer.checkForStartAt );
1140
- return;
1141
- }
1142
- jQuery.mbYTPlayer.checkForStart( YTPlayer );
1143
- YTPlayer.getState = setInterval( function() {
1144
- var prog = jQuery( YTPlayer ).YTPManageProgress();
1145
- var $YTPlayer = jQuery( YTPlayer );
1146
- var data = YTPlayer.opt;
1147
- var startAt = YTPlayer.opt.startAt ? YTPlayer.opt.startAt : 1;
1148
- var stopAt = YTPlayer.opt.stopAt > YTPlayer.opt.startAt ? YTPlayer.opt.stopAt : 0;
1149
- stopAt = stopAt < YTPlayer.player.getDuration() ? stopAt : 0;
1150
- if( YTPlayer.player.time != prog.currentTime ) {
1151
- var YTPEvent = jQuery.Event( "YTPTime" );
1152
- YTPEvent.time = YTPlayer.player.time;
1153
- jQuery( YTPlayer ).trigger( YTPEvent );
1154
- }
1155
- YTPlayer.player.time = prog.currentTime;
1156
- if( YTPlayer.player.getVolume() == 0 ) $YTPlayer.addClass( "isMuted" );
1157
- else $YTPlayer.removeClass( "isMuted" );
1158
- if( YTPlayer.opt.showControls )
1159
- if( prog.totalTime ) {
1160
- YTPlayer.controlBar.find( ".mb_YTPTime" ).html( jQuery.mbYTPlayer.formatTime( prog.currentTime ) + " / " + jQuery.mbYTPlayer.formatTime( prog.totalTime ) );
1161
- } else {
1162
- YTPlayer.controlBar.find( ".mb_YTPTime" ).html( "-- : -- / -- : --" );
1163
- }
1164
- if( eval( YTPlayer.opt.stopMovieOnBlur ) )
1165
- if( !document.hasFocus() ) {
1166
- if( YTPlayer.state == 1 ) {
1167
- YTPlayer.hasFocus = false;
1168
- $YTPlayer.YTPPause();
1169
- }
1170
- } else if( document.hasFocus() && !YTPlayer.hasFocus && !( YTPlayer.state == -1 || YTPlayer.state == 0 ) ) {
1171
- YTPlayer.hasFocus = true;
1172
- $YTPlayer.YTPPlay();
1173
- }
1174
- if( YTPlayer.controlBar && YTPlayer.controlBar.outerWidth() <= 400 && !YTPlayer.isCompact ) {
1175
- YTPlayer.controlBar.addClass( "compact" );
1176
- YTPlayer.isCompact = true;
1177
- if( !YTPlayer.isMute && YTPlayer.volumeBar ) YTPlayer.volumeBar.updateSliderVal( YTPlayer.opt.vol );
1178
- } else if( YTPlayer.controlBar && YTPlayer.controlBar.outerWidth() > 400 && YTPlayer.isCompact ) {
1179
- YTPlayer.controlBar.removeClass( "compact" );
1180
- YTPlayer.isCompact = false;
1181
- if( !YTPlayer.isMute && YTPlayer.volumeBar ) YTPlayer.volumeBar.updateSliderVal( YTPlayer.opt.vol );
1182
- }
1183
- if( YTPlayer.player.getPlayerState() == 1 && ( parseFloat( YTPlayer.player.getDuration() - 1.5 ) < YTPlayer.player.getCurrentTime() || ( stopAt > 0 && parseFloat( YTPlayer.player.getCurrentTime() ) > stopAt ) ) ) {
1184
- if( YTPlayer.isEnded ) return;
1185
- YTPlayer.isEnded = true;
1186
- setTimeout( function() {
1187
- YTPlayer.isEnded = false
1188
- }, 1000 );
1189
- if( YTPlayer.isPlayList ) {
1190
- clearInterval( YTPlayer.getState );
1191
- var YTPEnd = jQuery.Event( "YTPEnd" );
1192
- YTPEnd.time = YTPlayer.player.time;
1193
- jQuery( YTPlayer ).trigger( YTPEnd );
1194
- return;
1195
- } else if( !data.loop ) {
1196
- YTPlayer.player.pauseVideo();
1197
- YTPlayer.wrapper.CSSAnimate( {
1198
- opacity: 0
1199
- }, 1000, function() {
1200
- var YTPEnd = jQuery.Event( "YTPEnd" );
1201
- YTPEnd.time = YTPlayer.player.time;
1202
- jQuery( YTPlayer ).trigger( YTPEnd );
1203
- YTPlayer.player.seekTo( startAt, true );
1204
- if( !YTPlayer.isBackground ) {
1205
- YTPlayer.opt.containment.css( {
1206
- background: "rgba(0,0,0,0.5) url(" + YTPlayer.opt.backgroundUrl + ") center center",
1207
- backgroundSize: "cover"
1208
- } );
1209
- }
1210
- } );
1211
- } else {
1212
1213
- startAt = startAt || 1;
1214
1215
- YTPlayer.player.pauseVideo();
1216
- YTPlayer.player.seekTo( startAt, true );
1217
- $YTPlayer.YTPPlay();
1218
1219
- }
1220
- }
1221
- }, interval );
1222
- },
1223
- /**
1224
- *
1225
- * */
1226
- checkForStart: function( YTPlayer ) {
1227
- var $YTPlayer = jQuery( YTPlayer );
1228
- //Checking if player has been removed from scene
1229
- if( !jQuery.contains( document, YTPlayer ) ) {
1230
- jQuery( YTPlayer ).YTPPlayerDestroy();
1231
- return
1232
- }
1233
- if( jQuery.browser.chrome ) YTPlayer.opt.quality = "default";
1234
- YTPlayer.player.pauseVideo();
1235
- jQuery( YTPlayer ).muteYTPVolume();
1236
- jQuery( "#controlBar_" + YTPlayer.id ).remove();
1237
- if( YTPlayer.opt.showControls ) jQuery.mbYTPlayer.buildControls( YTPlayer );
1238
- if( YTPlayer.opt.addRaster ) {
1239
- var classN = YTPlayer.opt.addRaster == "dot" ? "raster-dot" : "raster";
1240
- YTPlayer.overlay.addClass( YTPlayer.isRetina ? classN + " retina" : classN );
1241
- } else {
1242
- YTPlayer.overlay.removeClass( function( index, classNames ) {
1243
- // change the list into an array
1244
- var current_classes = classNames.split( " " ),
1245
- // array of classes which are to be removed
1246
- classes_to_remove = [];
1247
- jQuery.each( current_classes, function( index, class_name ) {
1248
- // if the classname begins with bg add it to the classes_to_remove array
1249
- if( /raster.*/.test( class_name ) ) {
1250
- classes_to_remove.push( class_name );
1251
- }
1252
- } );
1253
- classes_to_remove.push( "retina" );
1254
- // turn the array back into a string
1255
- return classes_to_remove.join( " " );
1256
- } )
1257
- }
1258
- YTPlayer.checkForStartAt = setInterval( function() {
1259
- jQuery( YTPlayer ).YTPMute();
1260
- var startAt = YTPlayer.opt.startAt ? YTPlayer.opt.startAt : 1;
1261
- var canPlayVideo = ( YTPlayer.player.getVideoLoadedFraction() > startAt / YTPlayer.player.getDuration() );
1262
- if( YTPlayer.player.getDuration() > 0 && YTPlayer.player.getCurrentTime() >= startAt && canPlayVideo ) {
1263
- clearInterval( YTPlayer.checkForStartAt );
1264
- YTPlayer.isReady = true;
1265
- if( typeof YTPlayer.opt.onReady == "function" ) YTPlayer.opt.onReady( YTPlayer );
1266
- var YTPready = jQuery.Event( "YTPReady" );
1267
- jQuery( YTPlayer ).trigger( YTPready );
1268
- YTPlayer.player.pauseVideo();
1269
- if( !YTPlayer.opt.mute ) jQuery( YTPlayer ).YTPUnmute();
1270
- YTPlayer.canTrigger = true;
1271
- if( YTPlayer.opt.autoPlay ) {
1272
- $YTPlayer.YTPPlay();
1273
- $YTPlayer.css( "background-image", "none" );
1274
- jQuery( YTPlayer.playerEl ).CSSAnimate( {
1275
- opacity: 1
1276
- }, 1000 );
1277
- YTPlayer.wrapper.CSSAnimate( {
1278
- opacity: YTPlayer.isAlone ? 1 : YTPlayer.opt.opacity
1279
- }, 1000 );
1280
- } else {
1281
- YTPlayer.player.pauseVideo();
1282
- if( !YTPlayer.isPlayer ) {
1283
- jQuery( YTPlayer.playerEl ).CSSAnimate( {
1284
- opacity: 1
1285
- }, 1000 );
1286
- YTPlayer.wrapper.CSSAnimate( {
1287
- opacity: YTPlayer.isAlone ? 1 : YTPlayer.opt.opacity
1288
- }, 1000 );
1289
- }
1290
- }
1291
- if( YTPlayer.isPlayer && !YTPlayer.opt.autoPlay ) {
1292
- YTPlayer.loading.html( "Ready" );
1293
- setTimeout( function() {
1294
- YTPlayer.loading.fadeOut();
1295
1296
1297
- }, 100 )
1298
- }
1299
- if( YTPlayer.controlBar ) YTPlayer.controlBar.slideDown( 1000 );
1300
- } else {
1301
- //YTPlayer.player.playVideo();
1302
- if( startAt >= 0 ) YTPlayer.player.seekTo( startAt, true );
1303
- }
1304
- }, 1000 );
1305
- },
1306
- /**
1307
- *
1308
- * @param s
1309
- * @returns {string}
1310
- */
1311
- formatTime: function( s ) {
1312
- var min = Math.floor( s / 60 );
1313
- var sec = Math.floor( s - ( 60 * min ) );
1314
- return( min <= 9 ? "0" + min : min ) + " : " + ( sec <= 9 ? "0" + sec : sec );
1315
- }
1316
- };
1317
- /**
1318
- *
1319
- * @returns {boolean}
1320
- */
1321
- jQuery.fn.toggleVolume = function() {
1322
- var YTPlayer = this.get( 0 );
1323
- if( !YTPlayer ) return;
1324
- if( YTPlayer.player.isMuted() ) {
1325
- jQuery( YTPlayer ).YTPUnmute();
1326
- return true;
1327
- } else {
1328
- jQuery( YTPlayer ).YTPMute();
1329
- return false;
1330
- }
1331
- };
1332
- /**
1333
- *
1334
- */
1335
- jQuery.fn.optimizeDisplay = function() {
1336
- var YTPlayer = this.get( 0 );
1337
- var data = YTPlayer.opt;
1338
- var playerBox = jQuery( YTPlayer.playerEl );
1339
- var win = {};
1340
- var el = YTPlayer.wrapper;
1341
- win.width = el.outerWidth();
1342
- win.height = el.outerHeight();
1343
- var margin = 24;
1344
- var overprint = 100;
1345
- var vid = {};
1346
- if( data.optimizeDisplay ) {
1347
- vid.width = win.width + ( ( win.width * margin ) / 100 );
1348
- vid.height = data.ratio == "16/9" ? Math.ceil( ( 9 * win.width ) / 16 ) : Math.ceil( ( 3 * win.width ) / 4 );
1349
- vid.marginTop = -( ( vid.height - win.height ) / 2 );
1350
- vid.marginLeft = -( ( win.width * ( margin / 2 ) ) / 100 );
1351
- if( vid.height < win.height ) {
1352
- vid.height = win.height + ( ( win.height * margin ) / 100 );
1353
- vid.width = data.ratio == "16/9" ? Math.floor( ( 16 * win.height ) / 9 ) : Math.floor( ( 4 * win.height ) / 3 );
1354
- vid.marginTop = -( ( win.height * ( margin / 2 ) ) / 100 );
1355
- vid.marginLeft = -( ( vid.width - win.width ) / 2 );
1356
- }
1357
- vid.width += overprint;
1358
- vid.height += overprint;
1359
- vid.marginTop -= overprint / 2;
1360
- vid.marginLeft -= overprint / 2;
1361
- } else {
1362
- vid.width = "100%";
1363
- vid.height = "100%";
1364
- vid.marginTop = 0;
1365
- vid.marginLeft = 0;
1366
- }
1367
- playerBox.css( {
1368
- width: vid.width,
1369
- height: vid.height,
1370
- marginTop: vid.marginTop,
1371
- marginLeft: vid.marginLeft
1372
- } );
1373
- };
1374
- /**
1375
- *
1376
- * @param arr
1377
- * @returns {Array|string|Blob|*}
1378
- *
1379
- */
1380
- jQuery.shuffle = function( arr ) {
1381
- var newArray = arr.slice();
1382
- var len = newArray.length;
1383
- var i = len;
1384
- while( i-- ) {
1385
- var p = parseInt( Math.random() * len );
1386
- var t = newArray[ i ];
1387
- newArray[ i ] = newArray[ p ];
1388
- newArray[ p ] = t;
1389
- }
1390
- return newArray;
1391
- };
1392
1393
- /* Exposed public method */
1394
- jQuery.fn.YTPlayer = jQuery.mbYTPlayer.buildPlayer;
1395
- jQuery.fn.YTPGetPlayer = jQuery.mbYTPlayer.getPlayer;
1396
- jQuery.fn.YTPGetVideoID = jQuery.mbYTPlayer.getVideoID;
1397
- jQuery.fn.YTPChangeMovie = jQuery.mbYTPlayer.changeMovie;
1398
- jQuery.fn.YTPPlayerDestroy = jQuery.mbYTPlayer.playerDestroy;
1399
1400
- jQuery.fn.YTPPlay = jQuery.mbYTPlayer.play;
1401
- jQuery.fn.YTPTogglePlay = jQuery.mbYTPlayer.togglePlay;
1402
- jQuery.fn.YTPStop = jQuery.mbYTPlayer.stop;
1403
- jQuery.fn.YTPPause = jQuery.mbYTPlayer.pause;
1404
- jQuery.fn.YTPSeekTo = jQuery.mbYTPlayer.seekTo;
1405
1406
- jQuery.fn.YTPlaylist = jQuery.mbYTPlayer.playlist;
1407
- jQuery.fn.YTPPlayNext = jQuery.mbYTPlayer.playNext;
1408
- jQuery.fn.YTPPlayPrev = jQuery.mbYTPlayer.playPrev;
1409
1410
- jQuery.fn.YTPMute = jQuery.mbYTPlayer.mute;
1411
- jQuery.fn.YTPUnmute = jQuery.mbYTPlayer.unmute;
1412
- jQuery.fn.YTPToggleVolume = jQuery.mbYTPlayer.toggleVolume;
1413
- jQuery.fn.YTPSetVolume = jQuery.mbYTPlayer.setVolume;
1414
1415
- jQuery.fn.YTPGetVideoData = jQuery.mbYTPlayer.getVideoData;
1416
- jQuery.fn.YTPFullscreen = jQuery.mbYTPlayer.fullscreen;
1417
- jQuery.fn.YTPToggleLoops = jQuery.mbYTPlayer.toggleLoops;
1418
- jQuery.fn.YTPSetVideoQuality = jQuery.mbYTPlayer.setVideoQuality;
1419
- jQuery.fn.YTPManageProgress = jQuery.mbYTPlayer.manageProgress;
1420
1421
- jQuery.fn.YTPApplyFilter = jQuery.mbYTPlayer.applyFilter;
1422
- jQuery.fn.YTPApplyFilters = jQuery.mbYTPlayer.applyFilters;
1423
- jQuery.fn.YTPToggleFilter = jQuery.mbYTPlayer.toggleFilter;
1424
- jQuery.fn.YTPToggleFilters = jQuery.mbYTPlayer.toggleFilters;
1425
- jQuery.fn.YTPRemoveFilter = jQuery.mbYTPlayer.removeFilter;
1426
- jQuery.fn.YTPDisableFilters = jQuery.mbYTPlayer.disableFilters;
1427
- jQuery.fn.YTPEnableFilters = jQuery.mbYTPlayer.enableFilters;
1428
1429
1430
- /**
1431
- *
1432
- * @deprecated
1433
- *
1434
- **/
1435
- jQuery.fn.mb_YTPlayer = jQuery.mbYTPlayer.buildPlayer;
1436
- jQuery.fn.playNext = jQuery.mbYTPlayer.playNext;
1437
- jQuery.fn.playPrev = jQuery.mbYTPlayer.playPrev;
1438
- jQuery.fn.changeMovie = jQuery.mbYTPlayer.changeMovie;
1439
- jQuery.fn.getVideoID = jQuery.mbYTPlayer.getVideoID;
1440
- jQuery.fn.getPlayer = jQuery.mbYTPlayer.getPlayer;
1441
- jQuery.fn.playerDestroy = jQuery.mbYTPlayer.playerDestroy;
1442
- jQuery.fn.fullscreen = jQuery.mbYTPlayer.fullscreen;
1443
- jQuery.fn.buildYTPControls = jQuery.mbYTPlayer.buildControls;
1444
- jQuery.fn.playYTP = jQuery.mbYTPlayer.play;
1445
- jQuery.fn.toggleLoops = jQuery.mbYTPlayer.toggleLoops;
1446
- jQuery.fn.stopYTP = jQuery.mbYTPlayer.stop;
1447
- jQuery.fn.pauseYTP = jQuery.mbYTPlayer.pause;
1448
- jQuery.fn.seekToYTP = jQuery.mbYTPlayer.seekTo;
1449
- jQuery.fn.muteYTPVolume = jQuery.mbYTPlayer.mute;
1450
- jQuery.fn.unmuteYTPVolume = jQuery.mbYTPlayer.unmute;
1451
- jQuery.fn.setYTPVolume = jQuery.mbYTPlayer.setVolume;
1452
- jQuery.fn.setVideoQuality = jQuery.mbYTPlayer.setVideoQuality;
1453
- jQuery.fn.manageYTPProgress = jQuery.mbYTPlayer.manageProgress;
1454
- jQuery.fn.YTPGetDataFromFeed = jQuery.mbYTPlayer.getVideoData;
1455
1456
1457
} )( jQuery, ytp );
21
var ytp = ytp || {};
22
23
function onYouTubeIframeAPIReady() {
24
+ if( ytp.YTAPIReady ) return;
25
+ ytp.YTAPIReady = true;
26
+ jQuery( document ).trigger( "YTAPIReady" );
27
}
28
29
var getYTPVideoID = function( url ) {
30
+ var videoID, playlistID;
31
+ if( url.indexOf( "youtu.be" ) > 0 ) {
32
+ videoID = url.substr( url.lastIndexOf( "/" ) + 1, url.length );
33
+ playlistID = videoID.indexOf( "?list=" ) > 0 ? videoID.substr( videoID.lastIndexOf( "=" ), videoID.length ) : null;
34
+ videoID = playlistID ? videoID.substr( 0, videoID.lastIndexOf( "?" ) ) : videoID;
35
+ } else if( url.indexOf( "http" ) > -1 ) {
36
+ //videoID = url.match( /([\/&]v\/([^&#]*))|([\\?&]v=([^&#]*))/ )[ 1 ];
37
+ videoID = url.match( /[\\?&]v=([^&#]*)/ )[ 1 ];
38
+ playlistID = url.indexOf( "list=" ) > 0 ? url.match( /[\\?&]list=([^&#]*)/ )[ 1 ] : null;
39
+ } else {
40
+ videoID = url.length > 15 ? null : url;
41
+ playlistID = videoID ? null : url;
42
+ }
43
+ return {
44
+ videoID: videoID,
45
+ playlistID: playlistID
46
+ };
47
};
48
49
( function( jQuery, ytp ) {
50
51
+ jQuery.mbYTPlayer = {
52
+ name: "jquery.mb.YTPlayer",
53
+ version: "2.9.5",
54
+ build: "{{ build }}",
55
+ author: "Matteo Bicocchi",
56
+ apiKey: "",
57
+ defaults: {
58
+ containment: "body",
59
+ ratio: "auto", // "auto", "16/9", "4/3"
60
+ videoURL: null,
61
+ playlistURL: null,
62
+ startAt: 0,
63
+ stopAt: 0,
64
+ autoPlay: true,
65
+ vol: 50, // 1 to 100
66
+ addRaster: false,
67
+ opacity: 1,
68
+ quality: "default", //or “small”, “medium”, “large”, “hd720”, “hd1080”, “highres”
69
+ mute: false,
70
+ loop: true,
71
+ showControls: true,
72
+ showAnnotations: false,
73
+ showYTLogo: true,
74
+ stopMovieOnBlur: true,
75
+ realfullscreen: true,
76
+ gaTrack: true,
77
+ optimizeDisplay: true,
78
+ onReady: function( player ) {}
79
+ },
80
+ /* @fontface icons */
81
+ controls: {
82
+ play: "P",
83
+ pause: "p",
84
+ mute: "M",
85
+ unmute: "A",
86
+ onlyYT: "O",
87
+ showSite: "R",
88
+ ytLogo: "Y"
89
+ },
90
+ locationProtocol: "https:",
91
+ /**
92
+ *
93
+ * @param options
94
+ * @returns [players]
95
+ */
96
+ buildPlayer: function( options ) {
97
+ return this.each( function() {
98
+ var YTPlayer = this;
99
+ var $YTPlayer = jQuery( YTPlayer );
100
+ YTPlayer.loop = 0;
101
+ YTPlayer.opt = {};
102
+ YTPlayer.state = {};
103
+ YTPlayer.filtersEnabled = true;
104
+ YTPlayer.filters = {
105
+ grayscale: {
106
+ value: 0,
107
+ unit: "%"
108
+ },
109
+ hue_rotate: {
110
+ value: 0,
111
+ unit: "deg"
112
+ },
113
+ invert: {
114
+ value: 0,
115
+ unit: "%"
116
+ },
117
+ opacity: {
118
+ value: 0,
119
+ unit: "%"
120
+ },
121
+ saturate: {
122
+ value: 0,
123
+ unit: "%"
124
+ },
125
+ sepia: {
126
+ value: 0,
127
+ unit: "%"
128
+ },
129
+ brightness: {
130
+ value: 0,
131
+ unit: "%"
132
+ },
133
+ contrast: {
134
+ value: 0,
135
+ unit: "%"
136
+ },
137
+ blur: {
138
+ value: 0,
139
+ unit: "px"
140
+ }
141
+ };
142
+ $YTPlayer.addClass( "mb_YTPlayer" );
143
+ var property = $YTPlayer.data( "property" ) && typeof $YTPlayer.data( "property" ) == "string" ? eval( '(' + $YTPlayer.data( "property" ) + ')' ) : $YTPlayer.data( "property" );
144
+ if( typeof property != "undefined" && typeof property.vol != "undefined" ) property.vol = property.vol === 0 ? property.vol = 1 : property.vol;
145
+ jQuery.extend( YTPlayer.opt, jQuery.mbYTPlayer.defaults, options, property );
146
+ if( !YTPlayer.hasChanged ) {
147
+ YTPlayer.defaultOpt = {};
148
+ jQuery.extend( YTPlayer.defaultOpt, jQuery.mbYTPlayer.defaults, options, property );
149
+ }
150
+ YTPlayer.isRetina = ( window.retina || window.devicePixelRatio > 1 );
151
+ var isIframe = function() {
152
+ var isIfr = false;
153
+ try {
154
+ if( self.location.href != top.location.href ) isIfr = true;
155
+ } catch( e ) {
156
+ isIfr = true;
157
+ }
158
+ return isIfr;
159
+ };
160
+ YTPlayer.canGoFullScreen = !( jQuery.browser.msie || jQuery.browser.opera || isIframe() );
161
+ if( !YTPlayer.canGoFullScreen ) YTPlayer.opt.realfullscreen = false;
162
+ if( !$YTPlayer.attr( "id" ) ) $YTPlayer.attr( "id", "video_" + new Date().getTime() );
163
+ var playerID = "mbYTP_" + YTPlayer.id;
164
+ YTPlayer.isAlone = false;
165
+ YTPlayer.hasFocus = true;
166
+ var videoID = this.opt.videoURL ? getYTPVideoID( this.opt.videoURL ).videoID : $YTPlayer.attr( "href" ) ? getYTPVideoID( $YTPlayer.attr( "href" ) ).videoID : false;
167
+ var playlistID = this.opt.videoURL ? getYTPVideoID( this.opt.videoURL ).playlistID : $YTPlayer.attr( "href" ) ? getYTPVideoID( $YTPlayer.attr( "href" ) ).playlistID : false;
168
+ YTPlayer.videoID = videoID;
169
+ YTPlayer.playlistID = playlistID;
170
+ YTPlayer.opt.showAnnotations = ( YTPlayer.opt.showAnnotations ) ? '0' : '3';
171
+ var playerVars = {
172
+ 'autoplay': 0,
173
+ 'modestbranding': 1,
174
+ 'controls': 0,
175
+ 'showinfo': 0,
176
+ 'rel': 0,
177
+ 'enablejsapi': 1,
178
+ 'version': 3,
179
+ 'playerapiid': playerID,
180
+ 'origin': '*',
181
+ 'allowfullscreen': true,
182
+ 'wmode': 'transparent',
183
+ 'iv_load_policy': YTPlayer.opt.showAnnotations
184
+ };
185
+ if( document.createElement( 'video' ).canPlayType ) jQuery.extend( playerVars, {
186
+ 'html5': 1
187
+ } );
188
+ if( jQuery.browser.msie && jQuery.browser.version < 9 ) this.opt.opacity = 1;
189
+ var playerBox = jQuery( "<div/>" ).attr( "id", playerID ).addClass( "playerBox" );
190
+ var overlay = jQuery( "<div/>" ).css( {
191
+ position: "absolute",
192
+ top: 0,
193
+ left: 0,
194
+ width: "100%",
195
+ height: "100%"
196
+ } ).addClass( "YTPOverlay" );
197
+ YTPlayer.isSelf = YTPlayer.opt.containment == "self";
198
+ YTPlayer.defaultOpt.containment = YTPlayer.opt.containment = YTPlayer.opt.containment == "self" ? jQuery( this ) : jQuery( YTPlayer.opt.containment );
199
+ YTPlayer.isBackground = YTPlayer.opt.containment.get( 0 ).tagName.toLowerCase() == "body";
200
+ if( YTPlayer.isBackground && ytp.backgroundIsInited ) return;
201
+ var isPlayer = YTPlayer.opt.containment.is( jQuery( this ) );
202
+ YTPlayer.canPlayOnMobile = isPlayer && jQuery( this ).children().length === 0;
203
+ if( !isPlayer ) {
204
+ $YTPlayer.hide();
205
+ } else {
206
+ YTPlayer.isPlayer = true;
207
+ }
208
+ if( jQuery.browser.mobile && !YTPlayer.canPlayOnMobile ) {
209
+ $YTPlayer.remove();
210
+ return;
211
+ }
212
+ var wrapper = jQuery( "<div/>" ).addClass( "mbYTP_wrapper" ).attr( "id", "wrapper_" + playerID );
213
+ wrapper.css( {
214
+ position: "absolute",
215
+ zIndex: 0,
216
+ minWidth: "100%",
217
+ minHeight: "100%",
218
+ left: 0,
219
+ top: 0,
220
+ overflow: "hidden",
221
+ opacity: 0
222
+ } );
223
+ playerBox.css( {
224
+ position: "absolute",
225
+ zIndex: 0,
226
+ width: "100%",
227
+ height: "100%",
228
+ top: 0,
229
+ left: 0,
230
+ overflow: "hidden"
231
+ } );
232
+ wrapper.append( playerBox );
233
+ YTPlayer.opt.containment.children().not( "script, style" ).each( function() {
234
+ if( jQuery( this ).css( "position" ) == "static" ) jQuery( this ).css( "position", "relative" );
235
+ } );
236
+ if( YTPlayer.isBackground ) {
237
+ jQuery( "body" ).css( {
238
+ boxSizing: "border-box"
239
+ } );
240
+ wrapper.css( {
241
+ position: "fixed",
242
+ top: 0,
243
+ left: 0,
244
+ zIndex: 0
245
+ } );
246
+ $YTPlayer.hide();
247
+ } else if( YTPlayer.opt.containment.css( "position" ) == "static" ) YTPlayer.opt.containment.css( {
248
+ position: "relative"
249
+ } );
250
+ YTPlayer.opt.containment.prepend( wrapper );
251
+ YTPlayer.wrapper = wrapper;
252
+ playerBox.css( {
253
+ opacity: 1
254
+ } );
255
+ if( !jQuery.browser.mobile ) {
256
+ playerBox.after( overlay );
257
+ YTPlayer.overlay = overlay;
258
+ }
259
+ if( !YTPlayer.isBackground ) {
260
+ overlay.on( "mouseenter", function() {
261
+ if( YTPlayer.controlBar ) YTPlayer.controlBar.addClass( "visible" );
262
+ } ).on( "mouseleave", function() {
263
+ if( YTPlayer.controlBar ) YTPlayer.controlBar.removeClass( "visible" );
264
+ } )
265
+ }
266
+ if( !ytp.YTAPIReady ) {
267
+ jQuery( "#YTAPI" ).remove();
268
+ var tag = jQuery( "<script></script>" ).attr( {
269
+ "src": jQuery.mbYTPlayer.locationProtocol + "//www.youtube.com/iframe_api?v=" + jQuery.mbYTPlayer.version,
270
+ "id": "YTAPI"
271
+ } );
272
+ jQuery( "head" ).prepend( tag );
273
+ } else {
274
+ setTimeout( function() {
275
+ jQuery( document ).trigger( "YTAPIReady" );
276
+ }, 100 )
277
+ }
278
+ jQuery( document ).on( "YTAPIReady", function() {
279
+ if( ( YTPlayer.isBackground && ytp.backgroundIsInited ) || YTPlayer.isInit ) return;
280
+ if( YTPlayer.isBackground ) {
281
+ ytp.backgroundIsInited = true;
282
+ }
283
+ YTPlayer.opt.autoPlay = typeof YTPlayer.opt.autoPlay == "undefined" ? ( YTPlayer.isBackground ? true : false ) : YTPlayer.opt.autoPlay;
284
+ YTPlayer.opt.vol = YTPlayer.opt.vol ? YTPlayer.opt.vol : 100;
285
+ jQuery.mbYTPlayer.getDataFromAPI( YTPlayer );
286
+ jQuery( YTPlayer ).on( "YTPChanged", function() {
287
+ if( YTPlayer.isInit ) return;
288
+ YTPlayer.isInit = true;
289
+ //if is mobile && isPlayer fallback to the default YT player
290
+ if( jQuery.browser.mobile && YTPlayer.canPlayOnMobile ) {
291
+ // Try to adjust the player dimention
292
+ if( YTPlayer.opt.containment.outerWidth() > jQuery( window ).width() ) {
293
+ YTPlayer.opt.containment.css( {
294
+ maxWidth: "100%"
295
+ } );
296
+ var h = YTPlayer.opt.containment.outerWidth() * .6;
297
+ YTPlayer.opt.containment.css( {
298
+ maxHeight: h
299
+ } );
300
+ }
301
+ new YT.Player( playerID, {
302
+ videoId: YTPlayer.videoID.toString(),
303
+ height: '100%',
304
+ width: '100%',
305
+ events: {
306
+ 'onReady': function( event ) {
307
+ YTPlayer.player = event.target;
308
+ playerBox.css( {
309
+ opacity: 1
310
+ } );
311
+ YTPlayer.wrapper.css( {
312
+ opacity: 1
313
+ } );
314
+ }
315
+ }
316
+ } );
317
+ return;
318
+ }
319
+ new YT.Player( playerID, {
320
+ videoId: YTPlayer.videoID.toString(),
321
+ playerVars: playerVars,
322
+ events: {
323
+ 'onReady': function( event ) {
324
+ YTPlayer.player = event.target;
325
+ if( YTPlayer.isReady ) return;
326
+ YTPlayer.isReady = YTPlayer.isPlayer && !YTPlayer.opt.autoPlay ? false : true;
327
+ YTPlayer.playerEl = YTPlayer.player.getIframe();
328
+ $YTPlayer.optimizeDisplay();
329
+ YTPlayer.videoID = videoID;
330
+ jQuery( window ).on( "resize.YTP", function() {
331
+ $YTPlayer.optimizeDisplay();
332
+ } );
333
+ jQuery.mbYTPlayer.checkForState( YTPlayer );
334
+ // Trigger state events
335
+ var YTPEvent = jQuery.Event( "YTPUnstarted" );
336
+ YTPEvent.time = YTPlayer.player.time;
337
+ if( YTPlayer.canTrigger ) jQuery( YTPlayer ).trigger( YTPEvent );
338
+ },
339
+ /**
340
+ *
341
+ * @param event
342
+ *
343
+ * -1 (unstarted)
344
+ * 0 (ended)
345
+ * 1 (playing)
346
+ * 2 (paused)
347
+ * 3 (buffering)
348
+ * 5 (video cued).
349
+ *
350
+ *
351
+ */
352
+ 'onStateChange': function( event ) {
353
+ if( typeof event.target.getPlayerState != "function" ) return;
354
+ var state = event.target.getPlayerState();
355
+ if( YTPlayer.state == state ) return;
356
+ YTPlayer.state = state;
357
+ var eventType;
358
+ switch( state ) {
359
+ case -1: //------------------------------------------------ unstarted
360
+ eventType = "YTPUnstarted";
361
+ break;
362
+ case 0: //------------------------------------------------ ended
363
+ eventType = "YTPEnd";
364
+ break;
365
+ case 1: //------------------------------------------------ play
366
+ eventType = "YTPStart";
367
+ if( YTPlayer.controlBar ) YTPlayer.controlBar.find( ".mb_YTPPlaypause" ).html( jQuery.mbYTPlayer.controls.pause );
368
+ if( typeof _gaq != "undefined" && eval( YTPlayer.opt.gaTrack ) ) _gaq.push( [ '_trackEvent', 'YTPlayer', 'Play', ( YTPlayer.hasData ? YTPlayer.videoData.title : YTPlayer.videoID.toString() ) ] );
369
+ if( typeof ga != "undefined" && eval( YTPlayer.opt.gaTrack ) ) ga( 'send', 'event', 'YTPlayer', 'play', ( YTPlayer.hasData ? YTPlayer.videoData.title : YTPlayer.videoID.toString() ) );
370
+ break;
371
+ case 2: //------------------------------------------------ pause
372
+ eventType = "YTPPause";
373
+ if( YTPlayer.controlBar ) YTPlayer.controlBar.find( ".mb_YTPPlaypause" ).html( jQuery.mbYTPlayer.controls.play );
374
+ break;
375
+ case 3: //------------------------------------------------ buffer
376
+ YTPlayer.player.setPlaybackQuality( YTPlayer.opt.quality );
377
+ eventType = "YTPBuffering";
378
+ if( YTPlayer.controlBar ) YTPlayer.controlBar.find( ".mb_YTPPlaypause" ).html( jQuery.mbYTPlayer.controls.play );
379
+ break;
380
+ case 5: //------------------------------------------------ cued
381
+ eventType = "YTPCued";
382
+ break;
383
+ default:
384
+ break;
385
+ }
386
+ // Trigger state events
387
+ var YTPEvent = jQuery.Event( eventType );
388
+ YTPEvent.time = YTPlayer.player.time;
389
+ if( YTPlayer.canTrigger ) jQuery( YTPlayer ).trigger( YTPEvent );
390
+ },
391
+ /**
392
+ *
393
+ * @param e
394
+ */
395
+ 'onPlaybackQualityChange': function( e ) {
396
+ var quality = e.target.getPlaybackQuality();
397
+ var YTPQualityChange = jQuery.Event( "YTPQualityChange" );
398
+ YTPQualityChange.quality = quality;
399
+ jQuery( YTPlayer ).trigger( YTPQualityChange );
400
+ },
401
+ /**
402
+ *
403
+ * @param err
404
+ */
405
+ 'onError': function( err ) {
406
+ if( err.data == 150 ) {
407
+ console.log( "Embedding this video is restricted by Youtube." );
408
+ if( YTPlayer.isPlayList ) jQuery( YTPlayer ).playNext();
409
+ }
410
+ if( err.data == 2 && YTPlayer.isPlayList ) jQuery( YTPlayer ).playNext();
411
+ if( typeof YTPlayer.opt.onError == "function" ) YTPlayer.opt.onError( $YTPlayer, err );
412
+ }
413
+ }
414
+ } );
415
+ } );
416
+ } )
417
+ } );
418
+ },
419
+ /**
420
+ *
421
+ * @param YTPlayer
422
+ */
423
+ getDataFromAPI: function( YTPlayer ) {
424
+ YTPlayer.videoData = jQuery.mbStorage.get( "YTPlayer_data_" + YTPlayer.videoID );
425
+ jQuery( YTPlayer ).off( "YTPData.YTPlayer" ).on( "YTPData.YTPlayer", function() {
426
+ if( YTPlayer.hasData ) {
427
428
+ if( YTPlayer.isPlayer && !YTPlayer.opt.autoPlay ) {
429
+ var bgndURL = YTPlayer.videoData.thumb_max || YTPlayer.videoData.thumb_high || YTPlayer.videoData.thumb_medium;
430
+ YTPlayer.opt.containment.css( {
431
+ background: "rgba(0,0,0,0.5) url(" + bgndURL + ") center center",
432
+ backgroundSize: "cover"
433
+ } );
434
+ YTPlayer.opt.backgroundUrl = bgndURL;
435
+ }
436
+ }
437
+ } );
438
439
+ if( YTPlayer.videoData ) {
440
441
+ setTimeout( function() {
442
+ YTPlayer.opt.ratio = YTPlayer.opt.ratio == "auto" ? "16/9" : YTPlayer.opt.ratio;
443
+ YTPlayer.dataReceived = true;
444
+ jQuery( YTPlayer ).trigger( "YTPChanged" );
445
+ var YTPData = jQuery.Event( "YTPData" );
446
+ YTPData.prop = {};
447
+ for( var x in YTPlayer.videoData ) YTPData.prop[ x ] = YTPlayer.videoData[ x ];
448
+ jQuery( YTPlayer ).trigger( YTPData );
449
+ }, 500 );
450
451
+ YTPlayer.hasData = true;
452
+ } else if( jQuery.mbYTPlayer.apiKey ) {
453
+ // Get video info from API3 (needs api key)
454
+ // snippet,player,contentDetails,statistics,status
455
+ jQuery.getJSON( jQuery.mbYTPlayer.locationProtocol + "//www.googleapis.com/youtube/v3/videos?id=" + YTPlayer.videoID + "&key=" + jQuery.mbYTPlayer.apiKey + "&part=snippet", function( data ) {
456
+ YTPlayer.dataReceived = true;
457
+ jQuery( YTPlayer ).trigger( "YTPChanged" );
458
459
+ function parseYTPlayer_data( data ) {
460
+ YTPlayer.videoData = {};
461
+ YTPlayer.videoData.id = YTPlayer.videoID;
462
+ YTPlayer.videoData.channelTitle = data.channelTitle;
463
+ YTPlayer.videoData.title = data.title;
464
+ YTPlayer.videoData.description = data.description.length < 400 ? data.description : data.description.substring( 0, 400 ) + " ...";
465
+ YTPlayer.videoData.aspectratio = YTPlayer.opt.ratio == "auto" ? "16/9" : YTPlayer.opt.ratio;
466
+ YTPlayer.opt.ratio = YTPlayer.videoData.aspectratio;
467
+ YTPlayer.videoData.thumb_max = data.thumbnails.maxres ? data.thumbnails.maxres.url : null;
468
+ YTPlayer.videoData.thumb_high = data.thumbnails.high ? data.thumbnails.high.url : null;
469
+ YTPlayer.videoData.thumb_medium = data.thumbnails.medium ? data.thumbnails.medium.url : null;
470
+ jQuery.mbStorage.set( "YTPlayer_data_" + YTPlayer.videoID, YTPlayer.videoData );
471
+ }
472
+ parseYTPlayer_data( data.items[ 0 ].snippet );
473
+ YTPlayer.hasData = true;
474
+ var YTPData = jQuery.Event( "YTPData" );
475
+ YTPData.prop = {};
476
+ for( var x in YTPlayer.videoData ) YTPData.prop[ x ] = YTPlayer.videoData[ x ];
477
+ jQuery( YTPlayer ).trigger( YTPData );
478
+ } );
479
+ } else {
480
+ setTimeout( function() {
481
+ jQuery( YTPlayer ).trigger( "YTPChanged" );
482
+ }, 50 );
483
+ if( YTPlayer.isPlayer && !YTPlayer.opt.autoPlay ) {
484
+ var bgndURL = jQuery.mbYTPlayer.locationProtocol + "//i.ytimg.com/vi/" + YTPlayer.videoID + "/hqdefault.jpg";
485
+ YTPlayer.opt.containment.css( {
486
+ background: "rgba(0,0,0,0.5) url(" + bgndURL + ") center center",
487
+ backgroundSize: "cover"
488
+ } );
489
+ YTPlayer.opt.backgroundUrl = bgndURL;
490
+ }
491
+ YTPlayer.videoData = null;
492
+ YTPlayer.opt.ratio = YTPlayer.opt.ratio == "auto" ? "16/9" : YTPlayer.opt.ratio;
493
+ }
494
+ if( YTPlayer.isPlayer && !YTPlayer.opt.autoPlay ) {
495
+ YTPlayer.loading = jQuery( "<div/>" ).addClass( "loading" ).html( "Loading" ).hide();
496
+ jQuery( YTPlayer ).append( YTPlayer.loading );
497
+ YTPlayer.loading.fadeIn();
498
+ }
499
+ },
500
+ /**
501
+ *
502
+ */
503
+ removeStoredData: function() {
504
+ jQuery.mbStorage.remove();
505
+ },
506
+ /**
507
+ *
508
+ * @returns {*|YTPlayer.videoData}
509
+ */
510
+ getVideoData: function() {
511
+ var YTPlayer = this.get( 0 );
512
+ return YTPlayer.videoData;
513
+ },
514
+ /**
515
+ *
516
+ * @returns {*|YTPlayer.videoID|boolean}
517
+ */
518
+ getVideoID: function() {
519
+ var YTPlayer = this.get( 0 );
520
+ return YTPlayer.videoID || false;
521
+ },
522
+ /**
523
+ *
524
+ * @param quality
525
+ */
526
+ setVideoQuality: function( quality ) {
527
+ var YTPlayer = this.get( 0 );
528
+ if( !jQuery.browser.chrome ) YTPlayer.player.setPlaybackQuality( quality );
529
+ },
530
+ /**
531
+ * @param videos
532
+ * @param shuffle
533
+ * @param callback
534
+ * @returns {jQuery.mbYTPlayer}
535
+ */
536
+ playlist: function( videos, shuffle, callback ) {
537
+ var $YTPlayer = this;
538
+ var YTPlayer = $YTPlayer.get( 0 );
539
+ YTPlayer.isPlayList = true;
540
+ if( shuffle ) videos = jQuery.shuffle( videos );
541
+ if( !YTPlayer.videoID ) {
542
+ YTPlayer.videos = videos;
543
+ YTPlayer.videoCounter = 0;
544
+ YTPlayer.videoLength = videos.length;
545
+ jQuery( YTPlayer ).data( "property", videos[ 0 ] );
546
+ jQuery( YTPlayer ).mb_YTPlayer();
547
+ }
548
+ if( typeof callback == "function" ) jQuery( YTPlayer ).one( "YTPChanged", function() {
549
+ callback( YTPlayer );
550
+ } );
551
+ jQuery( YTPlayer ).on( "YTPEnd", function() {
552
+ jQuery( YTPlayer ).playNext();
553
+ } );
554
+ return $YTPlayer;
555
+ },
556
+ /**
557
+ *
558
+ * @returns {jQuery.mbYTPlayer}
559
+ */
560
+ playNext: function() {
561
+ var YTPlayer = this.get( 0 );
562
+ YTPlayer.videoCounter++;
563
+ if( YTPlayer.videoCounter >= YTPlayer.videoLength ) YTPlayer.videoCounter = 0;
564
+ jQuery( YTPlayer ).changeMovie( YTPlayer.videos[ YTPlayer.videoCounter ] );
565
+ return this;
566
+ },
567
+ /**
568
+ *
569
+ * @returns {jQuery.mbYTPlayer}
570
+ */
571
+ playPrev: function() {
572
+ var YTPlayer = this.get( 0 );
573
+ YTPlayer.videoCounter--;
574
+ if( YTPlayer.videoCounter < 0 ) YTPlayer.videoCounter = YTPlayer.videoLength - 1;
575
+ jQuery( YTPlayer ).changeMovie( YTPlayer.videos[ YTPlayer.videoCounter ] );
576
+ return this;
577
+ },
578
+ /**
579
+ *
580
+ * @param opt
581
+ */
582
+ changeMovie: function( opt ) {
583
+ var YTPlayer = this.get( 0 );
584
+ YTPlayer.opt.startAt = 0;
585
+ YTPlayer.opt.stopAt = 0;
586
+ YTPlayer.opt.mute = true;
587
+ YTPlayer.hasData = false;
588
+ YTPlayer.hasChanged = true;
589
+ if( opt ) jQuery.extend( YTPlayer.opt, YTPlayer.defaultOpt, opt );
590
+ YTPlayer.videoID = getYTPVideoID( YTPlayer.opt.videoURL ).videoID;
591
+ jQuery( YTPlayer.playerEl ).CSSAnimate( {
592
+ opacity: 0
593
+ }, 200, function() {
594
+ jQuery( YTPlayer ).YTPGetPlayer().cueVideoByUrl( encodeURI( jQuery.mbYTPlayer.locationProtocol + "//www.youtube.com/v/" + YTPlayer.videoID ), 1, YTPlayer.opt.quality );
595
+ jQuery.mbYTPlayer.checkForState( YTPlayer );
596
+ jQuery( YTPlayer ).optimizeDisplay();
597
+ jQuery.mbYTPlayer.getDataFromAPI( YTPlayer );
598
+ return this;
599
+ } );
600
+ },
601
+ /**
602
+ *
603
+ * @returns {player}
604
+ */
605
+ getPlayer: function() {
606
+ return jQuery( this ).get( 0 ).player;
607
+ },
608
+ playerDestroy: function() {
609
+ var YTPlayer = this.get( 0 );
610
+ ytp.YTAPIReady = false;
611
+ ytp.backgroundIsInited = false;
612
+ YTPlayer.isInit = false;
613
+ YTPlayer.videoID = null;
614
+ var playerBox = YTPlayer.wrapper;
615
+ playerBox.remove();
616
+ jQuery( "#controlBar_" + YTPlayer.id ).remove();
617
+ clearInterval( YTPlayer.checkForStartAt );
618
+ clearInterval( YTPlayer.getState );
619
+ return this;
620
+ },
621
+ /**
622
+ *
623
+ * @param real
624
+ * @returns {jQuery.mbYTPlayer}
625
+ */
626
+ fullscreen: function( real ) {
627
+ var YTPlayer = this.get( 0 );
628
+ if( typeof real == "undefined" ) real = YTPlayer.opt.realfullscreen;
629
+ real = eval( real );
630
+ var controls = jQuery( "#controlBar_" + YTPlayer.id );
631
+ var fullScreenBtn = controls.find( ".mb_OnlyYT" );
632
+ var videoWrapper = YTPlayer.isSelf ? YTPlayer.opt.containment : YTPlayer.wrapper;
633
+ //var videoWrapper = YTPlayer.wrapper;
634
+ if( real ) {
635
+ var fullscreenchange = jQuery.browser.mozilla ? "mozfullscreenchange" : jQuery.browser.webkit ? "webkitfullscreenchange" : "fullscreenchange";
636
+ jQuery( document ).off( fullscreenchange ).on( fullscreenchange, function() {
637
+ var isFullScreen = RunPrefixMethod( document, "IsFullScreen" ) || RunPrefixMethod( document, "FullScreen" );
638
+ if( !isFullScreen ) {
639
+ YTPlayer.isAlone = false;
640
+ fullScreenBtn.html( jQuery.mbYTPlayer.controls.onlyYT );
641
+ jQuery( YTPlayer ).YTPSetVideoQuality( YTPlayer.opt.quality );
642
+ videoWrapper.removeClass( "fullscreen" );
643
+ videoWrapper.CSSAnimate( {
644
+ opacity: YTPlayer.opt.opacity
645
+ }, 500 );
646
+ videoWrapper.css( {
647
+ zIndex: 0
648
+ } );
649
+ if( YTPlayer.isBackground ) {
650
+ jQuery( "body" ).after( controls );
651
+ } else {
652
+ YTPlayer.wrapper.before( controls );
653
+ }
654
+ jQuery( window ).resize();
655
+ jQuery( YTPlayer ).trigger( "YTPFullScreenEnd" );
656
+ } else {
657
+ jQuery( YTPlayer ).YTPSetVideoQuality( "default" );
658
+ jQuery( YTPlayer ).trigger( "YTPFullScreenStart" );
659
+ }
660
+ } );
661
+ }
662
+ if( !YTPlayer.isAlone ) {
663
+ function hideMouse() {
664
+ YTPlayer.overlay.css( {
665
+ cursor: "none"
666
+ } );
667
+ }
668
+ jQuery( document ).on( "mousemove.YTPlayer", function( e ) {
669
+ YTPlayer.overlay.css( {
670
+ cursor: "auto"
671
+ } );
672
+ clearTimeout( YTPlayer.hideCursor );
673
+ if( !jQuery( e.target ).parents().is( ".mb_YTPBar" ) ) YTPlayer.hideCursor = setTimeout( hideMouse, 3000 );
674
+ } );
675
+ hideMouse();
676
+ if( real ) {
677
+ videoWrapper.css( {
678
+ opacity: 0
679
+ } );
680
+ videoWrapper.addClass( "fullscreen" );
681
+ launchFullscreen( videoWrapper.get( 0 ) );
682
+ setTimeout( function() {
683
+ videoWrapper.CSSAnimate( {
684
+ opacity: 1
685
+ }, 1000 );
686
+ YTPlayer.wrapper.append( controls );
687
+ jQuery( YTPlayer ).optimizeDisplay();
688
+ YTPlayer.player.seekTo( YTPlayer.player.getCurrentTime() + .1, true );
689
+ }, 500 )
690
+ } else videoWrapper.css( {
691
+ zIndex: 10000
692
+ } ).CSSAnimate( {
693
+ opacity: 1
694
+ }, 1000 );
695
+ fullScreenBtn.html( jQuery.mbYTPlayer.controls.showSite );
696
+ YTPlayer.isAlone = true;
697
+ } else {
698
+ jQuery( document ).off( "mousemove.YTPlayer" );
699
+ YTPlayer.overlay.css( {
700
+ cursor: "auto"
701
+ } );
702
+ if( real ) {
703
+ cancelFullscreen();
704
+ } else {
705
+ videoWrapper.CSSAnimate( {
706
+ opacity: YTPlayer.opt.opacity
707
+ }, 500 );
708
+ videoWrapper.css( {
709
+ zIndex: 0
710
+ } );
711
+ }
712
+ fullScreenBtn.html( jQuery.mbYTPlayer.controls.onlyYT );
713
+ YTPlayer.isAlone = false;
714
+ }
715
716
+ function RunPrefixMethod( obj, method ) {
717
+ var pfx = [ "webkit", "moz", "ms", "o", "" ];
718
+ var p = 0,
719
+ m, t;
720
+ while( p < pfx.length && !obj[ m ] ) {
721
+ m = method;
722
+ if( pfx[ p ] == "" ) {
723
+ m = m.substr( 0, 1 ).toLowerCase() + m.substr( 1 );
724
+ }
725
+ m = pfx[ p ] + m;
726
+ t = typeof obj[ m ];
727
+ if( t != "undefined" ) {
728
+ pfx = [ pfx[ p ] ];
729
+ return( t == "function" ? obj[ m ]() : obj[ m ] );
730
+ }
731
+ p++;
732
+ }
733
+ }
734
735
+ function launchFullscreen( element ) {
736
+ RunPrefixMethod( element, "RequestFullScreen" );
737
+ }
738
739
+ function cancelFullscreen() {
740
+ if( RunPrefixMethod( document, "FullScreen" ) || RunPrefixMethod( document, "IsFullScreen" ) ) {
741
+ RunPrefixMethod( document, "CancelFullScreen" );
742
+ }
743
+ }
744
+ return this;
745
+ },
746
+ /**
747
+ *
748
+ * @returns {jQuery.mbYTPlayer}
749
+ */
750
+ toggleLoops: function() {
751
+ var YTPlayer = this.get( 0 );
752
+ var data = YTPlayer.opt;
753
+ if( data.loop == 1 ) {
754
+ data.loop = 0;
755
+ } else {
756
+ if( data.startAt ) {
757
+ YTPlayer.player.seekTo( data.startAt );
758
+ } else {
759
+ YTPlayer.player.playVideo();
760
+ }
761
+ data.loop = 1;
762
+ }
763
+ return this;
764
+ },
765
+ /**
766
+ *
767
+ * @returns {jQuery.mbYTPlayer}
768
+ */
769
+ play: function() {
770
+ var YTPlayer = this.get( 0 );
771
+ if( !YTPlayer.isReady ) return;
772
+ var controls = jQuery( "#controlBar_" + YTPlayer.id );
773
+ var playBtn = controls.find( ".mb_YTPPlaypause" );
774
+ playBtn.html( jQuery.mbYTPlayer.controls.pause );
775
+ YTPlayer.player.playVideo();
776
+ YTPlayer.wrapper.CSSAnimate( {
777
+ opacity: YTPlayer.isAlone ? 1 : YTPlayer.opt.opacity
778
+ }, 2000 );
779
+ jQuery( YTPlayer.playerEl ).CSSAnimate( {
780
+ opacity: 1
781
+ }, 1000 );
782
+ jQuery( YTPlayer ).css( "background-image", "none" );
783
+ return this;
784
+ },
785
+ /**
786
+ *
787
+ * @param callback
788
+ * @returns {jQuery.mbYTPlayer}
789
+ */
790
+ togglePlay: function( callback ) {
791
+ var YTPlayer = this.get( 0 );
792
+ if( YTPlayer.state == 1 ) this.YTPPause();
793
+ else this.YTPPlay();
794
+ if( typeof callback == "function" ) {
795
+ callback( YTPlayer.state );
796
+ }
797
+ return this;
798
+ },
799
+ /**
800
+ *
801
+ * @returns {jQuery.mbYTPlayer}
802
+ */
803
+ stop: function() {
804
+ var YTPlayer = this.get( 0 );
805
+ var controls = jQuery( "#controlBar_" + YTPlayer.id );
806
+ var playBtn = controls.find( ".mb_YTPPlaypause" );
807
+ playBtn.html( jQuery.mbYTPlayer.controls.play );
808
+ YTPlayer.player.stopVideo();
809
+ return this;
810
+ },
811
+ /**
812
+ *
813
+ * @returns {jQuery.mbYTPlayer}
814
+ */
815
+ pause: function() {
816
+ var YTPlayer = this.get( 0 );
817
+ var controls = jQuery( "#controlBar_" + YTPlayer.id );
818
+ var playBtn = controls.find( ".mb_YTPPlaypause" );
819
+ playBtn.html( jQuery.mbYTPlayer.controls.play );
820
+ YTPlayer.player.pauseVideo();
821
+ return this;
822
+ },
823
+ /**
824
+ *
825
+ * @param val
826
+ * @returns {jQuery.mbYTPlayer}
827
+ */
828
+ seekTo: function( val ) {
829
+ var YTPlayer = this.get( 0 );
830
+ YTPlayer.player.seekTo( val, true );
831
+ return this;
832
+ },
833
+ /**
834
+ *
835
+ * @param val
836
+ * @returns {jQuery.mbYTPlayer}
837
+ */
838
+ setVolume: function( val ) {
839
+ var YTPlayer = this.get( 0 );
840
+ if( !val && !YTPlayer.opt.vol && YTPlayer.player.getVolume() == 0 ) jQuery( YTPlayer ).YTPUnmute();
841
+ else if( ( !val && YTPlayer.player.getVolume() > 0 ) || ( val && YTPlayer.opt.vol == val ) ) {
842
+ if( !YTPlayer.isMute ) jQuery( YTPlayer ).YTPMute();
843
+ else jQuery( YTPlayer ).YTPUnmute();
844
+ } else {
845
+ YTPlayer.opt.vol = val;
846
+ YTPlayer.player.setVolume( YTPlayer.opt.vol );
847
+ if( YTPlayer.volumeBar && YTPlayer.volumeBar.length ) YTPlayer.volumeBar.updateSliderVal( val )
848
+ }
849
+ return this;
850
+ },
851
+ /**
852
+ *
853
+ * @returns {jQuery.mbYTPlayer}
854
+ */
855
+ mute: function() {
856
+ var YTPlayer = this.get( 0 );
857
+ if( YTPlayer.isMute ) return;
858
+ YTPlayer.player.mute();
859
+ YTPlayer.isMute = true;
860
+ YTPlayer.player.setVolume( 0 );
861
+ if( YTPlayer.volumeBar && YTPlayer.volumeBar.length && YTPlayer.volumeBar.width() > 10 ) {
862
+ YTPlayer.volumeBar.updateSliderVal( 0 );
863
+ }
864
+ var controls = jQuery( "#controlBar_" + YTPlayer.id );
865
+ var muteBtn = controls.find( ".mb_YTPMuteUnmute" );
866
+ muteBtn.html( jQuery.mbYTPlayer.controls.unmute );
867
+ jQuery( YTPlayer ).addClass( "isMuted" );
868
+ if( YTPlayer.volumeBar && YTPlayer.volumeBar.length ) YTPlayer.volumeBar.addClass( "muted" );
869
+ var YTPEvent = jQuery.Event( "YTPMuted" );
870
+ YTPEvent.time = YTPlayer.player.time;
871
+ if( YTPlayer.canTrigger ) jQuery( YTPlayer ).trigger( YTPEvent );
872
+ return this;
873
+ },
874
+ /**
875
+ *
876
+ * @returns {jQuery.mbYTPlayer}
877
+ */
878
+ unmute: function() {
879
+ var YTPlayer = this.get( 0 );
880
+ if( !YTPlayer.isMute ) return;
881
+ YTPlayer.player.unMute();
882
+ YTPlayer.isMute = false;
883
+ YTPlayer.player.setVolume( YTPlayer.opt.vol );
884
+ if( YTPlayer.volumeBar && YTPlayer.volumeBar.length ) YTPlayer.volumeBar.updateSliderVal( YTPlayer.opt.vol > 10 ? YTPlayer.opt.vol : 10 );
885
+ var controls = jQuery( "#controlBar_" + YTPlayer.id );
886
+ var muteBtn = controls.find( ".mb_YTPMuteUnmute" );
887
+ muteBtn.html( jQuery.mbYTPlayer.controls.mute );
888
+ jQuery( YTPlayer ).removeClass( "isMuted" );
889
+ if( YTPlayer.volumeBar && YTPlayer.volumeBar.length ) YTPlayer.volumeBar.removeClass( "muted" );
890
+ var YTPEvent = jQuery.Event( "YTPUnmuted" );
891
+ YTPEvent.time = YTPlayer.player.time;
892
+ if( YTPlayer.canTrigger ) jQuery( YTPlayer ).trigger( YTPEvent );
893
+ return this;
894
+ },
895
+ /**
896
+ *
897
+ * @param filter
898
+ * @param value
899
+ * @returns {jQuery.mbYTPlayer}
900
+ */
901
+ applyFilter: function( filter, value ) {
902
+ var YTPlayer = this.get( 0 );
903
+ YTPlayer.filters[ filter ].value = value;
904
+ if( YTPlayer.filtersEnabled ) this.YTPEnableFilters();
905
+ return this;
906
+ },
907
+ /**
908
+ *
909
+ * @param filters
910
+ * @returns {jQuery.mbYTPlayer}
911
+ */
912
+ applyFilters: function( filters ) {
913
+ var YTPlayer = this.get( 0 );
914
+ this.on( "YTPReady", function() {
915
+ for( var key in filters ) {
916
+ YTPlayer.filters[ key ].value = filters[ key ];
917
+ jQuery( YTPlayer ).YTPApplyFilter( key, filters[ key ] );
918
+ }
919
+ jQuery( YTPlayer ).trigger( "YTPFiltersApplied" );
920
+ } );
921
+ return this;
922
+ },
923
+ /**
924
+ *
925
+ * @param filter
926
+ * @param value
927
+ * @returns {*}
928
+ */
929
+ toggleFilter: function( filter, value ) {
930
+ return this.each( function() {
931
+ var YTPlayer = this;
932
+ if( !YTPlayer.filters[ filter ].value ) YTPlayer.filters[ filter ].value = value;
933
+ else YTPlayer.filters[ filter ].value = 0;
934
+ if( YTPlayer.filtersEnabled ) jQuery( this ).YTPEnableFilters();
935
+ } )
936
+ return this;
937
+ },
938
+ /**
939
+ *
940
+ * @param callback
941
+ * @returns {*}
942
+ */
943
+ toggleFilters: function( callback ) {
944
+ return this.each( function() {
945
+ var YTPlayer = this;
946
+ if( YTPlayer.filtersEnabled ) {
947
+ jQuery( YTPlayer ).trigger( "YTPDisableFilters" );
948
+ jQuery( YTPlayer ).YTPDisableFilters();
949
+ } else {
950
+ jQuery( YTPlayer ).YTPEnableFilters();
951
+ jQuery( YTPlayer ).trigger( "YTPEnableFilters" );
952
+ }
953
+ if( typeof callback == "function" ) callback( YTPlayer.filtersEnabled );
954
+ } )
955
+ },
956
+ /**
957
+ *
958
+ * @returns {*}
959
+ */
960
+ disableFilters: function() {
961
+ return this.each( function() {
962
+ var YTPlayer = this;
963
+ var iframe = jQuery( YTPlayer.playerEl );
964
+ iframe.css( "-webkit-filter", "" );
965
+ iframe.css( "filter", "" );
966
+ YTPlayer.filtersEnabled = false;
967
+ } )
968
+ },
969
+ /**
970
+ *
971
+ * @returns {*}
972
+ */
973
+ enableFilters: function() {
974
+ return this.each( function() {
975
+ var YTPlayer = this;
976
+ var iframe = jQuery( YTPlayer.playerEl );
977
+ var filterStyle = "";
978
+ for( var key in YTPlayer.filters ) {
979
+ if( YTPlayer.filters[ key ].value ) filterStyle += key.replace( "_", "-" ) + "(" + YTPlayer.filters[ key ].value + YTPlayer.filters[ key ].unit + ") ";
980
+ }
981
+ iframe.css( "-webkit-filter", filterStyle );
982
+ iframe.css( "filter", filterStyle );
983
+ YTPlayer.filtersEnabled = true;
984
+ } )
985
+ return this;
986
+ },
987
+ /**
988
+ *
989
+ * @param filter
990
+ * @param callback
991
+ * @returns {*}
992
+ */
993
+ removeFilter: function( filter, callback ) {
994
+ return this.each( function() {
995
+ if( typeof filter == "function" ) {
996
+ callback = filter;
997
+ filter = null;
998
+ }
999
+ var YTPlayer = this;
1000
+ if( !filter )
1001
+ for( var key in YTPlayer.filters ) {
1002
+ jQuery( this ).YTPApplyFilter( key, 0 );
1003
+ if( typeof callback == "function" ) callback( key );
1004
+ } else {
1005
+ jQuery( this ).YTPApplyFilter( filter, 0 );
1006
+ if( typeof callback == "function" ) callback( filter );
1007
+ }
1008
+ } );
1009
+ return this;
1010
+ },
1011
+ /**
1012
+ *
1013
+ * @returns {{totalTime: number, currentTime: number}}
1014
+ */
1015
+ manageProgress: function() {
1016
+ var YTPlayer = this.get( 0 );
1017
+ var controls = jQuery( "#controlBar_" + YTPlayer.id );
1018
+ var progressBar = controls.find( ".mb_YTPProgress" );
1019
+ var loadedBar = controls.find( ".mb_YTPLoaded" );
1020
+ var timeBar = controls.find( ".mb_YTPseekbar" );
1021
+ var totW = progressBar.outerWidth();
1022
+ var currentTime = Math.floor( YTPlayer.player.getCurrentTime() );
1023
+ var totalTime = Math.floor( YTPlayer.player.getDuration() );
1024
+ var timeW = ( currentTime * totW ) / totalTime;
1025
+ var startLeft = 0;
1026
+ var loadedW = YTPlayer.player.getVideoLoadedFraction() * 100;
1027
+ loadedBar.css( {
1028
+ left: startLeft,
1029
+ width: loadedW + "%"
1030
+ } );
1031
+ timeBar.css( {
1032
+ left: 0,
1033
+ width: timeW
1034
+ } );
1035
+ return {
1036
+ totalTime: totalTime,
1037
+ currentTime: currentTime
1038
+ };
1039
+ },
1040
+ /**
1041
+ *
1042
+ * @param YTPlayer
1043
+ */
1044
+ buildControls: function( YTPlayer ) {
1045
+ var data = YTPlayer.opt;
1046
+ // @data.printUrl: is deprecated; use data.showYTLogo
1047
+ data.showYTLogo = data.showYTLogo || data.printUrl;
1048
+ if( jQuery( "#controlBar_" + YTPlayer.id ).length ) return;
1049
+ YTPlayer.controlBar = jQuery( "<span/>" ).attr( "id", "controlBar_" + YTPlayer.id ).addClass( "mb_YTPBar" ).css( {
1050
+ whiteSpace: "noWrap",
1051
+ position: YTPlayer.isBackground ? "fixed" : "absolute",
1052
+ zIndex: YTPlayer.isBackground ? 10000 : 1000
1053
+ } ).hide();
1054
+ var buttonBar = jQuery( "<div/>" ).addClass( "buttonBar" );
1055
+ /* play/pause button*/
1056
+ var playpause = jQuery( "<span>" + jQuery.mbYTPlayer.controls.play + "</span>" ).addClass( "mb_YTPPlaypause ytpicon" ).click( function() {
1057
+ if( YTPlayer.player.getPlayerState() == 1 ) jQuery( YTPlayer ).YTPPause();
1058
+ else jQuery( YTPlayer ).YTPPlay();
1059
+ } );
1060
+ /* mute/unmute button*/
1061
+ var MuteUnmute = jQuery( "<span>" + jQuery.mbYTPlayer.controls.mute + "</span>" ).addClass( "mb_YTPMuteUnmute ytpicon" ).click( function() {
1062
+ if( YTPlayer.player.getVolume() == 0 ) {
1063
+ jQuery( YTPlayer ).YTPUnmute();
1064
+ } else {
1065
+ jQuery( YTPlayer ).YTPMute();
1066
+ }
1067
+ } );
1068
+ /* volume bar*/
1069
+ var volumeBar = jQuery( "<div/>" ).addClass( "mb_YTPVolumeBar" ).css( {
1070
+ display: "inline-block"
1071
+ } );
1072
+ YTPlayer.volumeBar = volumeBar;
1073
+ /* time elapsed */
1074
+ var idx = jQuery( "<span/>" ).addClass( "mb_YTPTime" );
1075
+ var vURL = data.videoURL ? data.videoURL : "";
1076
+ if( vURL.indexOf( "http" ) < 0 ) vURL = jQuery.mbYTPlayer.locationProtocol + "//www.youtube.com/watch?v=" + data.videoURL;
1077
+ var movieUrl = jQuery( "<span/>" ).html( jQuery.mbYTPlayer.controls.ytLogo ).addClass( "mb_YTPUrl ytpicon" ).attr( "title", "view on YouTube" ).on( "click", function() {
1078
+ window.open( vURL, "viewOnYT" )
1079
+ } );
1080
+ var onlyVideo = jQuery( "<span/>" ).html( jQuery.mbYTPlayer.controls.onlyYT ).addClass( "mb_OnlyYT ytpicon" ).on( "click", function() {
1081
+ jQuery( YTPlayer ).YTPFullscreen( data.realfullscreen );
1082
+ } );
1083
+ var progressBar = jQuery( "<div/>" ).addClass( "mb_YTPProgress" ).css( "position", "absolute" ).click( function( e ) {
1084
+ timeBar.css( {
1085
+ width: ( e.clientX - timeBar.offset().left )
1086
+ } );
1087
+ YTPlayer.timeW = e.clientX - timeBar.offset().left;
1088
+ YTPlayer.controlBar.find( ".mb_YTPLoaded" ).css( {
1089
+ width: 0
1090
+ } );
1091
+ var totalTime = Math.floor( YTPlayer.player.getDuration() );
1092
+ YTPlayer.goto = ( timeBar.outerWidth() * totalTime ) / progressBar.outerWidth();
1093
+ YTPlayer.player.seekTo( parseFloat( YTPlayer.goto ), true );
1094
+ YTPlayer.controlBar.find( ".mb_YTPLoaded" ).css( {
1095
+ width: 0
1096
+ } );
1097
+ } );
1098
+ var loadedBar = jQuery( "<div/>" ).addClass( "mb_YTPLoaded" ).css( "position", "absolute" );
1099
+ var timeBar = jQuery( "<div/>" ).addClass( "mb_YTPseekbar" ).css( "position", "absolute" );
1100
+ progressBar.append( loadedBar ).append( timeBar );
1101
+ buttonBar.append( playpause ).append( MuteUnmute ).append( volumeBar ).append( idx );
1102
+ if( data.showYTLogo ) {
1103
+ buttonBar.append( movieUrl );
1104
+ }
1105
+ if( YTPlayer.isBackground || ( eval( YTPlayer.opt.realfullscreen ) && !YTPlayer.isBackground ) ) buttonBar.append( onlyVideo );
1106
+ YTPlayer.controlBar.append( buttonBar ).append( progressBar );
1107
+ if( !YTPlayer.isBackground ) {
1108
+ YTPlayer.controlBar.addClass( "inlinePlayer" );
1109
+ YTPlayer.wrapper.before( YTPlayer.controlBar );
1110
+ } else {
1111
+ jQuery( "body" ).after( YTPlayer.controlBar );
1112
+ }
1113
+ volumeBar.simpleSlider( {
1114
+ initialval: YTPlayer.opt.vol,
1115
+ scale: 100,
1116
+ orientation: "h",
1117
+ callback: function( el ) {
1118
+ if( el.value == 0 ) {
1119
+ jQuery( YTPlayer ).YTPMute();
1120
+ } else {
1121
+ jQuery( YTPlayer ).YTPUnmute();
1122
+ }
1123
+ YTPlayer.player.setVolume( el.value );
1124
+ if( !YTPlayer.isMute ) YTPlayer.opt.vol = el.value;
1125
+ }
1126
+ } );
1127
+ },
1128
+ /**
1129
+