PluginProbe
Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades / trunk
Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades vtrunk
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-admin.js

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

379 lines 13.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function (window, $)
2 {
3 window._EPYTA_.widen_ytprefs_wiz = window._EPYTA_.widen_ytprefs_wiz || function ()
4 {
5 setTimeout(function ()
6 {
7 var tbWidth = Math.min(950, $(window).width() - 100);
8 var tbMargin = -1 * tbWidth / 2;
9 $("#TB_window").addClass('epyt-thickbox').animate({marginLeft: tbMargin, width: tbWidth}, 150, 'swing', function ()
10 {
11 $("#TB_window").get(0).style.setProperty('width', tbWidth, 'important');
12 });
13
14 $("#TB_overlay").addClass('epyt-thickbox');
15
16 $("#TB_window iframe").animate({width: tbWidth}, 150);
17 }, 750);
18 };
19
20 window._EPYTA_.onboardNext = function ($step)
21 {
22 $('.ytprefs-ob-step').removeClass('active-step');
23 setTimeout(function ()
24 {
25 window.scrollTo(0, 0);
26 $step.next().addClass('active-step');
27 }, 600);
28 };
29
30 window._EPYTA_.onboardPrev = function ($step)
31 {
32 $('.ytprefs-ob-step').removeClass('active-step');
33 setTimeout(function ()
34 {
35 window.scrollTo(0, 0);
36 $step.prev().addClass('active-step');
37 }, 600);
38 };
39
40 window._EPYTA_.selectText = function (ele)
41 {
42 if (document.selection)
43 {
44 var range = document.body.createTextRange();
45 range.moveToElementText(ele);
46 range.select();
47 }
48 else if (window.getSelection)
49 {
50 var selection = window.getSelection();
51 var range = document.createRange();
52 range.selectNode(ele);
53 selection.removeAllRanges();
54 selection.addRange(range);
55 }
56 };
57
58 window._EPYTA_.gbPreviewSetup = function ()
59 {
60 window._EPADashboard_.loadYTAPI();
61 window._EPADashboard_.apiInit();
62 window._EPADashboard_.log("YT API GB");
63 window._EPADashboard_.pageReady();
64 if (typeof $.fn.fitVidsEP !== 'undefined')
65 {
66 $('body').fitVidsEP();
67 }
68 };
69
70 $.fn.ytprefsFormJSON = function ()
71 {
72 var o = {};
73 var a = this.serializeArray();
74 $.each(a, function ()
75 {
76 if (o[this.name])
77 {
78 if (!o[this.name].push)
79 {
80 o[this.name] = [o[this.name]];
81 }
82 o[this.name].push(this.value || '');
83 }
84 else
85 {
86 o[this.name] = this.value || '';
87 }
88 });
89 return o;
90 };
91
92 $(document).ready(function ()
93 {
94
95 if (window.location.toString().indexOf('https://') === 0)
96 {
97 window._EPYTA_.wpajaxurl = window._EPYTA_.wpajaxurl.replace("http://", "https://");
98 }
99 // Create IE + others compatible event handler
100 var epeventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
101 var epeventer = window[epeventMethod];
102 var epmessageEvent = epeventMethod == "attachEvent" ? "onmessage" : "message";
103
104 // Listen to message from child window
105 epeventer(epmessageEvent, function (e)
106 {
107 var embedcode = "";
108 try
109 {
110 if (e.data.indexOf("youtubeembedplus") === 0 && e.data.indexOf('clientId=') < 0)
111 {
112 embedcode = e.data.split("|")[1];
113 if (embedcode.indexOf("[") !== 0)
114 {
115 embedcode = "<p>" + embedcode + "</p>";
116 }
117
118 if (window.tinyMCE !== null && window.tinyMCE.activeEditor !== null && !window.tinyMCE.activeEditor.isHidden())
119 {
120 if (window._EPYTA_.mceBookmark)
121 {
122 try
123 {
124 window.tinyMCE.activeEditor.selection.moveToBookmark(window._EPYTA_.mceBookmark);
125 }
126 catch (err)
127 {
128 }
129 }
130
131 if (typeof window.tinyMCE.execInstanceCommand !== 'undefined')
132 {
133 window.tinyMCE.execInstanceCommand(
134 window.tinyMCE.activeEditor.id,
135 'mceInsertContent',
136 false,
137 embedcode);
138 }
139 else
140 {
141 send_to_editor(embedcode);
142 }
143
144 setTimeout(function ()
145 {
146 window._EPYTA_.mceBookmark = null;
147 }, 500);
148 }
149 else
150 {
151 embedcode = embedcode.replace('<p>', '\n').replace('</p>', '\n');
152 if (typeof QTags.insertContent === 'function')
153 {
154 QTags.insertContent(embedcode);
155 }
156 else
157 {
158 send_to_editor(embedcode);
159 }
160 }
161 tb_remove();
162 }
163 }
164 catch (err)
165 {
166
167 }
168 }, false);
169
170 $('body').on('click.tbyt', "#ytprefs_wiz_button, .ytprefs_wiz_button_widget_text, .ytprefs-onboarding-launch", function ()
171 {
172 window._EPYTA_.widen_ytprefs_wiz();
173 });
174
175 $(window).on('resize', window._EPYTA_.widen_ytprefs_wiz);
176
177 $(document).on('wp-before-tinymce-init.ytprefs-media_button', function (event, init)
178 {
179 var $media_buttons = $(init.selector).closest('.wp-editor-wrap').find('.wp-media-buttons');
180 if (!$media_buttons.find('.ytprefs_media_link').length)
181 {
182 $media_buttons.append('<a href="' + encodeURI(window._EPYTA_.wizhref) + '" class="thickbox button ytprefs_media_link ytprefs_wiz_button_widget_text" title="Visual YouTube Search Tool and Wizard - For easier embedding"><span></span> YouTube</a>');
183 }
184 });
185
186 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
187 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
188 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
189
190 $('.wrap section a[href^="#jump"]').on('click', function (e)
191 {
192 e.preventDefault();
193 var tab = $(this).attr('href');
194 $('.nav-tab-wrapper a[href="' + tab + '"], .nav-tab-wrapper a[rel="' + tab + '"]').trigger('click');
195 });
196
197
198 $('.ytprefs-ajax-form').on('keypress', function (ev)
199 {
200 if (ev.which == 13)
201 {
202 ev.preventDefault();
203 $(this).find('.ytprefs-ajax-form--submit:not([disabled])').trigger('click');
204 }
205 });
206
207 /////////////////////////////// onboarding
208 if ($('.wrap-ytprefs-onboarding').length)
209 {
210 // global
211 $('.ytprefs-ob-nav-close').on('click', function ()
212 {
213 window.parent.tb_remove();
214 window.top.location.reload();
215 });
216
217 $('.ytprefs-ob-nav-prev').on('click', function ()
218 {
219 window._EPYTA_.onboardPrev($(this).closest('.ytprefs-ob-step'));
220 });
221
222 //////////////////////////////////////////////////////////////////////////////////////////////////////////////// step 1
223
224 $('.ytprefs-ob-filter li').hover(function ()
225 {
226 var sel = '.' + $(this).find('input[type="checkbox"]').data('obfilter') + '-icon';
227 $(sel).addClass('yob-icon-visible');
228 }, function ()
229 {
230 var sel = '.' + $(this).find('input[type="checkbox"]').data('obfilter') + '-icon';
231 $(sel).removeClass('yob-icon-visible');
232 });
233
234
235 $('.ytprefs-ob-filter input[type="checkbox"]').on('change', function ()
236 {
237 var $chk = $(this);
238 var obfilter = $chk.data('obfilter');
239
240 var $allChecked = $('.ytprefs-ob-filter input[type="checkbox"]:checked');
241 if ($allChecked.length && !($allChecked.length === 1 && $allChecked.is('[data-obfilter="yob-monetize"]')))
242 {
243 $('.ytprefs-ob-step1 .ytprefs-ob-nav-next').prop('disabled', false);
244 }
245 else
246 {
247 $('.ytprefs-ob-step1 .ytprefs-ob-nav-next').prop('disabled', true);
248 }
249
250 if (obfilter == 'yob-monetize')
251 {
252 $('.ytprefs-ob-step3 .ytprefs-ob-nav-ultimate, .ytprefs-ob-step3 .ytprefs-ob-nav-penultimate').toggleClass('ytprefs-ob-nav-hide');
253 }
254 else
255 {
256 if ($chk.is(":checked"))
257 {
258 $('.ytprefs-ob-step2 .' + obfilter).addClass(obfilter + '-visible');
259 }
260 else
261 {
262 $('.ytprefs-ob-step2 .' + obfilter).removeClass(obfilter + '-visible');
263 }
264 }
265
266 });
267
268
269 $('.ytprefs-ob-step1 .ytprefs-ob-nav-next').on('click', function ()
270 {
271 window._EPYTA_.onboardNext($(this).closest('.ytprefs-ob-step'));
272 });
273
274
275 //////////////////////////////////////////////////////////////////////////////////////////////////////////////// step 2
276 $('#form-onboarding').on('submit', function (e)
277 {
278 e.preventDefault();
279 (window.tinyMCE || window.tinymce).triggerSave();
280 var $formOnboarding = $(this);
281 $formOnboarding.find('.ytprefs-ob-nav-next').prop('disabled', true);
282
283 var formData = $formOnboarding.ytprefsFormJSON();
284 formData.security = window._EPYTA_.security;
285
286 $.ajax({
287 type: "post",
288 dataType: "json",
289 timeout: 30000,
290 url: window._EPYTA_ ? window._EPYTA_.wpajaxurl : ajaxurl,
291 data: formData,
292 success: function (response)
293 {
294 if (response.type == "success")
295 {
296
297 window._EPYTA_.onboardNext($formOnboarding.closest('.ytprefs-ob-step'));
298 }
299 else
300 {
301 }
302 },
303 error: function (xhr, ajaxOptions, thrownError)
304 {
305 },
306 complete: function ()
307 {
308 $formOnboarding.find('.ytprefs-ob-nav-next').prop('disabled', false);
309 }
310
311 });
312
313 });
314
315 //////////////////////////////////////////////////////////////////////////////////////////////////////////////// step 3
316 $('.ytprefs-ob-step3 .ytprefs-ob-nav-skip').on('click', function ()
317 {
318 window._EPYTA_.onboardNext($(this).closest('.ytprefs-ob-step'));
319 });
320
321 $('#form-onboarding-apikey').on('submit', function (e)
322 {
323 e.preventDefault();
324 var $formOnboarding = $(this);
325 $formOnboarding.find('.ytprefs-ob-nav-next').prop('disabled', true);
326
327 var formData = $formOnboarding.ytprefsFormJSON();
328 formData.security = window._EPYTA_.security;
329
330 $.ajax({
331 type: "post",
332 dataType: "json",
333 timeout: 30000,
334 url: window._EPYTA_ ? window._EPYTA_.wpajaxurl : ajaxurl,
335 data: formData,
336 success: function (response)
337 {
338 if (response.type == "success")
339 {
340 if ($formOnboarding.find('.ytprefs-ob-nav-ultimate').hasClass('ytprefs-ob-nav-hide'))
341 {
342 window._EPYTA_.onboardNext($formOnboarding.closest('.ytprefs-ob-step'));
343 }
344 else
345 {
346 window.parent.tb_remove();
347 window.top.location.reload();
348 }
349
350 }
351 else
352 {
353 }
354 },
355 error: function (xhr, ajaxOptions, thrownError)
356 {
357 },
358 complete: function ()
359 {
360 $formOnboarding.find('.ytprefs-ob-nav-next').prop('disabled', false);
361 }
362
363 });
364
365 });
366
367
368
369 } // end onboarding
370
371 }); // end ready
372 $(window).on('load', function ()
373 {
374 if (_EPYTA_.onboarded != '1')
375 {
376 $('.ytprefs-onboarding-launch').trigger('click');
377 }
378 }); // end onload
379 })(window, jQuery);