PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / elementor-elements / classes / includes / js / live-editor.js

live-editor.js in WP Directory Kit 1.5.9, at elementor-elements/classes/includes/js/live-editor.js

263 lines 9.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 var $ = jQuery;
3
4 function wdkHandleLiveEditor() {
5
6 // close model events.
7 $('.eicon-close').on('click', wdkCloseModal);
8
9 $('#pa-insert-live-temp').on('click', function () {
10 $('body').attr('data-pa-liveeditor-load', 'true');
11 wdkCloseModal(true);
12 });
13
14 $(document).on('click', '.wdk-live-editor-iframe-modal', function (e) {
15 if ($(e.target).closest(".dialog-lightbox-widget-content").length < 1) {
16 wdkCloseModal();
17 }
18 });
19
20 // resize model event.
21 $('.wdk-live-editor-iframe-modal .wdk-expand').on('click', function () {
22
23 if ($(this).find(' > i').hasClass('eicon-frame-expand')) {
24 $(this).find('i.eicon-frame-expand').removeClass('eicon-frame-expand').addClass('eicon-frame-minimize').attr('title', 'Minimize');
25 $('.wdk-live-editor-iframe-modal').addClass('wdk-modal-expanded');
26
27 } else {
28 wdkMinimizeModal(this);
29 }
30 });
31
32 elementor.channels.editor.on('wdkCreateLiveTemp', function (e) {
33
34 console.log('wdkCreateLiveTemp');
35 var
36 $modalContainer = $('.wdk-live-editor-iframe-modal'),
37 paIframe = $modalContainer.find("#pa-live-editor-control-iframe"),
38 $lightboxLoading = $modalContainer.find(".dialog-lightbox-loading"),
39 lightboxType = $modalContainer.find(".dialog-type-lightbox"),
40 tempSelectorId = e.model.attributes.name.split('_live')[0],
41 settingsToChange = {};
42
43 // from e.model.attributes.button_type ("default papro-btn-block for-custom_layout_live_grid")
44 var buttonTypeClass = e.model.attributes.button_type || '';
45 var match = buttonTypeClass.match(/for-([^\s]*)/);
46 var liveTempKey = match ? match[1] : 'live_temp_content';
47
48 var layoutId = jQuery('[data-setting="'+liveTempKey+'"]').val() || '';
49
50 // show modal.
51 lightboxType.show();
52 $modalContainer.show();
53 $lightboxLoading.show();
54 paIframe.contents().find("#elementor-loading").show();
55 paIframe.css("z-index", "-1");
56
57 $.ajax({
58 type: 'POST',
59 url: liveEditor.ajaxurl,
60 dataType: 'JSON',
61 data: {
62 action: 'wdk_handle_live_editor',
63 security: liveEditor.nonce,
64 post_id: layoutId,
65 },
66 success: function (res) {
67
68 paIframe.attr("src", res.data.url);
69 paIframe.attr("data-wdk-temp-id", res.data.id);
70
71 console.log(res.data);
72 $('#wdk-live-temp-title').val(res.data.title);
73
74 paIframe.on("load", function () {
75 $lightboxLoading.hide();
76 paIframe.show();
77 //$modalContainer.find('.wdk-live-editor-title').css('display', 'flex');
78 paIframe.contents().find("#elementor-loading").hide();
79 paIframe.css("z-index", "1");
80 });
81
82 clearInterval(window.paLiveEditorInterval);
83
84 window.paLiveEditorInterval = setInterval(function () {
85 console.log('paLiveEditorInterval');
86 var loadTemplate = $('body').attr('data-pa-liveeditor-load');
87
88 if ('true' === loadTemplate) {
89 $('body').attr('data-pa-liveeditor-load', 'false');
90
91 settingsToChange = {};
92 settingsToChange[liveTempKey] = res.data.id;
93 $e.run('document/elements/settings', { container: e.container, settings: settingsToChange, options: { external: !0 } });
94
95 jQuery('[data-setting="'+liveTempKey+'"]').closest('.elementor-control').removeClass("control-hidden");
96
97 var tempTitle = $('#wdk-live-temp-title').val();
98 if (tempTitle && tempTitle !== res.data.title) {
99 wdkUpdateTemplateTitle(tempTitle, res.data.id);
100 }
101 }
102 }, 1000);
103 },
104 error: function (err) {
105 console.log(err);
106 }
107 });
108 });
109 }
110
111 /**
112 * Helper Funcitons.
113 */
114
115 function wdkCheckTempValidity(tempID, tempType) {
116
117 if ('' !== tempID) {
118 $.ajax({
119 type: 'POST',
120 url: liveEditor.ajaxurl,
121 dataType: 'JSON',
122 data: {
123 action: 'check_temp_validity',
124 security: liveEditor.nonce,
125 templateID: tempID,
126 tempType: tempType
127 },
128 success: function (res) {
129 console.log(res.data);
130 },
131 error: function (err) {
132 console.log(err);
133 }
134 });
135 }
136 }
137
138 function wdkMinimizeModal(_this) {
139
140 $(_this).find('i.eicon-frame-minimize').removeClass('eicon-frame-minimize').addClass('eicon-frame-expand').attr('title', 'Expand');
141 $('.wdk-live-editor-iframe-modal').removeClass('wdk-modal-expanded');
142 }
143
144 function wdkUpdateTemplateTitle(title, id) {
145
146 $.ajax({
147 type: 'POST',
148 url: liveEditor.ajaxurl,
149 dataType: 'JSON',
150 data: {
151 action: 'update_template_title',
152 security: liveEditor.nonce,
153 title: title,
154 id: id
155 },
156 success: function (res) {
157 console.log('Template Title Updated.');
158 },
159 error: function (err) {
160 console.log(err);
161 }
162 });
163 }
164
165 function wdkCloseModal(inserted = false) {
166
167 $('.wdk-live-editor-iframe-modal').css('display', 'none');
168
169 $(".wdk-live-temp-title input").attr('disabled', 'true');
170
171 wdkMinimizeModal($('.wdk-live-editor-iframe-modal .wdk-expand'));
172
173 if (!inserted) {
174 var tempId = $(".wdk-live-editor-iframe-modal #pa-live-editor-control-iframe").attr('data-wdk-temp-id'),
175 tempType = $(".wdk-live-editor-iframe-modal #pa-live-editor-control-iframe").attr('data-wdk-temp-type');
176
177 if (undefined !== tempId && '' !== tempId) {
178 wdkCheckTempValidity(tempId, tempType);
179 }
180 }
181
182 // reset temp id/src attribute.
183 $(".wdk-live-editor-iframe-modal #pa-live-editor-control-iframe").attr({
184 'data-wdk-temp-id': '',
185 'data-wdk-temp-type': '',
186 'src': ''
187 });
188 }
189
190 function wdkCheckLiveTemplateControl() {
191
192 setTimeout(function () {
193
194 $(".wdk-live-temp-title input").each(function (index, input) {
195 $(input).attr('disabled', 'true');
196 });
197
198 $('.wdk-cf-form-id input').attr('disabled', 'true');
199
200 }, 500);
201 }
202
203 // Update button text based on template selection
204 function wdkUpdateTemplateButtonText() {
205 elementor.channels.editor.on('element:settings:changed', function(model, key, value) {
206 if (key === 'wdk_carousel_repeater_item') {
207 var buttonText = value && value !== '' ?
208 'Edit Selected Template' :
209 'Create New Template';
210
211 // Update button text - try different selectors
212 $('.wdk-carousel-repeater-item-live button, [data-setting="wdk_carousel_repeater_item_live"] button').text(buttonText);
213 }
214 });
215 }
216
217 // Initialize button text on load
218 function wdkInitializeTemplateButton() {
219 setTimeout(function() {
220 $('[data-setting="wdk_carousel_repeater_item_live"] button').each(function() {
221 var $button = $(this);
222 var $control = $button.closest('.elementor-control');
223 var templateSelect = $control.siblings('[data-setting="wdk_carousel_repeater_item"]').find('select, input');
224
225 if (templateSelect.length && templateSelect.val() && templateSelect.val() !== '') {
226 $button.text('Edit Selected Template');
227 } else {
228 $button.text('Create New Template');
229 }
230 });
231 }, 100);
232 }
233
234 elementor.channels.editor.on('section:activated', function() {
235 wdkCheckLiveTemplateControl();
236 wdkInitializeTemplateButton();
237 });
238
239 $(window).on('elementor:init', function() {
240 wdkHandleLiveEditor();
241 wdkUpdateTemplateButtonText();
242 });
243
244
245 function checkLiveTemplateControl() {
246
247 setTimeout(function () {
248
249 $(".wdk-live-temp-title input").each(function (index, input) {
250 $(input).attr('disabled', 'true');
251 if ('' != $(input).val()) {
252 $(input).closest(".wdk-live-temp-title").removeClass("control-hidden");
253 }
254 });
255
256 $('.wdk-cf-form-id input').attr('disabled', 'true');
257
258 }, 500);
259 }
260
261 elementor.channels.editor.on('section:activated', checkLiveTemplateControl);
262
263 })(jQuery);