PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.3.2
Gallery : FooGallery v3.3.2
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / js / admin-foogallery-edit.js
foogallery / js Last commit date
admin-foogallery-attachment-autosave.js 2 days ago admin-foogallery-divi.js 2 days ago admin-foogallery-edit.js 2 days ago admin-foogallery-editor.js 2 days ago admin-foogallery-elementor.js 2 days ago admin-page-foogallery-extensions-modal.js 2 days ago admin-page-foogallery-extensions.js 2 days ago admin-page-foogallery-settings.js 2 days ago admin-tinymce.js 2 days ago admin-uploader.js 2 days ago foogallery-command-palette.js 2 days ago foogallery.admin.datasources.js 2 days ago foogallery.admin.min.js 2 days ago foogallery.admin.template.js 2 days ago
admin-foogallery-edit.js
1915 lines
1 FooGallery.autoEnabled = false;
2
3 (function (FOOGALLERY, $, undefined) {
4
5 FOOGALLERY.media_uploader = false;
6 FOOGALLERY.previous_post_id = 0;
7 FOOGALLERY.attachments = [];
8 FOOGALLERY.selected_attachment_id = 0;
9 FOOGALLERY.selected_gallery_template = '';
10 FOOGALLERY.dropzoneUploader = null;
11 FOOGALLERY.dropzoneInitialized = false;
12 FOOGALLERY.suppressPreviewRefresh = false;
13 FOOGALLERY.lockedSettingFieldSelector = '.foogallery_template_field[data-foogallery-locked]';
14
15 // Used for selecting files from the media modal.
16 FOOGALLERY.current_media_selector_modals = false;
17 FOOGALLERY.current_media_selector_input = false;
18
19 FOOGALLERY.enforceLockedSettingFields = function($container) {
20 $container.find(FOOGALLERY.lockedSettingFieldSelector)
21 .find(':input, range-input')
22 .attr('disabled', true);
23 };
24
25 FOOGALLERY.enableUnlockedSettingFields = function($container) {
26 $container.find(':input').not(function() {
27 return $(this).closest(FOOGALLERY.lockedSettingFieldSelector).length > 0;
28 }).prop('disabled', false);
29
30 $container.find('range-input').each(function() {
31 if ($(this).closest(FOOGALLERY.lockedSettingFieldSelector).length === 0) {
32 this.removeAttribute('disabled');
33 }
34 });
35
36 $container.find('.foogallery-setting-control-mobile').each(function() {
37 var $control = $(this),
38 $field = $control.closest('.foogallery_template_field'),
39 locked = $field.attr('data-foogallery-locked') !== undefined,
40 hidden = $field.hasClass('foogallery_template_field_template_hidden');
41
42 $control.prop('disabled', locked || hidden);
43 });
44
45 FOOGALLERY.enforceLockedSettingFields($container);
46 };
47
48 // Viewport controller for responsive preview
49 FOOGALLERY.previewActionsController = {
50 currentViewport: 'desktop',
51 viewports: ['desktop', 'tablet', 'mobile'],
52 mobilePromoId: 0,
53
54 init: function() {
55 this.bindEvents();
56 this.setViewport('desktop'); // Default to desktop
57 },
58
59 bindEvents: function() {
60 var self = this;
61
62 $('#foogallery_settings').on('click', '.foogallery-setting-mobile-locked', function(e) {
63 e.preventDefault();
64 var $button = $(this),
65 $field = $button.closest('.foogallery_template_field'),
66 label = $button.attr('data-foogallery-mobile-promo-label') || $.trim($field.find('.foogallery-setting-label').first().text()),
67 promo = FOOGALLERY.il8n && FOOGALLERY.il8n.mobileSettingsPromo;
68
69 if (!promo) return;
70 self.setResponsiveSettingViewport($field, 'mobile');
71 FOOGALLERY.handleSettingsShowRules();
72 $('.foogallery-mobile-settings-promo').each(function() {
73 $(this).find('.notice-dismiss').trigger('click');
74 });
75 self.mobilePromoId++;
76 var title = (promo.title || '').replace('{field}', label),
77 promoId = 'foogallery-mobile-settings-promo-' + self.mobilePromoId,
78 titleId = promoId + '-title',
79 $trayRow = $('<tr class="foogallery-mobile-settings-promo-row"><th aria-hidden="true"></th><td></td></tr>'),
80 $tray = $('<div class="foogallery-mobile-settings-promo" role="dialog" aria-modal="false" tabindex="-1">')
81 .attr({id: promoId, 'aria-labelledby': titleId})
82 .append($('<button type="button" class="notice-dismiss" aria-label="">').attr('aria-label', promo.close || 'Close'))
83 .append($('<strong>').attr('id', titleId).text(title))
84 .append($('<p>').text(promo.body || ''))
85 .append($('<a class="button button-primary" target="_blank" rel="noopener">').attr('href', promo.trialUrl || '#').text(promo.trial || ''))
86 .append($('<a class="button" target="_blank" rel="noopener">').attr('href', promo.upgradeUrl || '#').text(promo.upgrade || ''))
87 .append($('<a class="button" target="_blank" rel="noopener">').attr('href', promo.compareUrl || '#').text(promo.compare || ''));
88 $trayRow.find('td').append($tray);
89 $field.after($trayRow);
90 $button.attr({'aria-expanded': 'true', 'aria-controls': promoId});
91 var closePromo = function() { $trayRow.remove(); $button.removeAttr('aria-controls').attr('aria-expanded', 'false').trigger('focus'); $(document).off('mousedown.foogalleryMobilePromo'); };
92 $tray.find('.notice-dismiss').on('click', closePromo);
93 $tray.on('keydown', function(event) { if ('Escape' === event.key) { $tray.find('.notice-dismiss').trigger('click'); } });
94 $(document).on('mousedown.foogalleryMobilePromo', function(event) { if (!$(event.target).closest('.foogallery-mobile-settings-promo, .foogallery-setting-mobile-locked').length) { closePromo(); } });
95 $tray.trigger('focus');
96 });
97
98 // Refresh buttons click
99 $('.foogallery-preview-actions .foogallery-preview-refresh-btn').on('click', function(e) {
100 e.preventDefault();
101 e.stopPropagation(); // Prevent event bubbling
102 FOOGALLERY.reloadGalleryPreview();
103 });
104
105 // Viewport button clicks
106 $('.foogallery-preview-actions .foogallery-viewport-btn').on('click', function(e) {
107 e.preventDefault();
108 e.stopPropagation(); // Prevent event bubbling
109 var viewport = $(this).data('viewport');
110 self.setViewport(viewport);
111 });
112
113 $('#foogallery_settings').on('click', '.foogallery-setting-viewport-btn', function(e) {
114 e.preventDefault();
115 e.stopPropagation();
116 self.setResponsiveSettingViewport($(this).closest('.foogallery_template_field'), $(this).data('viewport'));
117 FOOGALLERY.handleSettingsShowRules();
118 });
119
120 var $currentButton = $('.foogallery-items-view-switch-container a.current'),
121 currentValue = $currentButton.data('value');
122
123 if ( currentValue === 'preview' ) {
124 //show the viewport buttons
125 $('.foogallery-preview-actions').show();
126 } else {
127 $('.foogallery-preview-actions').hide();
128 }
129 },
130
131 setViewport: function(viewport) {
132 if ($.inArray(viewport, this.viewports) === -1) return;
133
134 var previousViewport = this.currentViewport,
135 viewportChanged = previousViewport !== viewport;
136
137 this.currentViewport = viewport;
138
139 // The core client already merges data-foogallery-mobile when this is true.
140 // Keep the selected preview viewport authoritative inside the editor.
141 if (typeof FooGallery !== 'undefined') FooGallery.isMobile = viewport === 'mobile';
142
143 // Update button states
144 $('.foogallery-viewport-btn')
145 .removeClass('active')
146 .attr('aria-pressed', 'false');
147 $('.foogallery-viewport-btn[data-viewport="' + viewport + '"]')
148 .addClass('active')
149 .attr('aria-pressed', 'true');
150
151 // Update preview wrapper classes
152 var $wrapper = $('.foogallery-preview-wrapper');
153
154 // If wrapper doesn't exist, create it by wrapping the preview container
155 if ($wrapper.length === 0) {
156 var $preview = $('.foogallery_preview_container');
157 if ($preview.length > 0) {
158 $preview.wrap('<div class="foogallery-preview-wrapper viewport-desktop"></div>');
159 $wrapper = $('.foogallery-preview-wrapper');
160 }
161 }
162
163 if ($wrapper.length > 0) {
164 $wrapper.removeClass('viewport-desktop viewport-tablet viewport-mobile')
165 .addClass('viewport-' + viewport);
166 }
167
168 this.updateResponsiveSettings();
169 FOOGALLERY.handleSettingsShowRules();
170
171 // Mobile options are read while the client template is constructed,
172 // so an existing preview must be reinitialized after a viewport change.
173 if (viewportChanged && typeof FooGallery !== 'undefined') {
174 var $gallery = $('.foogallery_preview_container .foogallery'),
175 instance = $gallery.data('__FooGallery__');
176
177 if (instance instanceof FooGallery.Template) {
178 FOOGALLERY.updateGalleryPreview(true, true);
179 }
180 }
181
182 if (viewportChanged) {
183 $('body').trigger('foogallery-gallery-preview-viewport-changed', [viewport, previousViewport]);
184 }
185 },
186
187 updateResponsiveSettings: function() {
188 var self = this,
189 viewport = this.currentViewport === 'mobile' ? 'mobile' : 'desktop';
190
191 $('.foogallery_template_field[data-foogallery-mobile-friendly]').each(function() {
192 self.setResponsiveSettingViewport($(this), viewport);
193 });
194 $('.foogallery_template_field[data-foogallery-mobile-locked]').each(function() {
195 self.setResponsiveSettingViewport($(this), viewport);
196 });
197 },
198
199 setResponsiveSettingViewport: function($field, viewport) {
200 if (!$field.length || $.inArray(viewport, ['desktop', 'mobile']) === -1) return;
201
202 $field.attr('data-foogallery-setting-viewport', viewport);
203
204 if ($field.is('[data-foogallery-mobile-locked]')) {
205 var isMobile = 'mobile' === viewport,
206 $lockedLabel = $field.find('.foogallery-setting-label').first(),
207 desktopFor = $lockedLabel.attr('data-desktop-for');
208
209 $field.find('.foogallery-setting-mobile-locked')
210 .toggleClass('active', isMobile)
211 .attr('aria-pressed', isMobile ? 'true' : 'false');
212 $field.find('.foogallery-setting-mobile-locked-desktop')
213 .toggleClass('active', !isMobile)
214 .attr('aria-pressed', isMobile ? 'false' : 'true');
215
216 if (desktopFor) {
217 $lockedLabel.attr('for', desktopFor);
218 }
219 return;
220 }
221
222 $field.find('.foogallery-setting-control').each(function() {
223 var $control = $(this),
224 isActive = $control.data('viewport') === viewport;
225
226 $control.prop('hidden', !isActive);
227 });
228
229 $field.find('.foogallery-setting-viewport-btn')
230 .removeClass('active')
231 .attr('aria-pressed', 'false');
232 $field.find('.foogallery-setting-viewport-btn[data-viewport="' + viewport + '"]')
233 .addClass('active')
234 .attr('aria-pressed', 'true');
235
236 var $label = $field.find('.foogallery-setting-label').first(),
237 forAttribute = $label.attr('data-' + viewport + '-for');
238
239 if (forAttribute) {
240 $label.attr('for', forAttribute);
241 } else {
242 $label.removeAttr('for');
243 }
244 }
245 };
246
247 FOOGALLERY.calculateAttachmentIds = function() {
248 var sorted = [];
249 $('.foogallery-attachments-list li:not(.add-attachment)').each(function() {
250 if ( $(this).data('attachment-id') ) {
251 sorted.push($(this).data('attachment-id'));
252 }
253 });
254
255 $('#foogallery_attachments').val( sorted.join(',') );
256
257 // Force the datasource to be 'media_library' so that we do not get into a strange state with other datasources that were previously selected.
258 $('#foogallery_datasource').val('media_library');
259
260 $('.foogallery_preview_container').addClass('foogallery-preview-force-refresh');
261 };
262
263 FOOGALLERY.calculateHiddenAreas = function() {
264 FOOGALLERY.showHiddenAreas( FOOGALLERY.attachments.length === 0 );
265 };
266
267 FOOGALLERY.showHiddenAreas = function( show ) {
268 if ( show ) {
269 $('.foogallery-items-add').removeClass('foogallery-hidden');
270 $('.foogallery-attachments-list-container').addClass('foogallery-hidden');
271 $('.foogallery-items-empty').removeClass('foogallery-hidden');
272 } else {
273 $('.foogallery-items-add').addClass('foogallery-hidden');
274 $('.foogallery-attachments-list-container').removeClass('foogallery-hidden');
275 $('.foogallery-items-empty').addClass('foogallery-hidden');
276 }
277 };
278
279 FOOGALLERY.initAttachments = function() {
280 var attachments = $('#foogallery_attachments').val();
281 if (attachments) {
282 FOOGALLERY.attachments = $.map(attachments.split(','), function (value) {
283 return parseInt(value, 10);
284 });
285 }
286 };
287
288 FOOGALLERY.persistSettingValue = function($source, $target, settingType) {
289 if (!$source.length || !$target.length) return false;
290
291 switch (settingType) {
292 case 'radio':
293 case 'icon':
294 case 'htmlicon':
295 var selectedRadio = $source.find('input:checked').val();
296 if (selectedRadio !== undefined) {
297 var $newRadio = $target.find('input[value="' + selectedRadio + '"]'),
298 currentRadio = $target.find('input:checked').val();
299 if ($newRadio.length && currentRadio !== selectedRadio) {
300 $newRadio.prop('checked', true).trigger('change');
301 return true;
302 }
303 }
304 break;
305 case 'checkbox':
306 var isChecked = $source.find('input[type="checkbox"]').is(':checked'),
307 $newCheckbox = $target.find('input[type="checkbox"]');
308 if ($newCheckbox.length && $newCheckbox.is(':checked') !== isChecked) {
309 $newCheckbox.prop('checked', isChecked).trigger('change');
310 return true;
311 }
312 break;
313 case 'select':
314 var selectVal = $source.find('select').val(),
315 $newSelect = $target.find('select');
316 if ($newSelect.length && $newSelect.val() !== selectVal) {
317 $newSelect.val(selectVal).trigger('change');
318 return true;
319 }
320 break;
321 case 'text':
322 case 'textarea':
323 case 'number':
324 case 'slider':
325 var $input = $source.find(':input, range-input').first(),
326 value = $input.val(),
327 $newInput = $target.find(':input, range-input').first(),
328 currentValue = $newInput.val();
329
330 if ($newInput.length && currentValue !== value) {
331 $newInput.val(value).trigger('change');
332 return true;
333 }
334 break;
335 default:
336 console.log('Field type ' + settingType + ' is not supported for persisted settings.');
337 break;
338 }
339
340 return false;
341 };
342
343 FOOGALLERY.persistResponsiveSettingState = function($source, $target) {
344 if (!$source.is('[data-foogallery-mobile-friendly]') || !$target.is('[data-foogallery-mobile-friendly]')) {
345 return false;
346 }
347
348 var locked = $target.attr('data-foogallery-locked') !== undefined,
349 hidden = $target.hasClass('foogallery_template_field_template_hidden'),
350 fallbackMode = $target.attr('data-foogallery-mobile-fallback-mode') || 'inherit',
351 settingType = $target.data('foogallery-setting-type'),
352 $desktopControl = $target.find('.foogallery-setting-control-desktop'),
353 $mobileControl = $target.find('.foogallery-setting-control-mobile'),
354 fallbackValue,
355 mobileValue;
356
357 $mobileControl.prop('disabled', locked || hidden);
358 if (locked || hidden) return true;
359
360 if (fallbackMode === 'inherit') {
361 fallbackValue = FOOGALLERY.getSettingControlValue($desktopControl, settingType);
362 $target.attr('data-foogallery-mobile-fallback-value', JSON.stringify(fallbackValue));
363 } else {
364 try {
365 fallbackValue = JSON.parse($target.attr('data-foogallery-mobile-fallback-value'));
366 } catch (error) {
367 return false;
368 }
369 }
370
371 mobileValue = FOOGALLERY.getSettingControlValue($mobileControl, settingType);
372 $target.attr(
373 'data-foogallery-mobile-mode',
374 FOOGALLERY.mobileSettingValuesMatch(mobileValue, fallbackValue) ? fallbackMode : 'custom'
375 );
376
377 return true;
378 };
379
380 FOOGALLERY.setSettingControlValue = function($target, settingType, value) {
381 if (!$target.length) return;
382
383 switch (settingType) {
384 case 'radio':
385 case 'icon':
386 case 'htmlicon':
387 $target.find('input[type="radio"]').prop('checked', false).filter(function() {
388 return $(this).val() === String(value);
389 }).prop('checked', true);
390 break;
391 case 'checkbox':
392 $target.find('input[type="checkbox"]').prop('checked', value === 'on');
393 break;
394 case 'select':
395 $target.find('select').val(value);
396 break;
397 case 'text':
398 case 'textarea':
399 case 'number':
400 case 'slider':
401 $target.find(':input, range-input').first().val(value);
402 break;
403 default:
404 if ($.isPlainObject(value)) {
405 $.each(value, function(key, childValue) {
406 $target.find('[name$="[' + key + ']"]').val(childValue);
407 });
408 }
409 break;
410 }
411 };
412
413 FOOGALLERY.getSettingControlValue = function($source, settingType) {
414 if (!$source.length) return undefined;
415
416 switch (settingType) {
417 case 'radio':
418 case 'icon':
419 case 'htmlicon':
420 return $source.find('input:checked').val();
421 case 'checkbox':
422 return $source.find('input[type="checkbox"]').is(':checked') ? 'on' : '';
423 case 'select':
424 return $source.find('select').val();
425 case 'text':
426 case 'textarea':
427 case 'number':
428 case 'slider':
429 return $source.find(':input, range-input').first().val();
430 default:
431 var value = {};
432 $.each($source.find(':input').serializeArray(), function(index, entry) {
433 var key = entry.name.match(/\[([^\]]+)\]$/);
434 if (key) value[key[1]] = entry.value;
435 });
436 return value;
437 }
438 };
439
440 FOOGALLERY.syncInheritedMobileSetting = function($field, changedElement) {
441 if (!$field.length ||
442 $field.attr('data-foogallery-mobile-fallback-mode') !== 'inherit' ||
443 $field.hasClass('foogallery_template_field_template_hidden') ||
444 $field.attr('data-foogallery-locked') !== undefined) return false;
445
446 var $desktopControl = $(changedElement).closest('.foogallery-setting-control-desktop'),
447 $mobileControl = $field.find('.foogallery-setting-control-mobile'),
448 settingType = $field.data('foogallery-setting-type'),
449 value;
450
451 if (!$desktopControl.length || !$mobileControl.length) return false;
452
453 value = FOOGALLERY.getSettingControlValue($desktopControl, settingType);
454 if (value === undefined) return false;
455
456 $field.attr('data-foogallery-mobile-fallback-value', JSON.stringify(value));
457 if ($field.attr('data-foogallery-mobile-mode') === 'inherit') {
458 FOOGALLERY.setSettingControlValue($mobileControl, settingType, value);
459 }
460
461 return true;
462 };
463
464 FOOGALLERY.mobileSettingValuesMatch = function(left, right) {
465 if ($.isPlainObject(left) || $.isPlainObject(right) || Array.isArray(left) || Array.isArray(right)) {
466 return JSON.stringify(left) === JSON.stringify(right);
467 }
468
469 return String(left == null ? '' : left) === String(right == null ? '' : right);
470 };
471
472 FOOGALLERY.syncMobileSettingMode = function($field, changedElement) {
473 var $mobileControl = $(changedElement).closest('.foogallery-setting-control-mobile'),
474 fallbackValue,
475 value;
476
477 if (!$field.length || !$mobileControl.length) return false;
478
479 try {
480 fallbackValue = JSON.parse($field.attr('data-foogallery-mobile-fallback-value'));
481 } catch (error) {
482 return false;
483 }
484
485 value = FOOGALLERY.getSettingControlValue($mobileControl, $field.data('foogallery-setting-type'));
486 $field.attr(
487 'data-foogallery-mobile-mode',
488 FOOGALLERY.mobileSettingValuesMatch(value, fallbackValue)
489 ? ($field.attr('data-foogallery-mobile-fallback-mode') || 'inherit')
490 : 'custom'
491 );
492
493 return true;
494 };
495
496 FOOGALLERY.galleryTemplateChanged = function(reloadPreview) {
497 var selectedTemplate = FOOGALLERY.getSelectedTemplate(),
498 $settingsToShow = $('.foogallery-settings-container-' + selectedTemplate),
499 $settingsToHide = $('.foogallery-settings-container').not($settingsToShow),
500 $currentTab = $settingsToHide.find('.foogallery-vertical-tab.foogallery-tab-active'),
501 currentTab = $currentTab.data('name'),
502 currentChildTab = $currentTab.find('.foogallery-vertical-child-tab.foogallery-tab-active').data('name'),
503 previousSelectedTemplate = FOOGALLERY.selected_gallery_template;
504
505 FOOGALLERY.selected_gallery_template = selectedTemplate;
506
507 var previousSuppressState = FOOGALLERY.suppressPreviewRefresh;
508 FOOGALLERY.suppressPreviewRefresh = true;
509
510 var persistedCount = 0;
511
512 //check for persist settings
513 $('.foogallery-settings-container-' + previousSelectedTemplate + ' [data-foogallery-persist]').each(function() {
514 var $this = $(this),
515 settingId = $this.data('foogallery-setting-id'),
516 settingType = $this.data('foogallery-setting-type'),
517 $newSetting = $settingsToShow.find('[data-foogallery-setting-id="' + settingId + '"]');
518
519 if ( $this.hasClass('foogallery_template_field_template_hidden') ) {
520 return;
521 }
522
523 if ( $newSetting.length ) {
524 var $sources = $this.is('[data-foogallery-mobile-friendly]') ? $this.find('.foogallery-setting-control') : $this;
525
526 $sources.each(function() {
527 var $source = $(this),
528 viewport = $source.data('viewport'),
529 $target = viewport ? $newSetting.find('.foogallery-setting-control[data-viewport="' + viewport + '"]') : $newSetting;
530
531 if (FOOGALLERY.persistSettingValue($source, $target, settingType)) {
532 persistedCount++;
533 }
534 });
535
536 FOOGALLERY.persistResponsiveSettingState($this, $newSetting);
537 }
538 });
539
540 console.log('Persisted ' + persistedCount + ' settings.');
541
542 FOOGALLERY.suppressPreviewRefresh = previousSuppressState;
543
544 //hide all template fields
545 $settingsToHide.hide()
546 .removeClass('foogallery-settings-container-active')
547 .find(':input, range-input').attr('disabled', true);
548
549 //show all fields for the selected template only
550 $settingsToShow.show()
551 .addClass('foogallery-settings-container-active');
552
553 FOOGALLERY.enableUnlockedSettingFields($settingsToShow);
554 FOOGALLERY.previewActionsController.updateResponsiveSettings();
555
556 if (currentTab) {
557 currentTab = currentTab.replace( previousSelectedTemplate, selectedTemplate );
558
559 //ensure the previously active tab is clicked
560 $settingsToShow.find('.foogallery-vertical-tab[data-name="' + currentTab + '"]').trigger('click');
561
562 if (currentChildTab) {
563 currentChildTab = currentChildTab.replace( previousSelectedTemplate, selectedTemplate );
564
565 //ensure the previously active child tab is clicked
566 $settingsToShow.find('.foogallery-vertical-child-tab[data-name="' + currentChildTab + '"]').trigger('click');
567 }
568 }
569
570 // always ensure a tab is clicked
571 if ( $settingsToShow.find('.foogallery-vertical-tab.foogallery-tab-active').length === 0 ) {
572 $settingsToShow.find('.foogallery-vertical-tab:first').trigger('click');
573 }
574
575 //trigger a change so custom template js can do something
576 FOOGALLERY.triggerTemplateChangedEvent();
577
578 if (reloadPreview) {
579 FOOGALLERY.reloadGalleryPreview();
580 }
581 };
582
583 FOOGALLERY.handleSettingFieldChange = function(reloadPreview, setContainerHeight) {
584
585 //make sure the fields that should be hidden or shown are doing what they need to do
586 FOOGALLERY.handleSettingsShowRules();
587
588 //update the gallery preview
589 FOOGALLERY.updateGalleryPreview(reloadPreview, setContainerHeight);
590 };
591
592 FOOGALLERY.handleSettingControlChange = function($fieldContainer, changedElement) {
593 FOOGALLERY.syncInheritedMobileSetting($fieldContainer, changedElement);
594 FOOGALLERY.syncMobileSettingMode($fieldContainer, changedElement);
595
596 if ($fieldContainer.data('foogallery-preview') && $fieldContainer.data('foogallery-preview').indexOf('shortcode') !== -1) {
597 FOOGALLERY.reloadGalleryPreview();
598 } else {
599 FOOGALLERY.handleSettingFieldChange(
600 $fieldContainer.data('foogallery-preview') && $fieldContainer.data('foogallery-preview').indexOf('class') !== -1,
601 true
602 );
603 }
604 };
605
606 FOOGALLERY.updateGalleryPreview = function( initGallery, setContainerHeight ) {
607 var $preview = $('.foogallery_preview_container .foogallery'),
608 $preview_container = $('.foogallery_preview_container');
609
610 if ( setContainerHeight ) {
611 $preview_container.css('height', $preview_container.height());
612 }
613
614 //this allows any extensions to hook into the template change event
615 $('body').trigger('foogallery-gallery-preview-updated' + FOOGALLERY.getSelectedTemplate() );
616
617 //this handles all built-in templates that use the FooGallery core client side JS
618 if ( $preview.data('fg-common-fields') ) {
619 if ( initGallery ) {
620 $preview.foogallery( {}, function() {
621 $preview_container.css( 'height', '' );
622 if ( !$preview_container.find('.foogallery').data('foogallery-lightbox') ) {
623 $preview_container.find(".fg-thumb").off("click.foogallery").on("click", function (e) {
624 e.preventDefault();
625 });
626 }
627 } );
628 } else {
629 $preview.foogallery( 'layout' );
630 $preview_container.css( 'height', '' );
631 }
632 } else {
633 //reset the height to what it should be
634 $preview_container.css('height', '');
635 }
636 };
637
638 FOOGALLERY.getGalleryPreviewSettingsData = function($shortcodeFields) {
639 var data = [];
640
641 if (!$shortcodeFields.length) return data;
642
643 data = $shortcodeFields.find(':input').serializeArray();
644 $shortcodeFields.find('range-input').each(function() {
645 if (!this.hasAttribute('disabled')) {
646 data.push({name: this.name, value: this.value});
647 }
648 });
649
650 return data;
651 };
652
653 FOOGALLERY.reloadGalleryPreview = function() {
654 if ( FOOGALLERY.suppressPreviewRefresh ) {
655 return;
656 }
657
658 //make sure the fields that should be hidden or shown are doing what they need to do
659 FOOGALLERY.handleSettingsShowRules();
660
661 var $preview_container = $('.foogallery_preview_container'),
662 $preview = $preview_container.find('.foogallery');
663
664 //set the preview height so there is no jump
665 $preview_container.css('height', $preview_container.height());
666
667 //build up all the data to generate a preview
668 var $shortcodeFields = $('.foogallery-settings-container-active .foogallery-metabox-settings .foogallery_template_field[data-foogallery-preview*="shortcode"]'),
669 data = FOOGALLERY.getGalleryPreviewSettingsData($shortcodeFields),
670 foogallery_id = $('#post_ID').val();
671
672 //clear any items just in case
673 window['foogallery-gallery-' + foogallery_id + '_items'] = null;
674
675 //add additional data for the preview
676 data.push({name: 'foogallery_id', value: foogallery_id});
677 data.push({name: 'foogallery_template', value: FOOGALLERY.getSelectedTemplate()});
678
679 //include other preview fields
680 var previewData = $('[data-foogallery-preview="include"]').serializeArray();
681 data = data.concat(previewData);
682
683 //data.push({name: 'foogallery_attachments', value: $('#foogallery_attachments').val()});
684 data.push({name: 'foogallery_datasource', value: $('#foogallery_datasource').val()});
685 data.push({name: 'foogallery_datasource_value', value: $('#_foogallery_datasource_value').val()});
686
687 //add data needed for the ajax call
688 data.push({name: 'action', value: 'foogallery_preview'});
689 data.push({name: 'foogallery_preview_nonce', value: $('#foogallery_preview').val()});
690 data.push({name: '_wp_http_referer', value: encodeURIComponent($('input[name="_wp_http_referer"]').val())});
691
692 $('#foogallery_preview_spinner').addClass('is-active');
693 $preview_container.addClass('loading');
694
695 if ($preview.length > 0){
696 var fg = $preview.data("__FooGallery__");
697 if (fg instanceof FooGallery.Template){
698 fg.destroy(false);
699 }
700 }
701
702 $.ajax({
703 type: "POST",
704 url: ajaxurl,
705 data: data,
706 cache: false,
707 success: function(data) {
708 $('.foogallery_preview_container .foogallery').foogallery("destroy");
709
710 //updated the preview
711 $preview_container.html(data);
712 $('#foogallery_preview_spinner').removeClass('is-active');
713 $preview_container.removeClass('loading foogallery-preview-force-refresh');
714
715 FOOGALLERY.updateGalleryPreview(true, true);
716 }
717 });
718 };
719
720 FOOGALLERY.handleSettingsShowRules = function() {
721 var selectedTemplate = FOOGALLERY.getSelectedTemplate();
722
723 //hide any fields that need to be hidden initially
724 $('.foogallery-settings-container-active .foogallery_template_field[data-foogallery-hidden]').hide()
725 .addClass('foogallery_template_field_template_hidden')
726 .find(':input, range-input').attr('disabled', true);
727
728 $('.foogallery-settings-container-active .foogallery_template_field[data-foogallery-show-when-field]').each(function(index, item) {
729 var $item = $(item),
730 itemLabel = $item.find('th label').text(),
731 fieldId = $item.data('foogallery-show-when-field'),
732 fieldValue = $item.data('foogallery-show-when-field-value'),
733 fieldOperator = $item.data('foogallery-show-when-field-operator'),
734 $fieldRow = $('.foogallery_template_field_template_id-' + selectedTemplate + '-' + fieldId),
735 $fieldSelector = $fieldRow.data('foogallery-value-selector'),
736 fieldValueAttribute = $fieldRow.data('foogallery-value-attribute'),
737 $fieldScope = $fieldRow.is('[data-foogallery-mobile-friendly]') ? $fieldRow.find('.foogallery-setting-control:not([hidden])') : $fieldRow,
738 $field = $fieldScope.find($fieldSelector),
739 showField = false;
740
741 if ( $fieldRow.length === 0 ) {
742 // No matching field was found, which means we can un-hide
743 showField = true;
744 } else {
745
746 if ( $fieldRow.hasClass( 'foogallery_template_field_template_hidden' ) ) {
747 // The field we are checking is hidden, which means we should not rely on it
748 } else {
749
750 $field.each(function () {
751 var actualFieldValue = fieldValueAttribute ? $(this).attr(fieldValueAttribute) : $(this).val();
752
753 if (fieldOperator === '!==') {
754 if (actualFieldValue !== fieldValue) {
755 showField = true;
756 }
757 } else if (fieldOperator === 'regex') {
758 var re = new RegExp(fieldValue);
759 if (re.test(actualFieldValue)) {
760 showField = true;
761 }
762 } else if (fieldOperator === 'indexOf') {
763 if (actualFieldValue.indexOf(fieldValue) !== -1) {
764 showField = true;
765 }
766 } else if (actualFieldValue === fieldValue) {
767 showField = true;
768 }
769 });
770 }
771
772 }
773
774 if (showField) {
775 $item.show()
776 .removeClass('foogallery_template_field_template_hidden');
777
778 FOOGALLERY.enableUnlockedSettingFields($item);
779 $item.find('.colorpicker').not(function() {
780 return $(this).closest(FOOGALLERY.lockedSettingFieldSelector).length > 0;
781 }).spectrum("enable");
782 FOOGALLERY.enforceLockedSettingFields($item);
783 }
784 });
785
786 FOOGALLERY.handleSettingsTabs();
787 };
788
789 FOOGALLERY.handleSettingsTabs = function() {
790 var $activeSettings = $('.foogallery-settings-container-active'),
791 $tabs = $activeSettings.find('.foogallery-vertical-tab');
792
793 $tabs.each(function() {
794 var $tab = $(this),
795 tabName = $tab.data('name'),
796 $content = $activeSettings.find('.foogallery-tab-content[data-name="' + tabName + '"]'),
797 hasVisibleFields = $content.find('tr:not(.foogallery_template_field_template_hidden)').length > 0;
798
799 $tab.find('.foogallery-vertical-child-tab').each(function() {
800 var $childTab = $(this),
801 childName = $childTab.data('name'),
802 $childContent = $activeSettings.find('.foogallery-tab-content[data-name="' + childName + '"]'),
803 childHasVisibleFields = $childContent.find('tr:not(.foogallery_template_field_template_hidden)').length > 0;
804
805 if (childHasVisibleFields) {
806 $childTab.show();
807 hasVisibleFields = true;
808 } else {
809 $childTab.hide().removeClass('foogallery-tab-active');
810 $childContent.removeClass('foogallery-tab-active');
811 }
812 });
813
814 if (hasVisibleFields) {
815 $tab.show();
816 } else {
817 $tab.hide().removeClass('foogallery-tab-active');
818 $content.removeClass('foogallery-tab-active');
819 }
820 });
821
822 var $activeTab = $activeSettings.find('.foogallery-vertical-tab.foogallery-tab-active:visible'),
823 $visibleTabs = $activeSettings.find('.foogallery-vertical-tab:visible');
824
825 if ($activeTab.length === 0 && $visibleTabs.length) {
826 $visibleTabs.first().trigger('click');
827 } else if ($activeTab.length) {
828 var $visibleChildren = $activeTab.find('.foogallery-vertical-child-tab:visible');
829
830 if ($visibleChildren.length && $visibleChildren.filter('.foogallery-tab-active').length === 0) {
831 $visibleChildren.first().trigger('click');
832 }
833 }
834 };
835
836 FOOGALLERY.initSettings = function() {
837 //move the template selector into the metabox heading
838 var $metabox_heading = $('#foogallery_settings .hndle span');
839 //This check is done to accommodate a markup change in WP 5.5
840 if ( $metabox_heading.length === 0 ) {
841 $metabox_heading = $('#foogallery_settings .hndle');
842 $metabox_heading.addClass( 'foogallery-custom-metabox-header' );
843 }
844
845 $('.foogallery-template-selector').appendTo( $metabox_heading ).removeClass('foogallery-hidden');
846
847 //remove the loading spinner
848 $('.foogallery-gallery-items-metabox-title').remove();
849
850 var $items_metabox_heading = $('#foogallery_items .hndle span');
851 //This check is done to accommodate a markup change in WP 5.5
852 if ( $items_metabox_heading.length === 0 ) {
853 $items_metabox_heading = $('#foogallery_items .hndle');
854 $items_metabox_heading.addClass( 'foogallery-custom-metabox-header' );
855 }
856
857 $('.foogallery-items-view-switch-container').appendTo( $items_metabox_heading ).removeClass('foogallery-hidden');
858
859 //Bind to the Manage / Preview buttons
860 $('.foogallery-items-view-switch-container a').on('click', function(e) {
861 e.stopPropagation();
862
863 var $currentButton = $('.foogallery-items-view-switch-container a.current'),
864 currentSelector = $currentButton.data('container'),
865 $nextButton = $(this),
866 nextSelector = $nextButton.data('container'),
867 value = $nextButton.data('value');
868
869 //if the preview button is already selected, and we are clicking it again, then force a preview refresh
870 if ( currentSelector === nextSelector && value === 'preview' ) {
871 $('.foogallery_preview_container').addClass('foogallery-preview-force-refresh');
872 }
873
874 if ( value === 'preview' ) {
875 //show the viewport buttons
876 $('.foogallery-preview-actions').show();
877 } else {
878 $('.foogallery-preview-actions').hide();
879 }
880
881 //toggle the views
882 $(currentSelector).hide();
883 $(nextSelector).show();
884
885 //toggle the switch button
886 $currentButton.removeClass('current');
887 $nextButton.addClass('current');
888
889 //set the input so that it is saved
890 $('#foogallery_items_view_input').val(value);
891
892 if ( $('.foogallery_preview_container').is(':visible') ) {
893 FOOGALLERY.updateGalleryPreview(false, false);
894
895 //check if there is no preview
896 if ( !$.trim( $('.foogallery_preview_container').html() ) ||
897 $( '.foogallery_preview_container.foogallery-preview-force-refresh').length > 0 ) {
898 FOOGALLERY.reloadGalleryPreview();
899 }
900 }
901 });
902
903 FOOGALLERY.previewActionsController.init();
904
905 $(function() {
906
907 // Prevent inputs in settings meta box headings opening/closing contents.
908 $( '#foogallery_settings' ).find( '.hndle' ).off( 'click.postboxes' );
909
910 $( '#foogallery_settings' ).on( 'click', '.hndle', function( event ) {
911
912 // If the user clicks on some form input inside the h3 the box should not be toggled.
913 if ( $( event.target ).filter( 'input, option, label, select' ).length ) {
914 return;
915 }
916
917 $( '#foogallery_settings' ).toggleClass( 'closed' );
918 });
919
920 // Prevent inputs in items meta box headings opening/closing contents.
921 $( '#foogallery_items' ).find( '.hndle' ).off( 'click.postboxes' );
922
923 $( '#foogallery_items' ).on( 'click', '.hndle', function( event ) {
924
925 // If the user clicks on some form input inside the h3 the box should not be toggled.
926 if ( $( event.target ).filter( 'input, option, label, select' ).length ) {
927 return;
928 }
929
930 $( '#foogallery_items' ).toggleClass( 'closed' );
931 });
932 });
933
934 //hook into settings fields changes
935 $('.foogallery-metabox-settings .foogallery_template_field[data-foogallery-change-selector]').each(function(index, item) {
936 var $fieldContainer = $(item),
937 selector = $fieldContainer.data('foogallery-change-selector');
938
939 $fieldContainer.find(selector).on('change', function() {
940 FOOGALLERY.handleSettingControlChange($fieldContainer, this);
941 });
942 });
943
944 $(document).on('change', 'input[name="foogallery_sort"]', function() {
945 $('.foogallery_preview_container').addClass('foogallery-preview-force-refresh');
946
947 if ( $('.foogallery_preview_container').is(':visible') ) {
948 FOOGALLERY.reloadGalleryPreview();
949 }
950 });
951
952 //trigger this onload too!
953 FOOGALLERY.galleryTemplateChanged(false);
954
955 //force hidden field state to be correct on load
956 FOOGALLERY.handleSettingFieldChange(true, false);
957 };
958
959 FOOGALLERY.getSelectedTemplate = function() {
960 return $('#FooGallerySettings_GalleryTemplate').val();
961 };
962
963 FOOGALLERY.triggerTemplateChangedEvent = function() {
964 $('body').trigger('foogallery-gallery-template-changed-' + FOOGALLERY.getSelectedTemplate() );
965 };
966
967 FOOGALLERY.triggerAttachmentsChangedEvent = function(action, attachmentId) {
968 var attachments = $.isArray(FOOGALLERY.attachments) ? FOOGALLERY.attachments.slice(0) : [];
969
970 $('body').trigger('foogallery-attachments-changed', [attachments, action || '', parseInt(attachmentId, 10) || 0]);
971 };
972
973 FOOGALLERY.addAttachmentToGalleryList = function(attachment) {
974
975 if ($.inArray(attachment.id, FOOGALLERY.attachments) !== -1) return;
976
977 var $template = $($('#foogallery-attachment-template').val());
978
979 $template.attr('data-attachment-id', attachment.id);
980
981 $template.find('img').attr('src', attachment.src);
982
983 if (attachment.subtype) {
984 $template.find('.attachment-preview.type-image').addClass('subtype-' + attachment.subtype);
985 }
986
987 if ( $('.foogallery-attachments-list').hasClass('foogallery-add-media-button-start') ) {
988 $('.foogallery-attachments-list .datasource-medialibrary').after($template);
989 } else {
990 $('.foogallery-attachments-list .datasource-medialibrary').before($template);
991 }
992
993 FOOGALLERY.attachments.push( attachment.id );
994
995 FOOGALLERY.calculateAttachmentIds();
996
997 FOOGALLERY.calculateHiddenAreas();
998
999 $('.foogallery_preview_container').addClass('foogallery-preview-force-refresh');
1000
1001 FOOGALLERY.triggerAttachmentsChangedEvent('add', attachment.id);
1002 };
1003
1004 FOOGALLERY.removeAttachmentFromGalleryList = function(id) {
1005 var index = $.inArray(id, FOOGALLERY.attachments);
1006 if (index !== -1) {
1007 FOOGALLERY.attachments.splice(index, 1);
1008 }
1009 $('.foogallery-attachments-list [data-attachment-id="' + id + '"]').remove();
1010
1011 FOOGALLERY.calculateAttachmentIds();
1012
1013 FOOGALLERY.calculateHiddenAreas();
1014
1015 FOOGALLERY.triggerAttachmentsChangedEvent('remove', id);
1016 };
1017
1018 FOOGALLERY.showAttachmentInfoModal = function(id) {
1019 FOOGALLERY.openMediaModal( id );
1020 };
1021
1022 FOOGALLERY.openMediaModal = function(selected_attachment_id) {
1023 if (!selected_attachment_id) { selected_attachment_id = 0; }
1024
1025 var modal_style = $('#foogallery-image-edit-modal').data('modal_style');
1026
1027 if ( selected_attachment_id > 0 && modal_style === 'on') {
1028 FOOGALLERY.openAttachmentModal( selected_attachment_id );
1029 } else {
1030 FOOGALLERY.selected_attachment_id = selected_attachment_id;
1031
1032 if (FOOGALLERY.media_uploader !== false){
1033 FOOGALLERY.media_uploader.open();
1034 return;
1035 }
1036
1037 var createModal = $.isFunction(wp.foogallery) ? wp.foogallery : wp.media;
1038
1039 // Create our FooGallery media frame (use the child Select when available so extensions can override it).
1040 FOOGALLERY.media_uploader = createModal({
1041 frame: ( wp.foogallery && wp.foogallery.media && wp.foogallery.media.Select ) ? "select-child" : "select",
1042 multiple: 'add',
1043 title: FOOGALLERY.mediaModalTitle,
1044 button: {
1045 text: FOOGALLERY.mediaModalButtonText
1046 },
1047 library: {
1048 type: "image"
1049 }
1050 }).on("select", function(){
1051 var attachments = FOOGALLERY.media_uploader.state().get('selection').toJSON();
1052
1053 $.each(attachments, function(i, item) {
1054 if ( item && item.id ) {
1055 var attachment = {
1056 id: item.id,
1057 src: null,
1058 subtype: null
1059 };
1060 if ( item.sizes && item.sizes.thumbnail) {
1061 attachment.src = item.sizes.thumbnail.url;
1062 } else {
1063 //thumbnail could not be found for whatever reason. Default to the full image URL
1064 attachment.src = item.url;
1065 }
1066 if ( item.subtype ) {
1067 attachment.subtype = item.subtype;
1068 }
1069
1070 FOOGALLERY.addAttachmentToGalleryList(attachment);
1071 } else {
1072 //there was a problem adding the item! Move on to the next
1073 alert( 'There was a problem adding the item to the gallery!' );
1074 }
1075 });
1076 })
1077 .on( 'open', function() {
1078 var selection = FOOGALLERY.media_uploader.state().get('selection');
1079 if (selection && !$.isFunction(wp.foogallery)) {
1080 //clear any previous selections
1081 selection.reset();
1082 }
1083
1084 if (FOOGALLERY.selected_attachment_id > 0) {
1085 var attachment = wp.media.attachment(FOOGALLERY.selected_attachment_id);
1086 attachment.fetch();
1087 selection.add( attachment ? [ attachment ] : [] );
1088 } else {
1089 //would be nice to have all previously added media selected
1090 }
1091 });
1092
1093 // Finally, open the modal
1094 FOOGALLERY.media_uploader.open();
1095 }
1096 };
1097
1098 FOOGALLERY.initUsageMetabox = function() {
1099 $('#foogallery_create_page').on('click', function(e) {
1100 e.preventDefault();
1101
1102 $('#foogallery_create_page_spinner').addClass('is-active');
1103 var data = 'action=foogallery_create_gallery_page' +
1104 '&foogallery_id=' + $('#post_ID').val() +
1105 '&foogallery_create_gallery_page_nonce=' + $('#foogallery_create_gallery_page_nonce').val() +
1106 '&_wp_http_referer=' + encodeURIComponent($('input[name="_wp_http_referer"]').val());
1107
1108 $.ajax({
1109 type: "POST",
1110 url: ajaxurl,
1111 data: data,
1112 success: function(data) {
1113 if (data && data.success) {
1114 //refresh page
1115 location.reload();
1116 return;
1117 }
1118
1119 var message = data && data.data && data.data.message ? data.data.message : 'Unable to create page.';
1120 alert(message);
1121 $('#foogallery_create_page_spinner').removeClass('is-active');
1122 },
1123 error: function(xhr) {
1124 var message = xhr.responseJSON && xhr.responseJSON.data && xhr.responseJSON.data.message ? xhr.responseJSON.data.message : 'Unable to create page.';
1125 alert(message);
1126 $('#foogallery_create_page_spinner').removeClass('is-active');
1127 }
1128 });
1129 });
1130 };
1131
1132 FOOGALLERY.initThumbCacheMetabox = function() {
1133 $('#foogallery_clear_thumb_cache').on('click', function(e) {
1134 e.preventDefault();
1135
1136 $('#foogallery_clear_thumb_cache_spinner').addClass('is-active');
1137 var data = 'action=foogallery_clear_gallery_thumb_cache' +
1138 '&foogallery_id=' + $('#post_ID').val() +
1139 '&foogallery_clear_gallery_thumb_cache_nonce=' + $('#foogallery_clear_gallery_thumb_cache_nonce').val() +
1140 '&_wp_http_referer=' + encodeURIComponent($('input[name="_wp_http_referer"]').val());
1141
1142 $.ajax({
1143 type: "POST",
1144 url: ajaxurl,
1145 data: data,
1146 success: function(data) {
1147 var message = data && data.data && data.data.message ? data.data.message : data;
1148 alert(message);
1149 $('#foogallery_clear_thumb_cache_spinner').removeClass('is-active');
1150 },
1151 error: function(xhr) {
1152 var message = xhr.responseJSON && xhr.responseJSON.data && xhr.responseJSON.data.message ? xhr.responseJSON.data.message : 'There was a problem clearing the thumbnail cache.';
1153 alert(message);
1154 $('#foogallery_clear_thumb_cache_spinner').removeClass('is-active');
1155 }
1156 });
1157 });
1158 };
1159
1160 FOOGALLERY.initShortcodeHelpers = function() {
1161 var $toggle = $('#foogallery_toggle_shortcode_helpers');
1162
1163 if ( !$toggle.length ) {
1164 return;
1165 }
1166
1167 var helperSelector = '.foogallery-shortcode-argument-helper, .foogallery-shortcode-choice-helper, .foogallery-shortcode-select-helper',
1168 copyHelperText = function(text) {
1169 if (navigator.clipboard && navigator.clipboard.writeText) {
1170 navigator.clipboard.writeText(text).catch(fallbackCopy);
1171 } else {
1172 fallbackCopy();
1173 }
1174
1175 function fallbackCopy() {
1176 var $temp = $('<textarea class="foogallery-shortcode-hidden"></textarea>');
1177 $temp.val(text)
1178 .attr('readonly', 'readonly')
1179 .css({ position: 'absolute', left: '-9999px', top: '0' });
1180 $('body').append($temp);
1181 $temp[0].select();
1182
1183 try {
1184 document.execCommand('copy');
1185 } catch (err) {
1186 console.log('Oops, unable to copy!');
1187 }
1188
1189 $temp.remove();
1190 }
1191 };
1192
1193 $(document)
1194 .off('mousedown.foogalleryShortcodeHelper', helperSelector)
1195 .on('mousedown.foogalleryShortcodeHelper', helperSelector, function(e) {
1196 e.preventDefault();
1197 e.stopPropagation();
1198 })
1199 .off('click.foogalleryShortcodeHelper', helperSelector)
1200 .on('click.foogalleryShortcodeHelper', helperSelector, function(e) {
1201 e.preventDefault();
1202 e.stopPropagation();
1203
1204 copyHelperText($(this).find('code').text());
1205 });
1206
1207 $('.foogallery-metabox-settings label[data-setting]').each(function() {
1208 var $label = $(this),
1209 settingId = $label.data('setting');
1210
1211 if ( !settingId || $label.find('.foogallery-shortcode-argument-helper').length ) {
1212 return;
1213 }
1214
1215 $label.append(
1216 $('<span class="foogallery-shortcode-argument-helper" aria-hidden="true"></span>').append(
1217 $('<code></code>').text(settingId)
1218 )
1219 );
1220 });
1221
1222 $('.foogallery_metabox_field-radio > label').each(function() {
1223 var $label = $(this),
1224 $input = $label.find('input[type="radio"]').first(),
1225 choiceValue = $input.val(),
1226 choiceHelperText = choiceValue === '' ? '<empty>' : choiceValue;
1227
1228 if ( !$input.length || typeof choiceValue === 'undefined' || $label.find('.foogallery-shortcode-choice-helper').length ) {
1229 return;
1230 }
1231
1232 $label.append(
1233 $('<span class="foogallery-shortcode-choice-helper foogallery-shortcode-choice-helper-radio" aria-hidden="true"></span>').append(
1234 $('<code></code>').text(choiceHelperText)
1235 )
1236 );
1237 });
1238
1239 $('.foogallery_metabox_field-htmlicon > label[for]').each(function() {
1240 var $label = $(this),
1241 inputId = $label.attr('for'),
1242 $input = $('#' + inputId),
1243 choiceValue = $input.val(),
1244 choiceHelperText = choiceValue === '' ? '<empty>' : choiceValue;
1245
1246 if ( !$input.length || typeof choiceValue === 'undefined' || $label.next('.foogallery-shortcode-choice-helper-htmlicon').length ) {
1247 return;
1248 }
1249
1250 var $helper = $('<span class="foogallery-shortcode-choice-helper foogallery-shortcode-choice-helper-htmlicon" aria-hidden="true"></span>').append(
1251 $('<code></code>').text(choiceHelperText)
1252 );
1253
1254 $label.after($helper);
1255
1256 if ( !$input.parent().hasClass('foogallery-shortcode-choice-group-htmlicon') ) {
1257 $input.add($label).add($helper).wrapAll('<span class="foogallery-shortcode-choice-group-htmlicon"></span>');
1258 }
1259 });
1260
1261 $('.foogallery_metabox_field-select select').each(function() {
1262 var $select = $(this),
1263 $helper = $select.siblings('.foogallery-shortcode-select-helper'),
1264 updateHelper = function() {
1265 var selectedValue = $select.val(),
1266 helperText = selectedValue === '' ? '<empty>' : selectedValue;
1267
1268 if ( typeof selectedValue === 'undefined' ) {
1269 return;
1270 }
1271
1272 $helper.find('code').text(helperText);
1273 };
1274
1275 if ( !$helper.length ) {
1276 $helper = $('<span class="foogallery-shortcode-select-helper" aria-hidden="true"></span>').append(
1277 $('<code></code>')
1278 );
1279 $select.after($helper);
1280 }
1281
1282 updateHelper();
1283 $select.off('change.foogalleryShortcodeHelper').on('change.foogalleryShortcodeHelper', updateHelper);
1284 });
1285
1286 var showLabel = $toggle.data('show-label') || 'Show Argument Helpers',
1287 hideLabel = $toggle.data('hide-label') || 'Hide Argument Helpers',
1288 stateClass = 'foogallery-show-argument-helpers',
1289 updateState = function(show) {
1290 $('body').toggleClass(stateClass, show);
1291 $toggle.attr('aria-expanded', show ? 'true' : 'false').text(show ? hideLabel : showLabel);
1292 };
1293
1294 updateState(false);
1295
1296 $toggle.on('click', function(e) {
1297 e.preventDefault();
1298 updateState( !$('body').hasClass(stateClass) );
1299 });
1300 };
1301
1302 FOOGALLERY.adminReady = function () {
1303 $('.upload_image_button').on('click', function(e) {
1304 e.preventDefault();
1305 FOOGALLERY.mediaModalTitle = $(this).data( 'uploader-title' );
1306 FOOGALLERY.mediaModalButtonText = $(this).data( 'uploader-button-text' );
1307 FOOGALLERY.openMediaModal(0);
1308 });
1309
1310 $('.remove_all_media').on('click', function(e) {
1311 $('.foogallery-attachments-list a.remove').trigger('click');
1312 });
1313
1314 $(document).on('foogallery-datasource-changed', function(e, activeDatasource) {
1315 FOOGALLERY.showHiddenAreas( activeDatasource === 'media_library' );
1316 });
1317
1318 FOOGALLERY.initAttachments();
1319
1320 FOOGALLERY.initSettings();
1321
1322 FOOGALLERY.initUsageMetabox();
1323
1324 FOOGALLERY.initThumbCacheMetabox();
1325
1326 FOOGALLERY.initShortcodeHelpers();
1327
1328 FOOGALLERY.initAttachmentModal();
1329
1330 FOOGALLERY.initMediaSelector();
1331
1332 $('.foogallery-attachments-list')
1333 .on('click' ,'a.remove', function(e) {
1334 e.preventDefault();
1335 var $selected = $(this).parents('li:first'),
1336 attachment_id = $selected.data('attachment-id');
1337 FOOGALLERY.removeAttachmentFromGalleryList(attachment_id);
1338 })
1339 .on('click' ,'a.info', function() {
1340 var $selected = $(this).parents('li:first'),
1341 attachment_id = $selected.data('attachment-id');
1342 FOOGALLERY.showAttachmentInfoModal(attachment_id);
1343 })
1344 .sortable({
1345 items: 'li:not(.add-attachment)',
1346 distance: 10,
1347 placeholder: 'attachment placeholder',
1348 stop : function() {
1349 FOOGALLERY.calculateAttachmentIds();
1350 }
1351 });
1352
1353 //init any colorpickers
1354 $('.colorpicker').spectrum({
1355 preferredFormat: "rgb",
1356 showInput: true,
1357 clickoutFiresChange: true
1358 });
1359
1360 if (typeof IntersectionObserver === "undefined") {
1361 $(".foogallery-attachments-list .attachment .thumbnail img").each(function(i, img){
1362 var $img = $(img);
1363 $img.attr("src", $img.data("src"));
1364 });
1365 } else {
1366 //lazy loading of images on the gallery edit page
1367 var io = new IntersectionObserver(function (entries) {
1368 entries.forEach(function (entry) {
1369 if (entry.isIntersecting) {
1370 var $target = $(entry.target);
1371 $target.attr("src", $target.data("src"));
1372 io.unobserve(entry.target);
1373 }
1374 });
1375 }, {
1376 root: $(".foogallery-attachments-list").get(0)
1377 });
1378
1379 $(".foogallery-attachments-list .attachment .thumbnail img").each(function(i, img){
1380 io.observe(img);
1381 });
1382 }
1383
1384 $('.foogallery-admin-promo-dismiss').on('click', function(e) {
1385 e.preventDefault();
1386 alert( 'If you want to turn off these promotional messages forever, goto FooGallery Settings -> Advanced, and set the "Disable PRO Promotions" setting. Thank you for using FooGallery :)')
1387 } );
1388
1389 $('.foogallery-attachment-modal-toggle').on('click', function(e) {
1390 e.preventDefault();
1391 $(this).attr('disabled', 'disabled');
1392
1393 $.ajax({
1394 type: "POST",
1395 url: ajaxurl,
1396 data: {
1397 action: 'foogallery_attachment_modal_toggle',
1398 'nonce' : $(this).data('nonce')
1399 },
1400 success: function(data) {
1401 alert(data);
1402 //refresh page
1403 location.reload();
1404 }
1405 });
1406 } );
1407
1408 FOOGALLERY.initDropzone();
1409 };
1410
1411 FOOGALLERY.initMediaSelector = function() {
1412 $(document).on('click', '.foogallery-media-selector-choose', function(e){
1413 e.preventDefault();
1414
1415 var $el = $( this );
1416
1417 if ( $el.data( 'input' ) ) {
1418 // The input has been set by data-input="#my-input"
1419 FOOGALLERY.current_media_selector_input = $( $el.data('input') );
1420 } else {
1421 // Try and be smart and find the input.
1422 FOOGALLERY.current_media_selector_input = $el.parent().find( 'input[type="text"]')
1423 }
1424
1425 // If we do not have an input then get out!
1426 if ( FOOGALLERY.current_media_selector_input.length === 0 ) {
1427 return;
1428 }
1429
1430 var
1431 modalTitle = $el.data('modal-title') ? $el.data( 'modal-title' ) : 'Choose Image',
1432 modalButton = $el.data('modal-button') ? $el.data( 'modal-button' ) : 'Select Image',
1433 modalMultiple = $el.data('modal-multiple' ) ? $el.data( 'modal-multiple' ) === 'yes' : true;
1434 states = [
1435 // Main states.
1436 new wp.media.controller.Library( {
1437 library: wp.media.query(),
1438 multiple: modalMultiple,
1439 title: modalTitle,
1440 priority: 20,
1441 filterable: 'uploaded',
1442 } ),
1443 ];
1444
1445 // keep an array of modals, based off the modal title
1446
1447 //first check if modals have been initialized
1448 FOOGALLERY.current_media_selector_modals = FOOGALLERY.current_media_selector_modals || {};
1449
1450 // Check if we have a modal for this title
1451 if ( FOOGALLERY.current_media_selector_modals[modalTitle] ) {
1452 FOOGALLERY.current_media_selector_modals[modalTitle].open();
1453 return;
1454 }
1455
1456 // Create the media frame.
1457 FOOGALLERY.current_media_selector_modals[modalTitle] = wp.media.frames.downloadable_file = wp.media(
1458 {
1459 // Set the title of the modal.
1460 title: modalTitle,
1461 library: {
1462 type: '',
1463 },
1464 button: {
1465 text: modalButton,
1466 },
1467 multiple: modalMultiple,
1468 states: states,
1469 }
1470 );
1471
1472 // When an image is selected, run a callback.
1473 FOOGALLERY.current_media_selector_modals[modalTitle].on( 'select', function () {
1474 var file_path = '',
1475 selection = FOOGALLERY.current_media_selector_modals[modalTitle].state().get( 'selection' );
1476
1477 selection.map( function ( attachment ) {
1478 attachment = attachment.toJSON();
1479 if ( attachment.url ) {
1480 file_path = attachment.url;
1481 }
1482 } );
1483
1484 FOOGALLERY.current_media_selector_input.val( file_path ).trigger( 'change' );
1485 } );
1486
1487 // Finally, open the modal.
1488 FOOGALLERY.current_media_selector_modals[modalTitle].open();
1489 });
1490
1491 $(document).on('click', '.foogallery-media-selector-clear', function(e){
1492 e.preventDefault();
1493
1494 var $el = $( this );
1495
1496 if ( $el.data( 'input' ) ) {
1497 // The input has been set by data-input="#my-input"
1498 FOOGALLERY.current_media_selector_input = $( $el.data('input') );
1499 } else {
1500 // Try and be smart and find the input.
1501 FOOGALLERY.current_media_selector_input = $el.parent().find( 'input[type="text"]')
1502 }
1503
1504 // If we do not have an input then get out!
1505 if ( FOOGALLERY.current_media_selector_input.length === 0 ) {
1506 return;
1507 }
1508
1509 // Clear the input.
1510 FOOGALLERY.current_media_selector_input.val( '' ).trigger( 'change' );
1511 });
1512 };
1513
1514 FOOGALLERY.initAttachmentModal = function() {
1515 //close attachments modal
1516 jQuery('#foogallery-image-edit-modal .media-modal-close').on('click', function() {
1517 var $content = jQuery('#foogallery-image-edit-modal'),
1518 $wrapper = jQuery('#foogallery-image-edit-modal .media-frame-content .attachment-details'),
1519 $loader = jQuery('#foogallery-image-edit-modal .media-frame-content .spinner');
1520
1521 $content.hide();
1522 $wrapper.addClass('not-loaded');
1523 $loader.addClass('is-active');
1524 });
1525
1526 // Attachment taxonomy button toggles
1527 $(document).on('click', '#foogallery-panel-taxonomies ul a', function(e){
1528 var term_id = parseInt( $(this).data('term-id') ),
1529 $ul = $(this).parents('ul').first();
1530 if ( !isNaN(term_id) && term_id > 0 ) {
1531 $(this).toggleClass('button-primary');
1532 var terms = [];
1533 $ul.find('a.button-primary').each(function () {
1534 term_id = $(this).data('term-id');
1535 terms.push(term_id);
1536 });
1537 var terms_str = terms.toString();
1538 $('#foogallery_attachment_taxonomy_' + $ul.data('taxonomy') + '_selected').val(terms_str);
1539 } else {
1540 var action = $(this).data('action');
1541 if ( action === 'add' ) {
1542 $ul.find('.foogallery_attachment_taxonomy_add').toggle();
1543 $ul.find('.taxonomy_add input').focus();
1544 } else if ( action === 'save' || action === 'cancel' ){
1545 var term_to_add = $ul.find('input.foogallery_attachment_taxonomy_add').val();
1546 if ( term_to_add && term_to_add.length > 0 && action === 'save' ) {
1547 var nonce = $('#foogallery-panel-taxonomies').data('nonce');
1548 $.ajax({
1549 type: "POST",
1550 url: ajaxurl,
1551 data: {
1552 'img_id': $('.foogallery-image-edit-main').data('img_id'),
1553 'nonce': nonce,
1554 'action': 'foogallery_attachment_modal_taxonomy_add',
1555 'taxonomy' : $ul.data('taxonomy'),
1556 'term': term_to_add
1557 },
1558 cache: false,
1559 success: function(res) {
1560 var html = '<li><a href="javascript:void(0);" class="button button-small recently-added" data-term-id="' + res.data.id + '">' + res.data.name + '</a></li>';
1561 $ul.find('.taxonomy_add').before(html);
1562 $ul.find('a.recently-added').removeClass('recently-added').trigger('click');
1563 $ul.find('input.foogallery_attachment_taxonomy_add').val('');
1564 $ul.find('.foogallery_attachment_taxonomy_add').toggle();
1565 }
1566 });
1567 } else {
1568 $ul.find('input.foogallery_attachment_taxonomy_add').val('');
1569 $ul.find('.foogallery_attachment_taxonomy_add').toggle();
1570 }
1571 } else if ( action === 'remove' ) {
1572 // Deselect all taxonomies
1573 $ul.find('a.button.button-small').removeClass('button-primary');
1574 $('#foogallery_attachment_taxonomy_' + $ul.data('taxonomy') + '_selected').val('');
1575 }
1576 }
1577 });
1578
1579 $(document).on('click', '#attachments-data-save-btn', function(e){
1580 e.preventDefault();
1581 FOOGALLERY.saveAttachmentModal();
1582 });
1583
1584 $(document).on('click', '.copy-attachment-file-url', function(e) {
1585 $('#attachments-foogallery-file-url').select();
1586 document.execCommand('copy');
1587 });
1588
1589 $(document).on('click', '#foogallery-image-edit-modal .foogallery-img-modal-tab-wrapper', function(e) {
1590 var panel = '#' + $(this).data('tab_id');
1591 $('#foogallery-image-edit-modal .tab-panel').removeClass('active');
1592 $(panel).addClass('active');
1593 $('#foogallery-image-edit-modal').data( 'current_tab', $(this).data('tab_id') );
1594 });
1595
1596 $(document).on('click', '#foogallery_clear_img_thumb_cache', function(e) {
1597 e.preventDefault();
1598
1599 $('#foogallery_clear_img_thumb_cache_spinner').addClass('is-active');
1600 var data = 'action=foogallery_clear_attachment_thumb_cache' +
1601 '&attachment_id=' + $('.foogallery-image-edit-main').data('img_id') +
1602 '&foogallery_clear_attachment_thumb_cache_nonce=' + $('#foogallery_clear_attachment_thumb_cache_nonce').val() +
1603 '&_wp_http_referer=' + encodeURIComponent($('input[name="_wp_http_referer"]').val());
1604
1605 $.ajax({
1606 type: "POST",
1607 url: ajaxurl,
1608 data: data,
1609 success: function(data) {
1610 var message = data && data.data && data.data.message ? data.data.message : data;
1611 alert(message);
1612 $('#foogallery_clear_img_thumb_cache_spinner').removeClass('is-active');
1613 },
1614 error: function(xhr) {
1615 var message = xhr.responseJSON && xhr.responseJSON.data && xhr.responseJSON.data.message ? xhr.responseJSON.data.message : 'There was a problem clearing the thumbnail cache.';
1616 alert(message);
1617 $('#foogallery_clear_img_thumb_cache_spinner').removeClass('is-active');
1618 }
1619 });
1620 });
1621
1622 $(document).on('click', '#foogallery-image-edit-modal .edit-media-header button:not(.media-modal-close)', function(e) {
1623 e.preventDefault();
1624
1625 $(this).attr( 'disabled', 'disabled' );
1626 var selected_attachment_id = parseInt( $(this).data('attachment') ),
1627 autosave = jQuery('#attachment-modal-autosave').is(':checked');
1628 if ( selected_attachment_id > 0 ) {
1629
1630 // Check if we must save the data first!
1631 if ( autosave ) {
1632 FOOGALLERY.saveAttachmentModal(function () {
1633 $(this).prop( 'disabled', false );
1634 FOOGALLERY.openAttachmentModal(selected_attachment_id);
1635 });
1636 } else {
1637 $(this).prop( 'disabled', false );
1638 FOOGALLERY.openAttachmentModal(selected_attachment_id);
1639 }
1640 }
1641 });
1642 };
1643
1644 FOOGALLERY.saveAttachmentModal = function(callback) {
1645 var data = $('#foogallery_attachment_modal_save_form').serialize(),
1646 $spinner = $('.foogallery-image-edit-footer .spinner');
1647 $spinner.addClass('is-active');
1648 $.ajax({
1649 type: "POST",
1650 url: ajaxurl,
1651 data: data,
1652 cache: false,
1653 success: function(res) {
1654 $spinner.removeClass('is-active');
1655 if ( $.isFunction(callback) ) {
1656 callback();
1657 }
1658 }
1659 });
1660 };
1661
1662 FOOGALLERY.openAttachmentModal = function(img_id) {
1663 var $content = jQuery('#foogallery-image-edit-modal'),
1664 $wrapper = jQuery('#foogallery-image-edit-modal .media-frame-content .attachment-details'),
1665 $loader = jQuery('#foogallery-image-edit-modal .media-frame-content .spinner'),
1666 nonce = $content.data('nonce'),
1667 gallery_id = $content.data('gallery_id'),
1668 current_tab = $content.data('current_tab');
1669
1670 $content.show();
1671 $wrapper.addClass('not-loaded').html('<div class="spinner is-active"></div>');
1672 $wrapper.css({'grid-template-columns': '1fr'});
1673 $loader.addClass('is-active');
1674
1675 jQuery.ajax({
1676 type: "POST",
1677 url: ajaxurl,
1678 data: {
1679 'img_id': img_id,
1680 'gallery_id': gallery_id,
1681 'override_attachments': $('#foogallery_attachments').val(),
1682 'current_tab': current_tab,
1683 'nonce': nonce,
1684 'action': 'foogallery_attachment_modal_open'
1685 },
1686 success: function(json) {
1687 jQuery('#foogallery-image-edit-modal .edit-media-header button.left')
1688 .attr('disabled', !json.prev_slide)
1689 .data('attachment', json.prev_img_id);
1690 jQuery('#foogallery-image-edit-modal .edit-media-header button.right')
1691 .attr('disabled', !json.next_slide)
1692 .data('attachment', json.next_img_id);
1693
1694 if ( json.override_thumbnail ) {
1695 jQuery('#foogallery-image-edit-modal .tab-panels .settings span.setting.override-thumbnail').addClass('is-override-thumbnail');
1696 jQuery('#foogallery-image-edit-modal .tab-panels .settings span.setting.override-thumbnail-preview').addClass('is-override-thumbnail');
1697 }
1698
1699 jQuery('#foogallery-image-edit-modal .media-modal-content .edit-attachment-frame .media-frame-content .attachment-details').html(json.html);
1700
1701 if ( json.current_tab ) {
1702 jQuery('.foogallery-img-modal-tab-wrapper[data-tab_id="' + json.current_tab + '"] input').trigger('click');
1703 }
1704
1705 $wrapper.removeClass('not-loaded');
1706 $wrapper.css({'grid-template-columns': '1fr 2fr'});
1707 $loader.removeClass('is-active');
1708 },
1709 });
1710 };
1711
1712 FOOGALLERY.initDropzone = function() {
1713 const $metaBox = $('#foogallery_items .inside');
1714
1715 if (!$metaBox.length || typeof wp === 'undefined' || !wp.Uploader) {
1716 return;
1717 }
1718
1719 if (FOOGALLERY.dropzoneInitialized) {
1720 return;
1721 }
1722
1723 let $dropZone = $metaBox.find('.foogallery-dropzone');
1724 if (!$dropZone.length) {
1725 const dropzoneMessage = (FOOGALLERY.il8n && FOOGALLERY.il8n.dropzone_message) || 'Drop images here to upload';
1726
1727 $dropZone = $(
1728 '<div class="foogallery-dropzone">' +
1729 '<p class="message"></p>' +
1730 '<div class="upload-progress"></div>' +
1731 '</div>'
1732 );
1733 $metaBox.prepend($dropZone);
1734 $dropZone.find('.message').text(dropzoneMessage);
1735 }
1736
1737 FOOGALLERY.dropzoneInitialized = true;
1738
1739 const $progress = $dropZone.find('.upload-progress').css('width', '0').hide();
1740 const $uploadButton = $metaBox.find('.foogallery-upload-direct');
1741
1742 let dragDepth = 0;
1743 let uploadActive = false;
1744
1745 const isFileDrag = function(event) {
1746 const dt = event && event.originalEvent && event.originalEvent.dataTransfer;
1747
1748 if (!dt || !dt.types) {
1749 return false;
1750 }
1751
1752 if (typeof dt.types.indexOf === 'function') {
1753 return dt.types.indexOf('Files') !== -1;
1754 }
1755
1756 if (typeof dt.types.contains === 'function') {
1757 return dt.types.contains('Files');
1758 }
1759
1760 return dt.types === 'Files';
1761 };
1762
1763 $(document)
1764 .on('dragenter.foogalleryDropzone', function(event) {
1765 if (!isFileDrag(event)) {
1766 return;
1767 }
1768
1769 dragDepth++;
1770 $dropZone.addClass('visible');
1771 })
1772 .on('dragleave.foogalleryDropzone', function(event) {
1773 if (!isFileDrag(event)) {
1774 return;
1775 }
1776
1777 dragDepth = Math.max(dragDepth - 1, 0);
1778 if (dragDepth === 0) {
1779 if (uploadActive) {
1780 $dropZone.removeClass('drag-over');
1781 } else {
1782 $dropZone.removeClass('visible drag-over');
1783 }
1784 }
1785 })
1786 .on('dragover.foogalleryDropzone', function(event) {
1787 if (!isFileDrag(event)) {
1788 return;
1789 }
1790
1791 event.preventDefault();
1792 })
1793 .on('drop.foogalleryDropzone', function(event) {
1794 if (!isFileDrag(event)) {
1795 return;
1796 }
1797
1798 event.preventDefault();
1799
1800 const isInsideDropZone = $dropZone.is(event.target) || $.contains($dropZone[0], event.target);
1801
1802 dragDepth = 0;
1803 $dropZone.removeClass('drag-over');
1804
1805 if (!isInsideDropZone) {
1806 uploadActive = false;
1807 $dropZone.removeClass('visible');
1808 } else {
1809 uploadActive = true;
1810 }
1811 });
1812
1813 $dropZone
1814 .on('dropzone:enter.foogalleryDropzone', function() {
1815 $dropZone.addClass('visible drag-over');
1816 })
1817 .on('dropzone:leave.foogalleryDropzone', function() {
1818 if (dragDepth === 0) {
1819 $dropZone.removeClass('visible drag-over');
1820 }
1821 });
1822
1823 const finalizeUI = function() {
1824 setTimeout(function() {
1825 $dropZone.removeClass('drag-over visible');
1826 dragDepth = 0;
1827 uploadActive = false;
1828
1829 $progress.fadeOut(200, function() {
1830 $(this).css('width', '0');
1831 });
1832 }, 400);
1833 };
1834
1835 try {
1836 const uploaderSettings = {
1837 container: $dropZone,
1838 dropzone: $dropZone,
1839 params: {
1840 post_id: $('#post_ID').val()
1841 },
1842 added: function() {
1843 uploadActive = true;
1844 $dropZone.addClass('visible');
1845 $progress.show().css('width', '0');
1846 },
1847 progress: function(attachment) {
1848 let percent = 0;
1849
1850 if (this.uploader && this.uploader.total && typeof this.uploader.total.percent === 'number') {
1851 percent = this.uploader.total.percent;
1852 } else if (attachment && attachment.get) {
1853 percent = attachment.get('percent') || 0;
1854 }
1855
1856 $progress.css('width', percent + '%');
1857 },
1858 success: function(attachment) {
1859 const data = attachment && attachment.toJSON ? attachment.toJSON() : attachment;
1860
1861 if (!data || !data.id) {
1862 return;
1863 }
1864
1865 const subtype = data.subtype || (data.mime ? data.mime.split('/')[1] : null);
1866
1867 FOOGALLERY.addAttachmentToGalleryList({
1868 id: data.id,
1869 src: (data.sizes && data.sizes.thumbnail && data.sizes.thumbnail.url) ||
1870 data.icon ||
1871 data.url ||
1872 '',
1873 subtype: subtype
1874 });
1875
1876 if (!wp.Uploader.queue || !wp.Uploader.queue.length) {
1877 finalizeUI();
1878 }
1879 },
1880 error: function(message, responseData, file) {
1881 console.error('FooGallery uploader error:', message || responseData, file);
1882
1883 if (!wp.Uploader.queue || !wp.Uploader.queue.length) {
1884 finalizeUI();
1885 }
1886 }
1887 };
1888
1889 if ($uploadButton.length) {
1890 uploaderSettings.browser = $uploadButton;
1891 }
1892
1893 const uploader = new wp.Uploader(uploaderSettings);
1894
1895 FOOGALLERY.dropzoneUploader = uploader;
1896 } catch (error) {
1897 console.error('FooGallery failed to initialize dropzone uploader', error);
1898 }
1899 };
1900
1901 // $(document).ready(function () {
1902
1903 // FOOGALLERY.initAttachments();
1904
1905 // FOOGALLERY.galleryTemplateChanged(false);
1906 // });
1907
1908 }(window.FOOGALLERY = window.FOOGALLERY || {}, jQuery));
1909
1910 FooGallery.utils.ready(function ($) {
1911 if ( $('#foogallery_attachments').length > 0 ) {
1912 FOOGALLERY.adminReady();
1913 }
1914 });
1915