PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.2.3
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.2.3
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 / wpWidgetOpts.js
widget-options / assets / js Last commit date
bootstrap-multiselect.min.js 2 months ago jquery.liveFilter.js 2 months ago jquery.liveFilter.min.js 2 months ago jquery.widgetopts.beaver.js 2 months ago jquery.widgetopts.beaver.min.js 2 months ago select2-settings.js 2 months ago select2-settings.min.js 2 months ago select2.min.js 2 months ago settings.js 2 months ago settings.min.js 2 months ago widgetopts.global.js 2 months ago widgetopts.migration.js 2 months ago widgetopts.resize.js 2 months ago widgets.js 2 months ago widgets.min.js 2 months ago wpWidgetOpts.js 2 months ago wpWidgetOpts.min.js 2 months ago
wpWidgetOpts.js
492 lines
1 /*global ajaxurl, isRtl */
2 var wpWidgetOpts;
3 (function($) {
4 var $document = $( document );
5
6 wpWidgetOpts = {
7 /**
8 * A closed Sidebar that gets a Widget dragged over it.
9 *
10 * @var element|null
11 */
12 hoveredSidebar: null,
13
14 init : function() {
15 var self = this,
16 title = $( '.wp-admin.widgets-php .wrap a.page-title-action' ),
17 tabs = $( '.extended-widget-opts-tabs' ),
18 chooser = $( '.widgetsopts-chooser' ),
19 selectSidebar = chooser.find( '.widgetopts-chooser-sidebars' );
20 // ta = chooser.find('.widgets-chooser-sidebars'),
21 // sidebars = $('div.widgets-sortables'),
22 // isRTL = !! ( 'undefined' !== typeof isRtl && isRtl );
23
24 if( tabs.length > 0 ){
25 self.loaded( '', 'loaded' );
26 }
27
28 //runs on customizer
29 $( '.widget-liquid-right .widget, .inactive-sidebar .widget, #accordion-panel-widgets .customize-control-widget_form' ).each(function (i, widget) {
30 self.loaded( '', 'loaded' );
31 });
32
33 //fires when widget added
34 $document.on( 'widget-added', function( event, widget ) {
35 self.loaded( widget, 'added' );
36 });
37
38 //fires when widget updated
39 $document.on( 'widget-updated', function( event, widget ) {
40 self.loaded( widget, 'updated' );
41 });
42
43 //toggle accordions
44 $document.on( 'click', '.extended-widget-opts-inner-lists h4',function(){
45 var getid = $(this).attr('id');
46 $( '.extended-widget-opts-inner-lists .'+ getid ).slideToggle(250);
47 } );
48
49 //toggle widget logic notice
50 $document.on( 'click', '.widget-opts-toggler-note',function(e){
51 $( this ).parent( 'p' ).parent( '.widget-opts-logic' ).find( '.widget-opts-toggle-note' ).slideToggle( 250 );
52 e.preventDefault();
53 e.stopPropagation();
54 } );
55
56 //add link to settings page on title
57 if( title.length > 0 ){
58 title.after('<a href="'+ widgetopts10n.opts_page +'" class="page-title-action hide-if-no-customize widgetopts-super">'+ widgetopts10n.translation.manage_settings +'</a>');
59 }
60
61 //live search filter
62 self.live_search();
63
64 //append move and clone button to .widget-control-actions
65 $( '.widget-control-actions .alignleft .widget-control-remove' ).after( widgetopts10n.controls );
66
67 //chooser for move and clone action
68 self.do_chooser( chooser, selectSidebar );
69
70 //add sidebar options
71 self.sidebarOptions();
72 self.removeSidebarWidgets();
73 self.initPageDropdown('');
74 self.initTaxonomyDropdown('');
75
76 },
77 loaded : function( widget, action ){
78 var widget_id,
79 selected = 0,
80 selected_styling = 0,
81 selected_main = 0,
82 selected_visibility = 0,
83 selected_settings = 0,
84 in_customizer = false,
85 tabs = '.extended-widget-opts-tabs',
86 styling_tabs = '.extended-widget-opts-styling-tabs',
87 visibility_main = '.extended-widget-opts-visibility-m-tabs',
88 visibility_tabs = '.extended-widget-opts-visibility-tabs',
89 settings_tabs = '.extended-widget-opts-settings-tabs',
90 selectedtab = '#extended-widget-opts-selectedtab',
91 selectedstyling = '#extended-widget-opts-styling-selectedtab',
92 selectedmain = '#extended-widget-opts-visibility-m-selectedtab',
93 selectedvisibility = '#extended-widget-opts-visibility-selectedtab',
94 selectedsettings = '#extended-widget-opts-settings-selectedtab';
95
96 // check for wp.customize return boolean
97 if ( typeof wp !== 'undefined' ) {
98 in_customizer = typeof wp.customize !== 'undefined' ? true : false;
99 }
100 if( '' != widget ){
101 widget_id = '#' + widget.attr('id');
102
103 if( $( widget_id ).find( selectedtab ).length > 0 ){
104 selected = $( '#' + widget.attr('id') ).find( selectedtab ).val();
105 selected = parseInt( selected );
106 }
107
108 if( $( widget_id ).find( selectedvisibility ).length > 0 ){
109 selected_visibility = $( '#' + widget.attr('id') ).find( selectedvisibility ).val();
110 selected_visibility = parseInt( selected_visibility );
111 }
112
113 if( $( widget_id ).find( selectedmain ).length > 0 ){
114 selected_main = $( '#' + widget.attr('id') ).find( selectedmain ).val();
115 selected_main = parseInt( selected_main );
116 }
117
118 if( $( widget_id ).find( selectedsettings ).length > 0 ){
119 selected_settings = $( '#' + widget.attr('id') ).find( selectedsettings ).val();
120 selected_settings = parseInt( selected_settings );
121 }
122 // console.log( in_customizer );
123 }
124 if( action == 'added' ){
125 selected = 0;
126 selected_main = 0,
127 selected_visibility = 0;
128 selected_settings = 0;
129 }
130
131 if( '' != widget ){
132 if( $( widget_id ).find( tabs ).length > 0 ){
133 $( widget_id ).find( tabs ).tabs({ active: selected });
134 }
135 if( $( widget_id ).find( visibility_main ).length > 0 ){
136 $( widget_id ).find( visibility_main ).tabs({ active: selected_main });
137 }
138 if( $( widget_id ).find( visibility_tabs ).length > 0 ){
139 $( widget_id ).find( visibility_tabs ).tabs({ active: selected_visibility });
140 }
141 if( $( widget_id ).find( settings_tabs ).length > 0 ){
142 $( widget_id ).find( settings_tabs ).tabs({ active: selected_settings });
143 }
144 }else{
145 $( tabs ).tabs({ active: selected });
146 $( styling_tabs ).tabs({ active: selected_styling });
147 $( visibility_main ).tabs({ active: selected_main });
148 $( visibility_tabs ).tabs({ active: selected_visibility });
149 $( settings_tabs ).tabs({ active: selected_settings });
150 }
151
152 $( tabs ).click('tabsselect', function (event, ui) {
153 if( $(this).find( selectedtab ).length > 0 ){
154 $(this).find( selectedtab ).val( $(this).tabs('option', 'active') );
155 }
156 });
157
158 $( visibility_tabs ).click('tabsselect', function (event, ui) {
159 if( $(this).find( selectedvisibility ).length > 0 ){
160 $(this).find( selectedvisibility ).val( $(this).tabs('option', 'active') );
161 }
162 });
163
164 $( visibility_main ).click('tabsselect', function (event, ui) {
165 if( $(this).find( selectedmain ).length > 0 ){
166 $(this).find( selectedmain ).val( $(this).tabs('option', 'active') );
167 }
168 });
169
170 $( settings_tabs ).click('tabsselect', function (event, ui) {
171 if( $(this).find( selectedsettings ).length > 0 ){
172 $(this).find( selectedsettings ).val( $(this).tabs('option', 'active') );
173 }
174 });
175
176 this.initPageDropdown(widget_id);
177 this.initTaxonomyDropdown(widget_id);
178 },
179 live_search : function(){
180 if ( typeof $.fn.liveFilter !== 'undefined' && $( '#widgetopts-widgets-search' ).length > 0 ) {
181 // Add separator to distinguish between visible and hidden widgets
182 $('.widget:last-of-type').after('<div class="widgetopts-separator" />');
183
184 // Add data attribute for order to each widget
185 $('#widgets-left .widget').each(function() {
186 var index = $(this).index() + 1;
187 $(this).attr( 'data-widget-index', index );
188 });
189
190 // Add liveFilter : credits to https://wordpress.org/plugins/widget-search-filter/ plugin
191 $('#widgets-left').liveFilter('#widgetopts-widgets-search', '.widget', {
192 filterChildSelector: '.widget-title h4, .widget-title h3',
193 after: function(contains, containsNot) {
194
195 // Move all hidden widgets to end.
196 containsNot.each(function() {
197 $(this).insertAfter($(this).parent().find('.widgetopts-separator'));
198 });
199
200 // Sort all visible widgets by original index
201 contains.sort(function(a,b) {
202 return a.getAttribute('data-widget-index') - b.getAttribute('data-widget-index');
203 });
204
205 // Move all visible back
206 contains.each(function() {
207 $(this).insertBefore($(this).parent().find('.widgetopts-separator'));
208 });
209
210 }
211 });
212
213 //add clear search
214 $( '#wpbody-content' ).on( 'keyup', '.widgetopts-widgets-search', function(e){
215 p = $(this).parent().find( '.widgetopts-clear-results' );
216 if ( '' !== $(this).val() ) {
217 p.addClass( 'widgetopts-is-visible' );
218 }else{
219 p.removeClass( 'widgetopts-is-visible' );
220 }
221 } );
222
223 $( '#wpbody-content' ).on( 'click', '.widgetopts-clear-results', function(e){
224 s = $(this).parent().find( '.widgetopts-widgets-search' );
225 s.val( '' ).focus().trigger( 'keyup' );
226
227 if( s.attr( 'id' ) == 'widgetopts-search-chooser' ){
228 $( '.widgets-chooser-sidebars li:not(:first)' ).removeClass( 'widgets-chooser-selected' );
229 }else if( s.hasClass('widgetsopts-widgets-search') ){
230 $( '.widgetopts-chooser-sidebars li:not(:first)' ).removeClass( 'widgetopts-chooser-selected' );
231 }
232
233 e.preventDefault();
234 e.stopPropagation();
235 return false;
236 } );
237
238 //add sidebar chooser search field
239 $('.widgets-chooser').prepend( widgetopts10n.search_form );
240 //live filter
241 $('.widgets-chooser').liveFilter('#widgetopts-search-chooser', '.widgets-chooser-sidebars li', {
242 // filterChildSelector: 'li',
243 after: function( contains, containsNot ) {
244 //hide
245 containsNot.each(function() {
246 $(this).addClass( 'widgetopts-is-hidden' ).removeClass( 'widgets-chooser-selected' );
247 });
248 contains.each(function() {
249 $(this).removeClass( 'widgetopts-is-hidden' ).removeClass( 'widgets-chooser-selected' );
250 });
251 if( contains.length > 0 ){
252 $( contains[0] ).addClass( 'widgets-chooser-selected' );
253 }
254
255 }
256 });
257
258 }
259 },
260 do_chooser : function( chooser, selectSidebar ){
261 var self = this;
262
263 //add sidebar lists on chooser
264 $( '#widgets-right .widgets-holder-wrap' ).each( function( index, element ) {
265 var $element = $( element ),
266 name = $element.find( '.sidebar-name h2' ).text(),
267 id = $element.find( '.widgets-sortables' ).attr( 'id' ),
268 li = $('<li tabindex="0">').text(name.trim());
269
270 if ( index === 0 ) {
271 li.addClass( 'widgetopts-chooser-selected' );
272 }
273
274 selectSidebar.append( li );
275 li.attr( 'data-sidebarId', id );
276 });
277
278 //do click
279 $document.on( 'click', '.widgetopts-control', function(e){
280 var lbl = $(this).text(),
281 action = $( this ).attr( 'data-action' );
282
283 if( $(this).hasClass( 'widgetopts-control-open' ) ){
284 self.closeChooser();
285 $( '.widgetopts-control-open' ).removeClass( 'widgetopts-control-open' );
286 }else{
287
288 chooser.find( '.widgetopts-chooser-action span' ).text( lbl );
289 chooser.find( '.widgetopts-chooser-action' ).attr( 'data-action', action );
290 $(this).parents('.widget-control-actions').find('.clear').after( chooser );
291
292 chooser.slideDown( 300, function() {
293 selectSidebar.find('.widgets-chooser-selected').focus();
294 });
295 $( '.widgetopts-control-open' ).removeClass( 'widgetopts-control-open' );
296 $(this).addClass( 'widgetopts-control-open' );
297
298 self.chooserSearch();
299 }
300
301 e.preventDefault();
302 } );
303
304 //add selected on click
305 $document.on( 'click', '.widgetopts-chooser-sidebars li', function(e){
306 selectSidebar.find('.widgetopts-chooser-selected').removeClass( 'widgetopts-chooser-selected' );
307 $(this).addClass( 'widgetopts-chooser-selected' );
308 } );
309
310 //do action
311 $document.on( 'click', '.widgetsopts-chooser .widgetopts-chooser-action', function(e){
312 var $container = $( 'html,body' ),
313 $action = $( this ).attr( 'data-action' ),
314 parentSidebar = $( this ).parents('.widgets-sortables').attr('id'),
315 widgetID = $( this ).parents('.widget').attr('id'),
316 $widget = $( '#'+ widgetID );
317 sidebarID = $( '.widgetopts-chooser-selected' ).attr('data-sidebarId');
318 // console.log( $action + ' ' + parentSidebar +' ' + widgetID + ' ' + sidebarID);
319 //remove chooser
320 $( '#'+ widgetID + ' .widgetsopts-chooser' ).remove();
321 $widget.find(' .widgetopts-control-open' ).removeClass( 'widgetopts-control-open' );
322
323 switch ( $action ) {
324 case 'move':
325 $( '#' + parentSidebar ).find( '#' + widgetID ).appendTo( '#' + sidebarID );
326
327 $('#' + sidebarID).sortable('refresh');
328 $widget.addClass( 'widgetopts-move-ds' );
329 $( '#' + sidebarID ).parent('.widgets-holder-wrap').removeClass( 'closed' );
330 wpWidgets.save( $( '#' + widgetID ), 0, 0, 1 );
331 break;
332 default:
333 break;
334
335 }
336
337 var $scrollTo = $( '.widgetopts-move-ds' );
338
339 $container.animate({ scrollTop: $scrollTo.offset().top - ( $container.offset().top + $container.scrollTop() + 60 ) }, 200 );
340 $( '.widgetopts-move-ds' ).removeClass( '.widgetopts-move-ds' );
341 e.preventDefault();
342 } );
343
344 //cancel chooser
345 $document.on( 'click', '.widgetsopts-chooser .widgetsopts-chooser-cancel', function(e){
346 self.closeChooser( chooser );
347 e.preventDefault();
348 } );
349 },
350 closeChooser : function( chooser ) {
351 var self = this;
352
353 $( '.widgetsopts-chooser' ).slideUp( 200, function() {
354 $( '.widgetopts-control' ).removeClass( 'widgetopts-control-open' );
355 $( '#wpbody-content' ).append( this );
356 });
357 },
358 chooserSearch : function(){
359 //add livefilter
360 if( $( '#widgetsopts-widgets-search' ).length > 0 ){
361 $('.widgetsopts-chooser').liveFilter('#widgetsopts-widgets-search', '.widgetopts-chooser-sidebars li', {
362 // filterChildSelector: 'li',
363 after: function( contains, containsNot ) {
364 //hide
365 containsNot.each(function() {
366 $(this).addClass( 'widgetopts-is-hidden' ).removeClass( 'widgetopts-chooser-selected' );
367 });
368 contains.each(function() {
369 $(this).removeClass( 'widgetopts-is-hidden' ).removeClass( 'widgetopts-chooser-selected' );
370 });
371 if( contains.length > 0 ){
372 $( contains[0] ).addClass( 'widgetopts-chooser-selected' );
373 }
374
375 }
376 });
377 }
378 },
379 sidebarOptions : function(){
380 var self = this;
381 if( widgetopts10n.sidebaropts.length > 0 ){
382 $( '#widgets-right .widgets-holder-wrap' ).each( function( index, element ) {
383 var sidebar_opts_h2 = $(this).find('.widgets-sortables h2').text();
384 dl_link = widgetopts10n.sidebaropts.replace( '__sidebaropts__', $(this).find('.widgets-sortables').attr('id') );
385 dl_link = dl_link.replace( '__sidebar_opts__', sidebar_opts_h2.trim() );
386 $(this).append( dl_link );
387 });
388 }
389 },
390 removeSidebarWidgets : function(){
391 var self = this;
392 var $container = $( 'html,body' );
393 $document.on( 'click', '.sidebaropts-clear', function(e){
394 //show confirmation
395 $(this).parent().find( '.sidebaropts-confirm' ).addClass( 'sidebaropts-confirmed' );
396 $(this).parent().find( '.sidebaropts-confirm' ).slideToggle(250);
397
398 e.preventDefault();
399 });
400
401 $document.on( 'click', '.sidebaropts-confirmed .button', function(e){
402 sidebar_id = $(this).parent().parent().parent().find('.widgets-sortables');
403
404 if( $(this).hasClass( 'button-primary' ) ){
405 var $scrollTo = sidebar_id;
406
407 $(this).parent().slideToggle(50);
408 $container.animate({ scrollTop: $scrollTo.offset().top - 50 }, 200 );
409
410 sidebar_id.find( '.widget' ).each( function( index, element ) {
411 $( element ).fadeOut();
412 wpWidgets.save( $( element ), 1, 1, 0 );
413 });
414
415 }else{
416 $(this).parent().slideToggle(250);
417 }
418
419 e.preventDefault();
420 });
421 },
422 initPageDropdown : function(widget_id) {
423 var args = {
424 ajax: {
425 url: widgetopts10n.ajax_url,
426 dataType: 'json',
427 delay: 250,
428 type: 'POST',
429 data: function (params) {
430 var query = {
431 action: 'widgetopts_ajax_page_search',
432 term: params.term
433 }
434
435 return query;
436 }
437 },
438 placeholder: 'Search for Pages',
439 minimumInputLength: 3,
440 language: {
441 searching: function() {
442 return 'Searching...';
443 }
444 },
445 }
446
447 if ( widget_id != '' ) {
448 $( widget_id ).find( '.extended-widget-opts-select2-page-dropdown' ).select2(args);
449 }
450 else {
451 $( '.widget-liquid-right .extended-widget-opts-select2-page-dropdown' ).select2(args);
452 }
453 },
454 initTaxonomyDropdown : function(widget_id) {
455 var args = {
456 ajax: {
457 url: widgetopts10n.ajax_url,
458 dataType: 'json',
459 delay: 250,
460 type: 'POST',
461 data: function (params) {
462 var query = {
463 action: 'widgetopts_ajax_taxonomy_search',
464 term: params.term,
465 taxonomy: $(this).data('taxonomy')
466 }
467
468 return query;
469 }
470 },
471 placeholder: 'Search for Terms',
472 minimumInputLength: 3,
473 language: {
474 searching: function() {
475 return 'Searching...';
476 }
477 },
478 }
479
480 if ( widget_id != '' ) {
481 $( widget_id ).find( '.extended-widget-opts-select2-taxonomy-dropdown' ).select2(args);
482 }
483 else {
484 $( '.widget-liquid-right .extended-widget-opts-select2-taxonomy-dropdown' ).select2(args);
485 }
486 }
487 };
488
489 $document.ready( function(){ wpWidgetOpts.init(); } );
490
491 })(jQuery);
492