PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.4.7
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.4.7
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / assets / js / settings.js
embedpress / assets / js Last commit date
chunks 7 months ago vendor 8 months ago admin.build.js 7 months ago admin.js 9 months ago analytics-tracker.js 9 months ago analytics.build.js 7 months ago blocks.build.js 6 months ago carousel.js 1 year ago documents-viewer-script.js 3 years ago feature-notices.js 7 months ago front.js 6 months ago frontend.build.js 9 months ago gallery-justify.js 9 months ago gutneberg-script.js 1 year ago index.html 7 years ago initCarousel.js 2 years ago initplyr.js 8 months ago instafeed.js 7 months ago lazy-load.js 6 months ago license.js 7 months ago preview.js 8 months ago settings.js 6 months ago sponsored.js 9 months ago
settings.js
857 lines
1 function embedPressRemoveURLParameter(url, parameter) {
2 //prefer to use l.search if you have a location/link object
3 let urlparts = url.split('?');
4 if (urlparts.length >= 2) {
5
6 let prefix = encodeURIComponent(parameter) + '=';
7 let pars = urlparts[1].split(/[&;]/g);
8
9 //reverse iteration as may be destructive
10 for (var i = pars.length; i-- > 0;) {
11 //idiom for string.startsWith
12 if (pars[i].lastIndexOf(prefix, 0) !== -1) {
13 pars.splice(i, 1);
14 }
15 }
16
17 return urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : '');
18 }
19 return url;
20 }
21 jQuery(document).ready(function ($) {
22 $('.ep-color-picker').wpColorPicker();
23 let formDataChanged = false;
24 let $settingsForm = $('.embedpress-settings-form');
25 let _$Forminputs = $('.embedpress-settings-form :input:not([type=submit], [disabled], button, [readonly])');
26 _$Forminputs.on('change', function (e) {
27 //':input' selector get all form fields even textarea, input, or select
28 formDataChanged = false;
29 let fields_to_avoids = ['ep_settings_nonce', '_wp_http_referer', 'g_loading_animation', 'submit'];
30 let types_to_avoid = ['button'];
31 let yes_no_type_checkbox_radios = ['yt_branding', 'embedpress_document_powered_by', 'embedpress_pro_twitch_autoplay', 'embedpress_pro_twitch_chat'];
32 let radio_names = [];
33 for (var i = 0; i < _$Forminputs.length; i++) {
34 let ip = _$Forminputs[i];
35 let input_type = ip.type;
36 let input_name = ip.name;
37 if (!fields_to_avoids.includes(input_name) && !types_to_avoid.includes(input_type)) {
38 let $e_input = $(ip);
39 if ('radio' === input_type) {
40 if (!radio_names.includes(input_name)) {
41
42 let $checked_radio = $(`input[name="${input_name}"]:checked`);
43 let $input__radio_wrap = $checked_radio.parents('.input__radio_wrap');
44 let checked_radio_value = $checked_radio.val();
45 $input__radio_wrap.data('value', checked_radio_value);
46
47 if ($input__radio_wrap.data('value') != $input__radio_wrap.data('default')) {
48 formDataChanged = true;
49 //break;
50 }
51 radio_names.push(input_name);
52 }
53 } else if ('checkbox' === input_type) {
54 if ($e_input.is(":checked")) {
55 $e_input.data('value', $e_input.val());
56 } else {
57 if (yes_no_type_checkbox_radios.includes(input_name)) {
58 $e_input.data('value', 'no');
59 } else {
60 $e_input.data('value', '');
61 }
62 }
63 if ($e_input.data('value') != $e_input.data('default')) {
64 formDataChanged = true;
65 }
66 } else {
67 if ($e_input.val() != $e_input.data('default')) {
68 formDataChanged = true;
69 //break;
70 }
71 }
72
73 }
74
75 }
76 if (formDataChanged === true) {
77 $settingsForm.find('.embedpress-submit-btn').addClass('ep-settings-form-changed');
78 } else {
79 $settingsForm.find('.embedpress-submit-btn').removeClass('ep-settings-form-changed');
80 }
81 });
82
83 window.onbeforeunload = function () {
84 if (formDataChanged === true) {
85 return "You have unsaved data. Are you sure to leave without saving them?";
86 } else {
87 return;
88 }
89 };
90
91 // Sidebar Menu Toggle
92 $('.sidebar__dropdown .sidebar__link--toggler').on('click', function (e) {
93 e.preventDefault();
94 let $this = $(this);
95 let $sidebarItem = $('.sidebar__item');
96 $sidebarItem.removeClass('show');
97 $this.parent().addClass('show');
98 if ($this.siblings('.dropdown__menu').hasClass('show')) {
99 $this.siblings('.dropdown__menu').removeClass('show');
100 $this.siblings('.dropdown__menu').slideUp();
101 $sidebarItem.removeClass('show');
102 } else {
103 $('.dropdown__menu.show').slideUp().removeClass('show');
104 $this.siblings('.dropdown__menu').addClass('show');
105 // $('.sidebar__menu .dropdown__menu.show').slideUp();
106 $this.siblings('.dropdown__menu').slideDown();
107 }
108 })
109
110 // Sidebar Toggle
111 $('.sidebar__toggler').on('click', function (e) {
112 e.preventDefault();
113 $(this).siblings('.sidebar__menu').slideToggle();
114 })
115
116 // Logo Remove
117 $('.preview__remove').on('click', function (e) {
118 e.preventDefault();
119
120 let $logo_remove_btn = $(this);
121 let $main_adjustment_wrap = $logo_remove_btn.parents('.logo__adjust__wrap');
122 $main_adjustment_wrap.find('.preview__logo').attr('src', '');
123 $main_adjustment_wrap.find(".logo__upload__preview").hide();
124 $main_adjustment_wrap.find(".logo__upload").show();
125 $main_adjustment_wrap.find(".instant__preview__img").attr('src', '');
126 $main_adjustment_wrap.find('.preview__logo__input').val('');
127 $main_adjustment_wrap.find('.preview__logo__input_id').val('');
128 $settingsForm.find('.embedpress-submit-btn').addClass('ep-settings-form-changed');
129 formDataChanged = true;
130 })
131
132 // Logo Controller
133 let rangeSlider = function () {
134 let $slider = $('.logo__adjust');
135 $slider.each(function () {
136 let $es = $(this),
137 previewImg = $es.find('.preview__logo'),
138 opRange = $es.find('.opacity__range'),
139 xRange = $es.find('.x__range'),
140 yRange = $es.find('.y__range'),
141 $range__value = $es.find('.range__value');
142 $range__value.each(function () {
143 $(this).html($(this).prev().attr('value'));
144 });
145
146 opRange.on('input', function () {
147 $(this).next($range__value).val(this.value);
148 previewImg.css('opacity', this.value / 100);
149 });
150 xRange.on('input', function () {
151 $(this).next($range__value).val(this.value);
152 previewImg.css('right', this.value + "%");
153 });
154 yRange.on('input', function () {
155 $(this).next($range__value).val(this.value);
156 previewImg.css('bottom', this.value + "%");
157 });
158 });
159
160
161
162 };
163
164 rangeSlider();
165
166 $('.template__wrapper .input__switch .logo__adjust__toggler').on('click', function (e) {
167 e.preventDefault();
168 $('.logo__adjust__wrap').not($(this).parents('.form__control__wrap').children('.logo__adjust__wrap')).slideUp();
169 $('.template__wrapper .input__switch .logo__adjust__toggler').not($(this)).removeClass('show');
170 $(this).toggleClass('show');
171 $(this).parents('.form__control__wrap').children('.logo__adjust__wrap').slideToggle();
172 })
173
174 $('.form__control__wrap .input__switch input').on('click', function () {
175 $(this).siblings('.logo__adjust__toggler.show').trigger('click');
176 })
177
178 let proFeatureAlert = function () {
179
180 $(document).on('click', '.isPro', function () {
181 $(this).siblings('.pro__alert__wrap').fadeIn();
182 });
183
184 $(document).on('click', '.pro__alert__card .button', function (e) {
185 e.preventDefault();
186 $(this).parents('.pro__alert__wrap').fadeOut();
187 });
188 }
189
190 proFeatureAlert();
191
192 // custom logo upload for youtube
193 $(document).on('click', '.logo__upload', function (e) {
194 e.preventDefault();
195 let $logo_uploader_btn = $(this);
196 let $main_adjustment_wrap = $logo_uploader_btn.parent('.logo__adjust__wrap');
197 let curElement = $main_adjustment_wrap.find('.preview__logo');
198 //let $yt_logo_upload_wrap = $main_adjustment_wrap.find("#yt_logo_upload_wrap");
199 let $yt_logo__upload__preview = $main_adjustment_wrap.find(".logo__upload__preview");
200 let $yt_logo_preview = $main_adjustment_wrap.find(".instant__preview__img");
201 let $yt_logo_url = $main_adjustment_wrap.find('.preview__logo__input');
202 let $yt_logo_id = $main_adjustment_wrap.find('.preview__logo__input_id');
203 let button = $(this),
204 yt_logo_uploader = wp.media({
205 title: 'Custom Logo',
206 library: {
207 uploadedTo: wp.media.view.settings.post.id,
208 type: 'image'
209 },
210 button: {
211 text: 'Use this image'
212 },
213 multiple: false
214 }).on('select', function () {
215 let attachment = yt_logo_uploader.state().get('selection').first().toJSON();
216 if (attachment && attachment.id && attachment.url) {
217 $logo_uploader_btn.hide();
218 $yt_logo_url.val(attachment.url);
219 $yt_logo_id.val(attachment.id);
220 $yt_logo_preview.attr('src', attachment.url);
221 $yt_logo__upload__preview.show();
222 curElement.attr('src', attachment.url);
223 $settingsForm.find('.embedpress-submit-btn').addClass('ep-settings-form-changed');
224 formDataChanged = true;
225 } else {
226 console.log('something went wrong using selected image');
227 }
228 }).open();
229 });
230
231
232 // Elements
233 $(document).on('change', '.element-check', function (e) {
234 let $input = $(this);
235 $.ajax({
236 url: ajaxurl,
237 type: 'post',
238 data: {
239 action: 'embedpress_elements_action',
240 _wpnonce: embedpressSettingsData.nonce,
241 element_type: $input.data('type'),
242 element_name: $input.data('name'),
243 checked: $input.is(":checked"),
244 },
245 success: function (response) {
246 if (response && response.success) {
247 showSuccessMessage();
248 } else {
249 showErrorMessage();
250 }
251 },
252 error: function (error) {
253 showErrorMessage();
254 },
255 });
256 });
257
258 // track changes in settings page
259
260 // Save EmbedPRess Settings data using Ajax
261 $(document).on('submit', 'form.embedpress-settings-form', function (e) {
262 e.preventDefault();
263 let $form = $(this);
264 let $submit_btn = $form.find('.embedpress-submit-btn');
265 let submit_text = $submit_btn.text();
266 const form_data = $form.serializeArray();
267 const $submit_type = $submit_btn.attr('value');
268
269 $submit_btn.text('Saving...'); //@TODO; Translate the text;
270 const ajaxAction = {
271 name: "action",
272 value: 'embedpress_settings_action'
273 };
274 form_data.push(ajaxAction);
275 form_data.push({
276 name: 'submit',
277 value: $submit_type,
278 });
279 $.ajax({
280 url: ajaxurl,
281 type: 'post',
282 dataType: 'json',
283 data: form_data,
284 success: function (response) {
285 $submit_btn.removeClass('ep-settings-form-changed');
286 if (response && response.success) {
287 showSuccessMessage();
288 $submit_btn.text(submit_text);
289 formDataChanged = false;
290 } else {
291 $submit_btn.text(submit_text);
292 showErrorMessage();
293 }
294 },
295 error: function (error) {
296 $submit_btn.removeClass('ep-settings-form-changed');
297 $submit_btn.text(submit_text);
298 showErrorMessage();
299 },
300 });
301 });
302 /**
303 * It shows success message in a toast alert
304 * */
305 function showSuccessMessage() {
306 let $success_message_node = $('.toast__message--success');
307 $success_message_node.addClass('show');
308 setTimeout(function () {
309 $success_message_node.removeClass('show');
310 }, 3000);
311 }
312 /**
313 * It shows error message in a toast alert
314 * */
315 function showErrorMessage() {
316 let $error_message_node = $('.toast__message--error');
317 $error_message_node.addClass('show');
318 setTimeout(function () {
319 $error_message_node.removeClass('show');
320 }, 3000);
321 }
322
323
324 // license
325 $(document).on('click', '.embedpress-license-deactivation-btn', function (e) {
326 let $this = $(this);
327 setTimeout(function () {
328 $this.attr('disabled', 'disabled');
329 }, 2000);
330 $this.html('Deactivating.....');
331 });
332 $(document).on('click', '.embedpress-license-activation-btn', function (e) {
333 let $this = $(this);
334 let val = $('#embedpress-pro-license-key').val();
335 if (val) {
336 setTimeout(function () {
337 $this.attr('disabled', 'disabled');
338 }, 2000);
339 $this.html('Activating.....');
340 }
341 });
342
343
344 // Helpers
345 function copyToClipboard(text) {
346 if (window.clipboardData && window.clipboardData.setData) {
347 // Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
348 return window.clipboardData.setData("Text", text);
349
350 }
351 else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
352 var textarea = document.createElement("textarea");
353 textarea.textContent = text;
354 textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in Microsoft Edge.
355 document.body.appendChild(textarea);
356 textarea.select();
357 try {
358 return document.execCommand("copy"); // Security exception may be thrown by some browsers.
359 }
360 catch (ex) {
361 console.warn("Copy to clipboard failed.", ex);
362 return false;
363 }
364 finally {
365 document.body.removeChild(textarea);
366 }
367 }
368 }
369 function validateUrl(value) {
370 return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value);
371 }
372 // Generate Shortcode
373 let $shortcodePreview = $('#ep-shortcode');
374
375 $(document).on('click', '#ep-shortcode-btn', function (e) {
376 e.preventDefault();
377 let $linkNode = $('#ep-link');
378 let link = $linkNode.val();
379 if (!validateUrl(link)) {
380 show_attention_alert('Please enter a valid URL.');
381 $linkNode.val('');
382 $shortcodePreview.val('');
383 return;
384 }
385 $linkNode.val('');
386 var arr = link.split('.');
387 if (arr[arr.length - 1] === 'pdf') {
388 $shortcodePreview.val('[embedpress_pdf]' + link + '[/embedpress_pdf]');
389 }
390 else {
391 $shortcodePreview.val('[embedpress]' + link + '[/embedpress]');
392 }
393 $shortcodePreview.focus();
394 });
395
396 $(document).on('click', '#ep-shortcode-cp', function (e) {
397 e.preventDefault();
398 let shortcode = $shortcodePreview.val();
399 if (shortcode.length < 1) {
400 show_error_alert('Please enter a valid URL and generate a shortcode first.');
401 return;
402 }
403 copyToClipboard(shortcode);
404 $shortcodePreview.removeClass('active');
405 show_success_alert('Copied to your clipboard successfully.');
406 });
407
408 $shortcodePreview.on('focus', function (e) {
409 $(this).select();
410 });
411
412 function show_attention_alert(message = '') {
413 let $attention_message_node = $('.toast__message--attention');
414 if (message.length > 0) {
415 $attention_message_node.find('p').html(message);
416 }
417 $attention_message_node.addClass('show');
418 setTimeout(function () {
419 $attention_message_node.removeClass('show');
420 history.pushState('', '', embedPressRemoveURLParameter(location.href, 'attention'));
421 }, 3000);
422 }
423
424 function show_error_alert(message = '') {
425 let $error_message_node = $('.toast__message--error');
426 if (message.length > 0) {
427 $error_message_node.find('p').html(message);
428 }
429 $error_message_node.addClass('show');
430 setTimeout(function () {
431 $error_message_node.removeClass('show');
432 history.pushState('', '', embedPressRemoveURLParameter(location.href, 'error'));
433 }, 3000);
434 }
435
436 function show_success_alert(message = '') {
437 let $success_message_node = $('.toast__message--success');
438 if (message.length > 0) {
439 $success_message_node.find('p').html(message);
440 }
441 $success_message_node.addClass('show');
442 setTimeout(function () {
443 $success_message_node.removeClass('show');
444 history.pushState('', '', embedPressRemoveURLParameter(location.href, 'success'));
445 }, 3000);
446 }
447
448 function customConfirm(message, onYes, onNo) {
449 const dialogBox = document.createElement('div');
450 dialogBox.classList.add('custom-dialog');
451
452 const messageElement = document.createElement('p');
453 messageElement.textContent = message;
454
455 const yesButton = document.createElement('button');
456 yesButton.textContent = 'Yes';
457 yesButton.addEventListener('click', () => {
458 document.body.removeChild(dialogBox);
459 onYes();
460 });
461
462 const noButton = document.createElement('button');
463 noButton.textContent = 'No';
464 noButton.addEventListener('click', () => {
465 document.body.removeChild(dialogBox);
466 onNo();
467 });
468
469 dialogBox.appendChild(messageElement);
470 dialogBox.appendChild(yesButton);
471 dialogBox.appendChild(noButton);
472
473 document.body.appendChild(dialogBox);
474 }
475
476 $('.account-delete-button').on('click', function () {
477 customConfirm('Are you sure you want to delete?', onDeleteConfirmed, onDeleteCancelled);
478 $that = $(this);
479 $userId = $that.closest('tr').data('userid');
480 $accountType = $that.closest('tr').data('accounttype');
481
482 $that.css('pointer-events', 'none');
483
484 function onDeleteConfirmed() {
485
486 // Add code here to perform AJAX request or other actions for deletion
487
488 var data = {
489 'action': 'delete_instagram_account',
490 'user_id': $userId,
491 'account_type': $accountType,
492 '_nonce': embedpressSettingsData.nonce
493 };
494
495
496 jQuery.post(ajaxurl, data, function (response) {
497 if (response) {
498 $that.css('pointer-events', 'all');
499 $that.closest('tr').remove();
500 }
501 });
502 }
503
504 function onDeleteCancelled() {
505 $that.css('pointer-events', 'all');
506 // Code when deletion is cancelled
507 }
508
509
510 });
511
512 $('#instagram-form').on('submit', function (e) {
513 e.preventDefault(); // Prevent default form submission
514
515
516 if ($('#instagram-form p').length > 0) {
517 $('#instagram-form p').remove();
518 }
519
520 var access_token = $('#instagram-access-token').val();
521 var account_type = $('#account-option').val();
522
523 $('#instagram-form button').text('Connecting...');
524 $('#instagram-form button').attr('disabled', 'disabled');
525
526 // AJAX request
527 $.ajax({
528 url: ajaxurl, // WordPress AJAX URL
529 type: 'POST',
530 data: {
531 action: 'get_instagram_userdata_ajax', // AJAX action hook
532 access_token: access_token, // Access token data
533 account_type: account_type, // Access token data
534 _nonce: embedpressSettingsData.nonce
535 },
536 success: function (response) {
537 // Handle the response
538 if (response.error) {
539 $('#instagram-form button').text('Connect');
540 $('#instagram-access-token').after(`<p>${response.error}</p>`);
541 $('#instagram-form button').removeAttr('disabled');
542 setTimeout(() => {
543 $('#instagram-form p').remove();
544 }, 10000);
545 } else {
546 $('#instagram-form button').text('Connected');
547 setTimeout(() => {
548 window.location.reload();
549 }, 1000);
550 }
551 },
552 error: function (xhr, status, error) {
553 // Handle errors
554 console.error(error);
555 }
556 });
557 });
558
559
560 $('.instagram-sync-data').on('click', function (e) {
561 e.preventDefault(); // Prevent default form submission
562 $that = $(this);
563
564 var access_token = $that.data('acceess-token');
565 var account_type = $that.data('account-type');
566 var user_id = $that.data('userid');
567
568 // Add or remove the spinner class to start or stop the spinning animation
569 $that.find('i').addClass('sync-spin'); // Start spinning
570 $that.attr('disabled', 'disabled');
571
572
573 // AJAX request
574 $.ajax({
575 url: ajaxurl, // WordPress AJAX URL
576 type: 'POST',
577 data: {
578 action: 'sync_instagram_data_ajax', // AJAX action hook
579 access_token: access_token, // Access token data
580 account_type: account_type, // Account type data
581 user_id: user_id, // User ID data
582 _nonce: embedpressSettingsData.nonce
583 },
584 success: function (response) {
585 // Handle the response
586 if (response.error) {
587 $that.removeAttr('disabled');
588 } else {
589 $that.removeClass('sync-spin'); // Stop spinning
590
591 $that.text('Synced.');
592 setTimeout(() => {
593 window.location.reload();
594 }, 1000);
595 }
596 },
597 error: function (xhr, status, error) {
598 // Handle errors
599 console.error(error);
600 }
601 });
602 });
603
604
605
606 $('.calendly-event-copy-link').click(function () {
607 var eventLink = $(this).data('event-link');
608 var tempInput = $('<input>');
609 $('body').append(tempInput);
610 tempInput.val(eventLink).select();
611 document.execCommand('copy');
612 tempInput.remove();
613
614 var button = $(this);
615 button.find('span').text('Copied!');
616
617 setTimeout(function () {
618 button.find('span').text('Copy link');
619 }, 1500);
620 });
621
622 $('#open-modal-btn').click(function () {
623 $('.modal-overlay').css('display', 'block');
624 });
625
626 $('.modal-overlay .close-btn').click(function () {
627 $('.modal-overlay').css('display', 'none');
628 });
629
630 $(document).on('click', function (e) {
631 if (e.target.classList.contains('modal-overlay')) {
632 $('.modal-overlay').css('display', 'none');
633 }
634 });
635
636 $('.user-profile-link').click(function () {
637 var linkToCopy = $(this).attr('title');
638 copyToClipboard(linkToCopy);
639 alert('Link copied to clipboard: ' + linkToCopy);
640 });
641
642
643 $(document).on('click', '.popup-video-wrap, .close-video_btn', function (e) {
644 e.preventDefault();
645
646 // Remove the popup-video element
647 $('.popup-video').remove();
648 $('.popup-video-wrap').removeClass('popup-active');
649
650 });
651
652 $('.video-play_btn').click(function (e) {
653 $('.popup-video-wrap').append(`
654 <div class="popup-video">
655 <button class="close-video_btn">
656 <a href="#" class="close-btn"></a>
657 </button>
658 <iframe src="https://www.youtube.com/embed/fvYKLkEnJbI?autoplay=1"
659 title="YouTube video player"
660 frameborder="0"
661 allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
662 allowfullscreen>
663 </iframe>
664
665 </div>
666 `);
667 });
668
669 /**
670 * Hub Popup functionality
671 * - Show popup after 3 seconds
672 * - Handle dismiss button click
673 * - Close on Esc key press
674 * - Close when clicking outside popup content
675 */
676 (function() {
677 var $popup = $('.embedpress-pop-up');
678
679 if ($popup.length > 0) {
680 // Show popup after 3 seconds
681 setTimeout(function() {
682 $popup.addClass('show');
683 }, 3000);
684
685 // Function to dismiss popup
686 function dismissPopup() {
687 // Hide popup with fade out effect
688 $popup.removeClass('show');
689
690 // Send AJAX request to dismiss permanently
691 $.ajax({
692 url: ajaxurl,
693 type: 'POST',
694 data: {
695 action: 'embedpress_dismiss_element',
696 element_type: 'hub_popup',
697 nonce: typeof embedpressSettingsData !== 'undefined' ? embedpressSettingsData.ajaxNonce : ''
698 },
699 success: function(response) {
700 console.log('Hub popup dismissed successfully');
701 },
702 error: function(xhr, status, error) {
703 console.error('Error dismissing hub popup:', error);
704 }
705 });
706 }
707
708 // Handle dismiss button click
709 $('.embedpress-cancel-button, .embedpress-pop-up-btn, .pop-up-left-content .bfriday-deal-campaign a').on('click', function(e) {
710 dismissPopup();
711 });
712
713 // Close popup when clicking outside the popup content
714 // $popup.on('click', function(e) {
715 // // Check if click is on the popup overlay (not on the content)
716 // if ($(e.target).hasClass('embedpress-pop-up')) {
717 // dismissPopup();
718 // }
719 // });
720
721 // Close popup when pressing Esc key
722 $(document).on('keydown', function(e) {
723 // Check if popup is visible and Esc key is pressed
724 if (e.key === 'Escape' && $popup.hasClass('show')) {
725 dismissPopup();
726 }
727 });
728 }
729 })();
730
731 /**
732 * Global Brand Upload functionality
733 * - Handle upload button click
734 * - Handle remove button click
735 * - Save brand image via AJAX
736 */
737 $(document).on('click', '#globalBrandUploadBtn', function(e) {
738 e.preventDefault();
739
740 // Check if button is disabled
741 if ($(this).is(':disabled')) {
742 return;
743 }
744
745 var globalBrandUploader = wp.media({
746 title: 'Select Global Brand Logo',
747 library: {
748 type: 'image'
749 },
750 button: {
751 text: 'Use this image'
752 },
753 multiple: false
754 }).on('select', function() {
755 var attachment = globalBrandUploader.state().get('selection').first().toJSON();
756
757 if (attachment && attachment.id && attachment.url) {
758 // Save the brand image via AJAX
759 $.ajax({
760 url: ajaxurl,
761 type: 'POST',
762 data: {
763 action: 'save_global_brand_image',
764 logo_url: attachment.url,
765 logo_id: attachment.id,
766 nonce: typeof embedpressSettingsData !== 'undefined' ? embedpressSettingsData.ajaxNonce : ''
767 },
768 success: function(response) {
769 if (response.success) {
770 // Update all preview areas (for different license states)
771 $('#globalBrandPreview, #globalBrandPreviewExpired').html(
772 '<img src="' + attachment.url + '" alt="Global Brand Logo" class="embedpress-global-brand-preview-img">'
773 );
774
775 // Update hidden inputs
776 $('#globalBrandLogoUrl, #globalBrandLogoUrlExpired, #globalBrandLogoUrlValid').val(attachment.url);
777 $('#globalBrandLogoId, #globalBrandLogoIdExpired, #globalBrandLogoIdValid').val(attachment.id);
778
779 // Update button text to "Replace"
780 $('#globalBrandUploadBtn').text('Replace');
781
782 // Show remove button if not already visible
783 if ($('#globalBrandRemoveBtn').length === 0) {
784 $('#globalBrandUploadBtn').after(
785 '<button type="button" id="globalBrandRemoveBtn" class="embedpress-font-sm embedpress-font-family-dmsans embedpress-upload-btn remove-btn">Remove</button>'
786 );
787 }
788
789 console.log('Global brand image saved successfully');
790 } else {
791 console.error('Failed to save global brand image:', response.data);
792 alert('Failed to save global brand image. Please try again.');
793 }
794 },
795 error: function(xhr, status, error) {
796 console.error('Error saving global brand image:', error);
797 alert('Error saving global brand image. Please try again.');
798 }
799 });
800 }
801 }).open();
802 });
803
804 // Handle global brand remove button
805 $(document).on('click', '#globalBrandRemoveBtn', function(e) {
806 e.preventDefault();
807
808 // Check if button is disabled
809 if ($(this).is(':disabled')) {
810 return;
811 }
812
813 if (!confirm('Are you sure you want to remove the global brand logo?')) {
814 return;
815 }
816
817 // Remove the brand image via AJAX
818 $.ajax({
819 url: ajaxurl,
820 type: 'POST',
821 data: {
822 action: 'save_global_brand_image',
823 logo_url: '',
824 logo_id: '',
825 nonce: typeof embedpressSettingsData !== 'undefined' ? embedpressSettingsData.ajaxNonce : ''
826 },
827 success: function(response) {
828 if (response.success) {
829 // Clear all preview areas
830 $('#globalBrandPreview, #globalBrandPreviewExpired').html('');
831
832 // Clear hidden inputs
833 $('#globalBrandLogoUrl, #globalBrandLogoUrlExpired, #globalBrandLogoUrlValid').val('');
834 $('#globalBrandLogoId, #globalBrandLogoIdExpired, #globalBrandLogoIdValid').val('');
835
836 // Update button text to "Upload"
837 $('#globalBrandUploadBtn').text('Upload');
838
839 // Remove the remove button
840 $('#globalBrandRemoveBtn').remove();
841
842 console.log('Global brand image removed successfully');
843 } else {
844 console.error('Failed to remove global brand image:', response.data);
845 alert('Failed to remove global brand image. Please try again.');
846 }
847 },
848 error: function(xhr, status, error) {
849 console.error('Error removing global brand image:', error);
850 alert('Error removing global brand image. Please try again.');
851 }
852 });
853 });
854
855 });
856
857