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
select2-settings.js
116 lines
| 1 | (function($){ |
| 2 | |
| 3 | WidgetOptsSelect2 = { |
| 4 | _init: function() |
| 5 | { |
| 6 | $('select.widgetopts-select2').each(function() { |
| 7 | var $el = $(this); |
| 8 | |
| 9 | // Use AJAX mode for snippet dropdown |
| 10 | if ($el.attr('name') === 'widgetopts_logic_snippet_id') { |
| 11 | $el.select2({ |
| 12 | width: '100%', |
| 13 | allowClear: true, |
| 14 | placeholder: '— No Logic (Always Show) —', |
| 15 | minimumInputLength: 0, |
| 16 | ajax: { |
| 17 | url: ajaxurl, |
| 18 | type: 'POST', |
| 19 | dataType: 'json', |
| 20 | delay: 250, |
| 21 | data: function(params) { |
| 22 | return { |
| 23 | action: 'widgetopts_get_snippets_ajax', |
| 24 | search: params.term || '' |
| 25 | }; |
| 26 | }, |
| 27 | processResults: function(response) { |
| 28 | var results = [{id: '', text: '— No Logic (Always Show) —'}]; |
| 29 | if (response.success && response.data && response.data.snippets) { |
| 30 | response.data.snippets.forEach(function(snippet) { |
| 31 | results.push({id: String(snippet.id), text: snippet.title, description: snippet.description || ''}); |
| 32 | }); |
| 33 | } |
| 34 | return { results: results }; |
| 35 | }, |
| 36 | cache: true |
| 37 | } |
| 38 | }).on('change', $.proxy(WidgetOptsSelect2._maybePreview, this.context)); |
| 39 | |
| 40 | // Add dynamic description element if not present |
| 41 | var $field = $el.closest('.fl-field'); |
| 42 | var $descEl = $field.find('.widgetopts-snippet-desc'); |
| 43 | if (!$descEl.length) { |
| 44 | $descEl = $('<p class="widgetopts-snippet-desc description" style="font-style: italic; color: #666; display:none; margin-top:5px;"></p>'); |
| 45 | $field.find('.fl-field-control').append($descEl); |
| 46 | } |
| 47 | $el.on('select2:select', function(e) { |
| 48 | var desc = e.params.data.description || ''; |
| 49 | if (desc) { |
| 50 | $descEl.text(desc).show(); |
| 51 | } else { |
| 52 | $descEl.text('').hide(); |
| 53 | } |
| 54 | }); |
| 55 | $el.on('select2:unselect', function() { |
| 56 | $descEl.text('').hide(); |
| 57 | }); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | $el.select2({ |
| 62 | width: '100%', |
| 63 | allowClear: true, |
| 64 | placeholder: ' ' |
| 65 | }).on('change', $.proxy(WidgetOptsSelect2._maybePreview, this.context)) |
| 66 | .on('select2:unselecting', function(e) { |
| 67 | $(this).data('unselecting', true); |
| 68 | }).on('select2:open', function(e) { // note the open event is important |
| 69 | if ($(this).data('unselecting')) { |
| 70 | $(this).removeData('unselecting'); // you need to unset this before close |
| 71 | $(this).select2('close'); |
| 72 | } |
| 73 | }).on('select2:unselect', function(e) { // note the open event is important |
| 74 | if( !$(this).val() ){ |
| 75 | $(this).val("").trigger('change'); |
| 76 | } |
| 77 | }); |
| 78 | |
| 79 | if($(this).attr('multiple')) { |
| 80 | var ul = $(this).siblings('.select2-container').first('ul.select2-selection__rendered'); |
| 81 | ul.sortable({ |
| 82 | placeholder : 'ui-state-highlight', |
| 83 | forcePlaceholderSize: true, |
| 84 | items : 'li:not(.select2-search__field)', |
| 85 | tolerance : 'pointer', |
| 86 | stop: function() { |
| 87 | $($(ul).find('.select2-selection__choice').get().reverse()).each(function() { |
| 88 | var id = $(this).data('data').id; |
| 89 | var option = $(this).find('option[value="' + id + '"]')[0]; |
| 90 | $(this).prepend(option); |
| 91 | }); |
| 92 | } |
| 93 | }); |
| 94 | } |
| 95 | }); |
| 96 | }, |
| 97 | |
| 98 | _maybePreview: function() { |
| 99 | var e = { |
| 100 | target: this |
| 101 | }; |
| 102 | |
| 103 | var field = $(this).closest('.fl-field'); |
| 104 | var previewType = field.data('preview'); |
| 105 | |
| 106 | if ('refresh' == previewType.type) { |
| 107 | FLBuilder.preview.delayPreview(e); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | FLBuilder.addHook('settings-form-init', function() { |
| 113 | WidgetOptsSelect2._init(); |
| 114 | }); |
| 115 | |
| 116 | })(jQuery); |