PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.2.1
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.2.1
4.2.5 4.2.4 trunk 3.7.10 3.7.11 3.7.12 3.7.13 3.7.14 3.7.2 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8 3.8.1 3.8.10 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.8.9.1 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.5.1 4.0.6 4.0.6.1 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2.0 4.2.1 4.2.2 4.2.3
widget-options / assets / js / settings.js
widget-options / assets / js Last commit date
bootstrap-multiselect.min.js 3 months ago jquery.liveFilter.js 3 months ago jquery.liveFilter.min.js 3 months ago jquery.widgetopts.beaver.js 3 months ago jquery.widgetopts.beaver.min.js 3 months ago select2-settings.js 3 months ago select2-settings.min.js 3 months ago select2.min.js 3 months ago settings.js 3 months ago settings.min.js 3 months ago widgetopts.global.js 3 months ago widgetopts.migration.js 3 months ago widgetopts.resize.js 3 months ago widgets.js 3 months ago widgets.min.js 3 months ago wpWidgetOpts.js 3 months ago wpWidgetOpts.min.js 3 months ago
settings.js
370 lines
1 "use strict";
2
3 var widgetoptsSettingsModule = {
4 init: function() {
5 var self = this;
6 jQuery( '.widgetopts-module-settings-container' ).hide();
7
8 self.bindEvents();
9 },
10
11 bindEvents: function() {
12 var self = this;
13 var $wpcontent = jQuery( '#wpcontent' );
14
15 $wpcontent.on( 'click', '.widgetopts-toggle-settings, .widgetopts-module-settings-cancel', self.openModal );
16 $wpcontent.on( 'click', '.widgetopts-close-modal, .widgetopts-modal-background', self.closeModal );
17 $wpcontent.on( 'keyup', self.closeModal );
18 $wpcontent.on( 'click', '.widgetopts-toggle-activation', self.moduleToggle );
19 $wpcontent.on( 'click', '.widgetopts-module-settings-save', self.saveSettings );
20 // $wpcontent.on( 'click', '.widgetopts-license-button', self.licenseHandler );
21 $wpcontent.on( 'click', '.opts-add-class-btn', self.toggleCustomClass );
22 $wpcontent.on( 'click', '.opts-remove-class-btn', self.removeCustomClass );
23 $wpcontent.on( 'click', '.widgetopts-delete-cache', self.clearWidgetCache );
24 $wpcontent.on( 'click', '.widgetopts-license_deactivate', self.deactivationHandler );
25
26 },
27
28 openModal: function( e ) {
29 e.preventDefault();
30
31 var $container = jQuery(this).parents( '.widgetopts-module-card' ).find( '.widgetopts-module-settings-container' ),
32 $modalBg = jQuery( '.widgetopts-modal-background' );
33
34 $modalBg.show();
35 $container
36 .show();
37
38 jQuery( 'body' ).addClass( 'widgetopts-modal-open' );
39 },
40
41 closeModal: function( e ) {
42 if ( 'undefined' !== typeof e ) {
43 e.preventDefault();
44
45 // For keyup events, only process esc
46 if ( 'keyup' === e.type && 27 !== e.which ) {
47 return;
48 }
49 }
50
51 jQuery( '.widgetopts-modal-background' ).hide();
52 jQuery( '.widgetopts-module-settings-container' ).hide();
53 jQuery( 'body' ).removeClass( 'widgetopts-modal-open' );
54 },
55
56 moduleToggle: function( e ) {
57 e.preventDefault();
58 e.stopPropagation();
59
60 var $button = jQuery(this),
61 $card = $button.parents( '.widgetopts-module-card' ),
62 $buttons = $card.find( '.widgetopts-toggle-activation' ),
63 module = $card.attr( 'data-module-id' );
64
65 $buttons.prop( 'disabled', true );
66
67 if ( $button.html() == widgetopts.translation.activate ) {
68 var method = 'activate';
69 } else {
70 var method = 'deactivate';
71 }
72
73 widgetoptsSettingsModule.ajaxRequest( module, method, {}, widgetoptsSettingsModule.moduleCallback );
74 },
75
76 moduleCallback: function( results ) {
77 var module = results.module;
78 var method = results.method;
79
80 var $card = jQuery( '#widgetopts-module-card-' + module ),
81 $buttons = $card.find( '.widgetopts-toggle-activation' );
82
83 if ( results.errors.length > 0 ) {
84 $buttons
85 .html( widgetopts.translations.error )
86 .addClass( 'button-secondary' )
87 .removeClass( 'button-primary' );
88
89 setTimeout( function() {
90 widgetoptsSettingsModule.isModuleActive( module );
91 }, 1000 );
92
93 return;
94 }
95
96 if ( 'activate' === method ) {
97 $buttons
98 .html( widgetopts.translation.deactivate )
99 .addClass( 'button-secondary' )
100 .removeClass( 'button-primary' )
101 .prop( 'disabled', false );
102
103 $card
104 .addClass( 'widgetopts-module-type-enabled' )
105 .removeClass( 'widgetopts-module-type-disabled' );
106
107 if( $card.hasClass('no-settings') ) {
108 var newToggleSettingsLabel = widgetopts.translation.show_description;
109 } else {
110 var newToggleSettingsLabel = widgetopts.translation.show_settings;
111 }
112
113 // Show Manage Snippets button for Display Logic module
114 if ( 'logic' === module ) {
115 $card.find( '.widgetopts-manage-snippets-btn' ).show();
116 $card.find( '.widgetopts-migrate-btn' ).show();
117 }
118
119 } else {
120 $buttons
121 .html( widgetopts.translation.activate )
122 .addClass( 'button-primary' )
123 .removeClass( 'button-secondary' )
124 .prop( 'disabled', false );
125
126 $card
127 .addClass( 'widgetopts-module-type-disabled' )
128 .removeClass( 'widgetopts-module-type-enabled' );
129
130 var newToggleSettingsLabel = widgetopts.translation.show_description;
131
132 // Hide Manage Snippets button for Display Logic module
133 if ( 'logic' === module ) {
134 $card.find( '.widgetopts-manage-snippets-btn' ).hide();
135 $card.find( '.widgetopts-migrate-btn' ).hide();
136 }
137 }
138
139 // if( !$card.hasClass('widgetopts-module-card-no-settings') ){
140 $card.find( '.widgetopts-toggle-settings' ).html( newToggleSettingsLabel );
141 // }
142 },
143
144 saveSettings: function( e ) {
145 e.preventDefault();
146
147 var $button = jQuery(this);
148
149 if ( $button.hasClass( 'widgetopts-module-settings-save' ) ) {
150 var module = $button.parents( '.widgetopts-module-card' ).attr( 'data-module-id' );
151 } else {
152 var module = '';
153 }
154
155 $button.prop( 'disabled', true );
156
157 var data = {
158 '--widgetopts-form-serialized-data': jQuery( '#widgetopts-module-settings-form' ).serialize()
159 };
160
161 widgetoptsSettingsModule.ajaxRequest( module, 'save', data, widgetoptsSettingsModule.savingCallback );
162 },
163
164 savingCallback: function( results ) {
165 if ( '' === results.module ) {
166 jQuery( '#widgetopts-save' ).prop( 'disabled', false );
167 } else {
168 jQuery( '#widgetopts-module-card-' + results.module + ' button.widgetopts-module-settings-save' ).prop( 'disabled', false );
169 }
170
171 var $container = jQuery( '.widgetopts-module-cards-container' );
172 var view = 'grid';
173
174 // console.log( results );
175 widgetoptsSettingsModule.clearMessages();
176 if ( results.errors.length > 0 || ! results.closeModal ) {
177 widgetoptsSettingsModule.showMessages( results.messages, results.module, 'open' );
178 $container.find( '.widgetopts-module-settings-content-container:visible' ).animate( {'scrollTop': 0}, 'fast' );
179
180 } else {
181 widgetoptsSettingsModule.showMessages( results.messages, results.module, 'closed' );
182 $container.find( '.widgetopts-module-settings-content-container:visible' ).scrollTop( 0 );
183 widgetoptsSettingsModule.closeModal();
184 }
185 },
186
187 clearMessages: function() {
188 jQuery( '#widgetopts-settings-messages-container, .widgetopts-module-messages-container' ).empty();
189 },
190
191 showMessages: function( messages, module, containerStatus ) {
192 jQuery.each( messages, function( index, message ) {
193 widgetoptsSettingsModule.showMessage( message, module, containerStatus );
194 } );
195 },
196
197 showMessage: function( message, module, containerStatus ) {
198 var view = 'grid';
199
200 if ( 'closed' !== containerStatus && 'open' !== containerStatus ) {
201 containerStatus = 'closed';
202 }
203
204 if ( 'string' !== typeof module ) {
205 module = '';
206 }
207
208 if ( 'closed' === containerStatus || '' === module ) {
209 var container = jQuery( '#widgetopts-settings-messages-container' );
210
211 setTimeout( function() {
212 container.removeClass( 'visible' );
213 setTimeout( function() {
214 container.find( 'div' ).remove();
215 }, 500 );
216 }, 4000 );
217 } else {
218 var container = jQuery( '#widgetopts-module-card-' + module + ' .widgetopts-module-messages-container' );
219 }
220
221 container.append( '<div class="updated fade"><p><strong>' + message + '</strong></p></div>' ).addClass( 'visible' );
222 },
223
224
225 ajaxRequest: function( module, method, data, callback ) {
226 var postData = {
227 'action': widgetopts.ajax_action,
228 'nonce': widgetopts.ajax_nonce,
229 'module': module,
230 'method': method,
231 'data': data,
232 };
233
234 jQuery.post( ajaxurl, postData )
235 .always(function( a, status, b ) {
236 widgetoptsSettingsModule.processAjaxResponse( a, status, b, module, method, data, callback );
237 });
238 },
239
240 processAjaxResponse: function( a, status, b, module, method, data, callback ) {
241 var results = {
242 'module': module,
243 'method': method,
244 'data': data,
245 'status': status,
246 'license_status': null,
247 'jqxhr': null,
248 'success': false,
249 'response': null,
250 'button': null,
251 'errors': [],
252 'messages': [],
253 'functionCalls': [],
254 'redirect': false,
255 'closeModal': true
256 };
257 // console.log( a );
258
259 a = jQuery.parseJSON( a );
260
261 if ( 'WIDGETOPTS_Response' === a.source && 'undefined' !== a.response ) {
262 // Successful response with a valid format.
263 results.jqxhr = b;
264 results.success = a.success;
265 results.response = a.response;
266 results.errors = a.errors;
267 results.messages = a.messages;
268 results.functionCalls = a.functionCalls;
269 results.redirect = a.redirect;
270 results.closeModal = a.closeModal;
271 results.button = a.button;
272
273 if( typeof results.license_status != 'undefined' ){
274 results.license_status = a.license_status;
275 }
276 }
277
278 if ( 'function' === typeof callback ) {
279 callback( results );
280 } else if ( 'function' === typeof console.log ) {
281 console.log( 'ERROR: Unable to handle settings AJAX request due to an invalid callback:', callback, {'data': postData, 'results': results} );
282 }
283
284 },
285
286 toggleCustomClass: function(e){
287 var getVal = jQuery('.opts-add-class-txtfld').val();
288 var fname = 'extwopts_class_settings[classlists][]';
289 if( jQuery(this).hasClass('widgetopts-add-class-btn') ){
290 fname = 'classes[classlists][]';
291 }
292 if( getVal.length > 0 ){
293 jQuery('#opts-predefined-classes ul').append('<li><input type="hidden" name="'+ fname +'" value="'+ getVal +'" /><span class"opts-li-value">'+ getVal +'</span> <a href="#" class="opts-remove-class-btn"><span class="dashicons dashicons-dismiss"></span></a></li>');
294 jQuery('.opts-add-class-txtfld').val('');
295 }
296
297 e.preventDefault();
298 e.stopPropagation();
299 },
300
301 removeCustomClass: function(e){
302 jQuery(this).parent('li').fadeOut('fast',function(){
303 jQuery(this).remove();
304 });
305 e.preventDefault();
306 e.stopPropagation();
307 },
308
309 clearWidgetCache: function( e ){
310 var $button = jQuery(this);
311 $button.prop( 'disabled', true );
312
313 widgetoptsSettingsModule.ajaxRequest( 'clear_cache', 'clear_cache', '', widgetoptsSettingsModule.clearWidgetCacheCallback );
314 return false;
315 },
316 clearWidgetCacheCallback: function( results ){
317 if( typeof results.response != 'undefined' ){
318 jQuery( '.widgetopts-delete-cache' ).after( '<span class="dashicons dashicons-yes widgetopts-cache-dashicons"></span>' );
319 jQuery( '.widgetopts-cache-dashicons' ).delay(2000).fadeOut(400);
320 jQuery( '.widgetopts-delete-cache' ).prop( 'disabled', false );
321 }
322 },
323
324 deactivationHandler: function(e){
325 e.preventDefault();
326
327 var fld;
328 var $button = jQuery(this);
329 $button.prop( 'disabled', true );
330
331 fld = jQuery( '#' + $button.attr('data-target') );
332 if( fld.val() != '' ){
333 var data = {
334 'license-data': fld.val(),
335 'license-action': 'deactivate',
336 'shortname' : $button.attr('data-shortname'),
337 'button': $button.attr('id')
338 };
339
340 widgetoptsSettingsModule.ajaxRequest( 'license_key', 'deactivate_license', data, widgetoptsSettingsModule.licenseDeactivationCallback );
341 }else{
342 fld.css({ 'border' : '1px solid red' });
343 $button.prop( 'disabled', false );
344 }
345 },
346
347 licenseDeactivationCallback: function( results ){
348 // console.log( results ); widgetopts-license-extended-response
349 if( typeof results.response != 'undefined' && typeof results.messages != 'undefined' && typeof results.button != 'undefined' ){
350 var $button = jQuery( '#' + results.button );
351
352 jQuery( '#' + $button.attr('data-target') ).before( '<span>' + results.messages[0] + '</span>' );
353 if( results.success == 'deactivated' ){
354 $button.parent('td').parent('tr').fadeOut();
355 jQuery( '#' + $button.attr('data-target') ).val('');
356 }
357 }else{
358 // jQuery('.widgetopts-license-key').css({ 'border' : '1px solid red' });
359 // jQuery('.widgetopts-license-status').fadeIn();
360 }
361
362 $button.prop( 'disabled', false );
363
364 }
365 }
366
367 jQuery(document).ready(function() {
368 widgetoptsSettingsModule.init();
369 });
370