PluginProbe
Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades / 11.2
Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades v11.2
trunk 1.0 1.1 10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 11.0 11.0.1 11.1 11.2 11.3 11.3.1 11.4 11.5 11.6 11.7 11.7.1 11.8 All 143 releases
youtube-embed-plus / scripts / ytprefs.js

ytprefs.js in Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades 11.2, at scripts/ytprefs.js

366 lines 15.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function (window, $)
2 {
3 window._EPYT_ = window._EPYT_ || {
4 ajaxurl: "\/wp-admin\/admin-ajax.php",
5 security: "",
6 gallery_scrolloffset: 100,
7 eppathtoscripts: "\/wp-content\/plugins\/youtube-embed-plus\/scripts\/",
8 epresponsiveselector: ["iframe.__youtube_prefs_widget__"],
9 epdovol: true,
10 evselector: 'iframe.__youtube_prefs__[src], iframe[src*="youtube.com/embed/"], iframe[src*="youtube-nocookie.com/embed/"]',
11 usingdefault: true
12 };
13
14 if (!document.querySelectorAll)
15 {
16 document.querySelectorAll = function (selector)
17 {
18 var doc = document, head = doc.documentElement.firstChild, styleTag = doc.createElement('STYLE');
19 head.appendChild(styleTag);
20 doc.__qsaels = [];
21 styleTag.styleSheet.cssText = selector + "{x:expression(document.__qsaels.push(this))}";
22 window.scrollBy(0, 0);
23 return doc.__qsaels;
24 };
25 }
26
27 if (typeof window._EPADashboard_ === 'undefined')
28 {
29 window._EPADashboard_ =
30 {
31 initStarted: false,
32 checkCount: 0,
33 onPlayerReady: function (event)
34 {
35 try
36 {
37 if (typeof _EPYT_.epdovol !== "undefined" && _EPYT_.epdovol)
38 {
39 var vol = parseInt(event.target.getIframe().getAttribute("data-vol"));
40 if (!isNaN(vol))
41 {
42 if (vol === 0)
43 {
44 event.target.mute();
45 }
46 else
47 {
48 if (event.target.isMuted())
49 {
50 event.target.unMute();
51 }
52 event.target.setVolume(vol);
53 }
54 }
55 }
56 }
57 catch (err) {
58 }
59
60 setTimeout(function ()
61 {
62 try
63 {
64 var ytid = _EPADashboard_.justid(event.target.getVideoUrl());
65 _EPADashboard_.jp("ytid=" + ytid);
66
67 }
68 catch (err)
69 {
70 }
71 }, 1700);
72 },
73 onPlayerStateChange: function (event)
74 {
75 var ifm = event.target.getIframe();
76 if (event.data === YT.PlayerState.PLAYING && event.target.ponce !== true && ifm.src.indexOf('autoplay=1') === -1)
77 {
78 event.target.ponce = true;
79
80 try
81 {
82 var ytid = _EPADashboard_.justid(event.target.getVideoUrl());
83 _EPADashboard_.jp("ytid=" + ytid + "&p=1");
84
85 } catch (err)
86 {
87 }
88 }
89
90 var $gallery = $(ifm).closest('.epyt-gallery');
91 if ($gallery.length)
92 {
93 var autonext = $gallery.find('.epyt-pagebutton').first().data('autonext') == '1';
94 if (autonext && event.data === YT.PlayerState.ENDED)
95 {
96 var $currvid = $gallery.find('.epyt-current-video');
97 if (!$currvid.length)
98 {
99 $currvid = $gallery.find('.epyt-gallery-thumb').first();
100 }
101 var $nextvid = $currvid.find(' ~ .epyt-gallery-thumb').first();
102 if ($nextvid.length)
103 {
104 $nextvid.click();
105 }
106 else
107 {
108 $gallery.find('.epyt-pagebutton.epyt-next[data-pagetoken!=""][data-pagetoken]').first().click();
109 }
110 }
111 }
112
113 },
114 justid: function (s)
115 {
116 return new RegExp("[\\?&]v=([^&#]*)").exec(s)[1];
117 },
118 dynsetupevents: function ()
119 {
120 if (typeof this.epytsetupdone === 'undefined')
121 {
122 _EPADashboard_.setupevents(this.id);
123 }
124 },
125 setupevents: function (iframeid)
126 {
127 _EPADashboard_.log('Setting up YT API events: ' + iframeid);
128 if (YT.loaded)
129 {
130 var thisvid = document.getElementById(iframeid);
131 thisvid.epytsetupdone = true;
132 new YT.Player(iframeid, {
133 events: {
134 "onReady": _EPADashboard_.onPlayerReady,
135 "onStateChange": _EPADashboard_.onPlayerStateChange
136 }
137 });
138 }
139 },
140 jp: function (q)
141 {
142 //debug
143 },
144 apiInit: function () {
145 setTimeout(function ()
146 {
147 if (typeof (YT) !== 'undefined')
148 {
149 _EPADashboard_.initStarted = true;
150 var __allytifr = document.querySelectorAll(_EPYT_.evselector);
151 for (var i = 0; i < __allytifr.length; i++)
152 {
153 if (!__allytifr[i].hasAttribute("id"))
154 {
155 __allytifr[i].id = "_dytid_" + Math.round(Math.random() * 8999 + 1000);
156 }
157 _EPADashboard_.setupevents(__allytifr[i].id);
158 }
159
160
161
162
163 }
164 }, 300);
165 },
166 log: function (msg) {
167 try
168 {
169 console.log(msg);
170 }
171 catch (err) {
172 }
173 },
174 doubleCheck: function () {
175 _EPADashboard_.checkInterval = setInterval(function () {
176 _EPADashboard_.checkCount++;
177 if (_EPADashboard_.checkCount >= 5 || _EPADashboard_.initStarted) {
178 clearInterval(_EPADashboard_.checkInterval);
179 }
180 else {
181 _EPADashboard_.apiInit();
182 _EPADashboard_.log('YT API init');
183 }
184
185 }, 1000);
186 },
187 selectText: function (ele) {
188 if (document.selection) {
189 var range = document.body.createTextRange();
190 range.moveToElementText(ele);
191 range.select();
192 } else if (window.getSelection) {
193 var range = document.createRange();
194 range.selectNode(ele);
195 window.getSelection().addRange(range);
196 }
197 }
198
199 };
200 }
201
202 if (typeof window.YT === 'undefined')
203 {
204 var iapi = document.createElement('script');
205 iapi.src = "//www.youtube.com/iframe_api";
206 iapi.type = "text/javascript";
207 document.getElementsByTagName('head')[0].appendChild(iapi);
208 }
209 else if (YT.loaded)
210 {
211 _EPADashboard_.apiInit();
212 _EPADashboard_.log('YT API available');
213 }
214
215 _EPADashboard_.doubleCheck();
216
217 window.onYouTubeIframeAPIReady = typeof window.onYouTubeIframeAPIReady !== 'undefined' ? window.onYouTubeIframeAPIReady : function ()
218 {
219 _EPADashboard_.apiInit();
220 _EPADashboard_.log('YT API ready');
221 };
222
223
224 })(window, jQuery);
225
226
227
228 (function ($) {
229 $(document).ready(function () {
230 $('.epyt-gallery').each(function () {
231 var $container = $(this);
232 var $iframe = $(this).find('iframe').first();
233 var initSrc = $iframe.attr('src');
234 if (!initSrc)
235 {
236 initSrc = $iframe.data('ep-src');
237 }
238 var firstId = $(this).find('.epyt-gallery-list .epyt-gallery-thumb').first().data('videoid');
239 initSrc = initSrc.replace(firstId, 'GALLERYVIDEOID');
240 $iframe.data('ep-gallerysrc', initSrc);
241
242
243 var $listgallery = $container.find('.epyt-gallery-list');
244 var pagenumsalign = function () {
245 try {
246 if ($listgallery.hasClass('epyt-gallery-style-carousel'))
247 {
248 var thumbheight = $($listgallery.find('.epyt-gallery-thumb').get(0)).height();
249 var topval = thumbheight / 2;
250 var $pagenums = $listgallery.find('.epyt-pagination:first-child .epyt-pagenumbers');
251 $pagenums.css('top', (topval + 15) + "px");
252 }
253 }
254 catch (e) {
255 }
256 };
257 setTimeout(function () {
258 pagenumsalign();
259 }, 300);
260 $(window).resize(pagenumsalign);
261
262
263 $container.on('click', '.epyt-gallery-list .epyt-gallery-thumb', function () {
264 $container.find('.epyt-gallery-list .epyt-gallery-thumb').removeClass('epyt-current-video');
265 $(this).addClass('epyt-current-video');
266 var vid = $(this).data('videoid');
267 $container.data('currvid', vid);
268 var vidSrc = $iframe.data('ep-gallerysrc').replace('GALLERYVIDEOID', vid);
269
270 var thumbplay = $container.find('.epyt-pagebutton').first().data('thumbplay');
271 if (thumbplay !== '0' && thumbplay !== 0)
272 {
273 if (vidSrc.indexOf('autoplay') > 0)
274 {
275 vidSrc = vidSrc.replace('autoplay=0', 'autoplay=1');
276 }
277 else
278 {
279 vidSrc += '&autoplay=1';
280 }
281 }
282
283 $('html, body').animate({
284 scrollTop: $iframe.offset().top - parseInt(_EPYT_.gallery_scrolloffset)
285 }, 500, function () {
286 $iframe.attr('src', vidSrc);
287 _EPADashboard_.setupevents($iframe.attr('id'));
288 });
289 });
290
291 $container.on('mouseenter', '.epyt-gallery-list .epyt-gallery-thumb', function () {
292 $(this).addClass('hover');
293 if ($listgallery.hasClass('epyt-gallery-style-carousel') && $container.find('.epyt-pagebutton').first().data('showtitle') == 1)
294 {
295 $container.find('.epyt-pagenumbers').addClass('hide');
296 var ttl = $(this).find('.epyt-gallery-notitle span').text();
297 $container.find('.epyt-gallery-rowtitle').text(ttl).addClass('hover');
298 }
299 });
300
301 $container.on('mouseleave', '.epyt-gallery-list .epyt-gallery-thumb', function () {
302 $(this).removeClass('hover');
303 if ($listgallery.hasClass('epyt-gallery-style-carousel') && $container.find('.epyt-pagebutton').first().data('showtitle') == 1)
304 {
305 $container.find('.epyt-gallery-rowtitle').text('').removeClass('hover');
306 if ($container.find('.epyt-pagebutton[data-pagetoken!=""]').length > 0)
307 {
308 $container.find('.epyt-pagenumbers').removeClass('hide');
309 }
310 }
311 });
312
313 $container.on('click', '.epyt-pagebutton', function () {
314 var pageData = {
315 action: 'my_embedplus_gallery_page',
316 security: _EPYT_.security,
317 options: {
318 playlistId: $(this).data('playlistid'),
319 pageToken: $(this).data('pagetoken'),
320 pageSize: $(this).data('pagesize'),
321 columns: $(this).data('columns'),
322 showTitle: $(this).data('showtitle'),
323 showPaging: $(this).data('showpaging'),
324 autonext: $(this).data('autonext'),
325 style: $(this).data('style'),
326 thumbcrop: $(this).data('thumbcrop')
327 }
328 };
329 if ($(this).data('showdsc'))
330 {
331 pageData.options.showDsc = $(this).data('showdsc');
332 }
333
334 var forward = $(this).hasClass('epyt-next');
335 var currpage = parseInt($container.data('currpage') + "");
336 currpage += forward ? 1 : -1;
337 $container.data('currpage', currpage);
338 $container.find('.epyt-gallery-list').addClass('epyt-loading');
339
340 $.post(_EPYT_.ajaxurl, pageData, function (response) {
341 $container.find('.epyt-gallery-list').html(response);
342 $container.find('.epyt-current').each(function () {
343 $(this).text($container.data('currpage'));
344 });
345 $container.find('.epyt-gallery-thumb[data-videoid="' + $container.data('currvid') + '"]').addClass('epyt-current-video');
346
347 if ($container.find('.epyt-pagebutton').first().data('autonext') == '1')
348 {
349 $container.find('.epyt-gallery-thumb').first().click();
350 }
351
352 })
353 .fail(function () {
354 alert('Sorry, there was an error loading the next page.');
355 })
356 .always(function () {
357 $container.find('.epyt-gallery-list').removeClass('epyt-loading');
358 pagenumsalign();
359 });
360
361 });
362
363 });
364 });
365 })(jQuery);
366