admin-foogallery-attachment-autosave.js
1 day ago
admin-foogallery-divi.js
1 day ago
admin-foogallery-edit.js
1 day ago
admin-foogallery-editor.js
1 day ago
admin-foogallery-elementor.js
1 day ago
admin-page-foogallery-extensions-modal.js
1 day ago
admin-page-foogallery-extensions.js
1 day ago
admin-page-foogallery-settings.js
1 day ago
admin-tinymce.js
1 day ago
admin-uploader.js
1 day ago
foogallery-command-palette.js
1 day ago
foogallery.admin.datasources.js
1 day ago
foogallery.admin.min.js
1 day ago
foogallery.admin.template.js
1 day ago
admin-foogallery-elementor.js
136 lines
| 1 | ( function( $ ) { |
| 2 | /** |
| 3 | * @param $scope The Widget wrapper element as a jQuery element |
| 4 | * @param $ The jQuery alias |
| 5 | */ |
| 6 | var FooGalleryWidgetHandler = function( $scope, $ ) { |
| 7 | if ( FooGallery ) { |
| 8 | const $gallery = $scope.find('.foogallery'); |
| 9 | const instance = $gallery.data(FooGallery.DATA_TEMPLATE); |
| 10 | if ( instance instanceof FooGallery.Template ) { |
| 11 | return; |
| 12 | } |
| 13 | $gallery.foogallery(FooGallery.autoDefaults); |
| 14 | } |
| 15 | }; |
| 16 | |
| 17 | // Make sure you run this code under Elementor. |
| 18 | $( window ).on( 'elementor/frontend/init', function() { |
| 19 | elementorFrontend.hooks.addAction( 'frontend/element_ready/foogallery.default', FooGalleryWidgetHandler ); |
| 20 | } ); |
| 21 | |
| 22 | // Helper: pull gallery_id from whatever model shape Elementor gives us. |
| 23 | function getGalleryIdFromModel(model) { |
| 24 | if (!model) return null; |
| 25 | |
| 26 | // Elementor >=3.x |
| 27 | if (typeof model.getSetting === 'function') { |
| 28 | return model.getSetting('gallery_id'); |
| 29 | } |
| 30 | |
| 31 | // Fallbacks for older shapes |
| 32 | const settings = model.get && model.get('settings'); |
| 33 | if (settings && typeof settings.get === 'function') return settings.get('gallery_id'); |
| 34 | return settings && settings.gallery_id ? settings.gallery_id : null; |
| 35 | } |
| 36 | |
| 37 | function openEdit(galleryId) { |
| 38 | if (!galleryId) { |
| 39 | return; |
| 40 | } |
| 41 | window.open(FooGalleryElementor.editUrlBase + galleryId, '_blank'); |
| 42 | } |
| 43 | |
| 44 | function openCreate() { |
| 45 | window.open(FooGalleryElementor.newUrl, '_blank'); |
| 46 | } |
| 47 | |
| 48 | function refreshGalleries(panel) { |
| 49 | if (typeof FooGalleryElementor === 'undefined' || !FooGalleryElementor.ajaxUrl) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | const previousValue = (window.elementor?.getPanelView?.()?.getCurrentPageView?.()?.model?.getSetting?.('gallery_id')) ?? ''; |
| 54 | const controlView = window.elementor?.getPanelView?.()?.getCurrentPageView?.().getControlViewByName('gallery_id'); |
| 55 | |
| 56 | if (!controlView) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | const $control = controlView.$el; |
| 61 | const $select = $control.find('select'); |
| 62 | |
| 63 | $control.addClass('foogallery-refreshing'); |
| 64 | |
| 65 | $.ajax({ |
| 66 | url: FooGalleryElementor.ajaxUrl, |
| 67 | method: 'POST', |
| 68 | dataType: 'json', |
| 69 | data: { |
| 70 | action: 'foogallery_elementor_refresh_galleries', |
| 71 | nonce: FooGalleryElementor.refreshNonce |
| 72 | } |
| 73 | }).done(function(response) { |
| 74 | if (!response || !response.success || !response.data || !response.data.options) { |
| 75 | console.error('FooGallery Elementor: refresh response invalid.', response); |
| 76 | if (FooGalleryElementor.refreshError) { |
| 77 | elementor.notifications?.showToast({ message: FooGalleryElementor.refreshError, type: 'error' }); |
| 78 | } |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | const options = response.data.options; |
| 83 | controlView.model.set('options', options); |
| 84 | |
| 85 | if ($select.length) { |
| 86 | $select.empty(); |
| 87 | |
| 88 | Object.keys(options).forEach(function(value) { |
| 89 | const label = options[value]; |
| 90 | $select.append($('<option/>').attr('value', value).text(label)); |
| 91 | }); |
| 92 | |
| 93 | const hasPrevious = previousValue && Object.prototype.hasOwnProperty.call(options, previousValue); |
| 94 | const valueToSet = hasPrevious ? previousValue : ''; |
| 95 | |
| 96 | if (typeof controlView.setValue === 'function') { |
| 97 | controlView.setValue(valueToSet); |
| 98 | } else { |
| 99 | $select.val(valueToSet).trigger('change'); |
| 100 | } |
| 101 | } |
| 102 | }).fail(function(jqXHR, textStatus) { |
| 103 | console.error('FooGallery Elementor: refresh failed.', textStatus); |
| 104 | if (FooGalleryElementor.refreshError) { |
| 105 | elementor.notifications?.showToast({ message: FooGalleryElementor.refreshError, type: 'error' }); |
| 106 | } |
| 107 | }).always(function() { |
| 108 | $control.removeClass('foogallery-refreshing'); |
| 109 | }); |
| 110 | } |
| 111 | |
| 112 | // Wait until the editor is ready, then bind listeners. |
| 113 | $( window ).on( 'elementor/frontend/init', function() { |
| 114 | const channel = elementor.channels.editor; |
| 115 | |
| 116 | // Fired by your BUTTON controls' "event" property. |
| 117 | channel.on('foogallery:edit', function (panel, data) { |
| 118 | // Try to get the current element model from event payload, then fallbacks. |
| 119 | const galleryId = (window.elementor?.getPanelView?.()?.getCurrentPageView?.()?.model?.getSetting?.('gallery_id')) ?? null; |
| 120 | // if galleryId is not null |
| 121 | if ( galleryId ) { |
| 122 | openEdit(galleryId); |
| 123 | } |
| 124 | }); |
| 125 | |
| 126 | channel.on('foogallery:add', function () { |
| 127 | openCreate(); |
| 128 | }); |
| 129 | |
| 130 | channel.on('foogallery:refresh', function (panel) { |
| 131 | refreshGalleries(panel); |
| 132 | }); |
| 133 | }); |
| 134 | |
| 135 | } )( jQuery ); |
| 136 |