codemirror
9 years ago
javascript-md5
7 years ago
how-to.js
8 years ago
how-to.min.js
6 years ago
jquery.colorbox.js
8 years ago
jquery.colorbox.min.js
6 years ago
metabox.js
5 years ago
metabox.min.js
5 years ago
multisite-updater.js
6 years ago
multisite-updater.min.js
6 years ago
wp-pages.js
6 years ago
wp-pages.min.js
6 years ago
yit-cpt-unlimited.js
6 years ago
yit-cpt-unlimited.min.js
6 years ago
yit-plugin-panel.js
5 years ago
yit-plugin-panel.min.js
5 years ago
yit-wp-pointer.js
5 years ago
yit-wp-pointer.min.js
5 years ago
yith-colorpicker.min.js
5 years ago
yith-dashboard.js
7 years ago
yith-dashboard.min.js
6 years ago
yith-enhanced-select-wc-2.6.js
5 years ago
yith-enhanced-select-wc-2.6.min.js
5 years ago
yith-enhanced-select.js
5 years ago
yith-enhanced-select.min.js
5 years ago
yith-fields.js
5 years ago
yith-fields.min.js
5 years ago
yith-gutenberg.js
5 years ago
yith-gutenberg.min.js
5 years ago
yith-promo.js
7 years ago
yith-promo.min.js
6 years ago
yith-system-info.js
5 years ago
yith-system-info.min.js
5 years ago
yith-update-plugins.js
7 years ago
yith-update-plugins.min.js
6 years ago
yith-enhanced-select.js
198 lines
| 1 | /* global yith_framework_enhanced_select_params */ |
| 2 | |
| 3 | jQuery( function ( $ ) { |
| 4 | "use strict"; |
| 5 | |
| 6 | $( document.body ) |
| 7 | .on( 'yith-framework-enhanced-select-init', function () { |
| 8 | // Post Search |
| 9 | $( '.yith-post-search' ).filter( ':not(.enhanced)' ).each( function () { |
| 10 | var default_data = { |
| 11 | action : 'yith_plugin_fw_json_search_posts', |
| 12 | security : yith_framework_enhanced_select_params.search_posts_nonce, |
| 13 | post_type: 'post' |
| 14 | }, |
| 15 | current_data = $.extend( default_data, $( this ).data() ), |
| 16 | select2_args = { |
| 17 | allowClear : $( this ).data( 'allow_clear' ) ? true : false, |
| 18 | placeholder : $( this ).data( 'placeholder' ), |
| 19 | minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '3', |
| 20 | escapeMarkup : function ( m ) { |
| 21 | return m; |
| 22 | }, |
| 23 | ajax : { |
| 24 | url : ajaxurl, |
| 25 | dataType : 'json', |
| 26 | quietMillis : 250, |
| 27 | data : function ( params ) { |
| 28 | var default_data_to_return = { |
| 29 | term: params.term |
| 30 | }; |
| 31 | |
| 32 | return $.extend( default_data_to_return, current_data ); |
| 33 | }, |
| 34 | processResults: function ( data ) { |
| 35 | var terms = []; |
| 36 | if ( data ) { |
| 37 | $.each( data, function ( id, text ) { |
| 38 | terms.push( { id: id, text: text } ); |
| 39 | } ); |
| 40 | } |
| 41 | return { |
| 42 | results: terms |
| 43 | }; |
| 44 | }, |
| 45 | cache : true |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | $( this ).select2( select2_args ).addClass( 'enhanced' ); |
| 50 | |
| 51 | if ( $( this ).data( 'sortable' ) ) { |
| 52 | var $select = $( this ); |
| 53 | var $list = $( this ).next( '.select2-container' ).find( 'ul.select2-selection__rendered' ); |
| 54 | |
| 55 | $list.sortable( { |
| 56 | placeholder : 'ui-state-highlight select2-selection__choice', |
| 57 | forcePlaceholderSize: true, |
| 58 | items : 'li:not(.select2-search__field)', |
| 59 | tolerance : 'pointer', |
| 60 | stop : function () { |
| 61 | $( $list.find( '.select2-selection__choice' ).get().reverse() ).each( function () { |
| 62 | var id = $( this ).data( 'data' ).id; |
| 63 | var option = $select.find( 'option[value="' + id + '"]' )[ 0 ]; |
| 64 | $select.prepend( option ); |
| 65 | } ); |
| 66 | } |
| 67 | } ); |
| 68 | } |
| 69 | } ); |
| 70 | |
| 71 | // Customer Search |
| 72 | $( '.yith-customer-search' ).filter( ':not(.enhanced)' ).each( function () { |
| 73 | var default_data = { |
| 74 | action : 'woocommerce_json_search_customers', |
| 75 | security : yith_framework_enhanced_select_params.search_customers_nonce, |
| 76 | }, |
| 77 | current_data = $.extend( default_data, $( this ).data() ), |
| 78 | select2_args = { |
| 79 | allowClear : $( this ).data( 'allow_clear' ) ? true : false, |
| 80 | placeholder : $( this ).data( 'placeholder' ), |
| 81 | minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '3', |
| 82 | escapeMarkup : function ( m ) { |
| 83 | return m; |
| 84 | }, |
| 85 | ajax : { |
| 86 | url : ajaxurl, |
| 87 | dataType : 'json', |
| 88 | quietMillis : 250, |
| 89 | data : function ( params ) { |
| 90 | var default_data_to_return = { |
| 91 | term: params.term |
| 92 | }; |
| 93 | |
| 94 | return $.extend( default_data_to_return, current_data ); |
| 95 | }, |
| 96 | processResults: function ( data ) { |
| 97 | var terms = []; |
| 98 | if ( data ) { |
| 99 | $.each( data, function ( id, text ) { |
| 100 | terms.push( { id: id, text: text } ); |
| 101 | } ); |
| 102 | } |
| 103 | return { |
| 104 | results: terms |
| 105 | }; |
| 106 | }, |
| 107 | cache : true |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | $( this ).select2( select2_args ).addClass( 'enhanced' ); |
| 112 | |
| 113 | if ( $( this ).data( 'sortable' ) ) { |
| 114 | var $select = $( this ); |
| 115 | var $list = $( this ).next( '.select2-container' ).find( 'ul.select2-selection__rendered' ); |
| 116 | |
| 117 | $list.sortable( { |
| 118 | placeholder : 'ui-state-highlight select2-selection__choice', |
| 119 | forcePlaceholderSize: true, |
| 120 | items : 'li:not(.select2-search__field)', |
| 121 | tolerance : 'pointer', |
| 122 | stop : function () { |
| 123 | $( $list.find( '.select2-selection__choice' ).get().reverse() ).each( function () { |
| 124 | var id = $( this ).data( 'data' ).id; |
| 125 | var option = $select.find( 'option[value="' + id + '"]' )[ 0 ]; |
| 126 | $select.prepend( option ); |
| 127 | } ); |
| 128 | } |
| 129 | } ); |
| 130 | } |
| 131 | } ); |
| 132 | |
| 133 | // TERM SEARCH |
| 134 | $( '.yith-term-search' ).filter( ':not(.enhanced)' ).each( function () { |
| 135 | var default_data = { |
| 136 | action : 'yith_plugin_fw_json_search_terms', |
| 137 | security: yith_framework_enhanced_select_params.search_terms_nonce, |
| 138 | taxonomy: 'category' |
| 139 | }, |
| 140 | current_data = $.extend( default_data, $( this ).data() ), |
| 141 | select2_args = { |
| 142 | allowClear : $( this ).data( 'allow_clear' ) ? true : false, |
| 143 | placeholder : $( this ).data( 'placeholder' ), |
| 144 | minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '3', |
| 145 | escapeMarkup : function ( m ) { |
| 146 | return m; |
| 147 | }, |
| 148 | ajax : { |
| 149 | url : ajaxurl, |
| 150 | dataType : 'json', |
| 151 | quietMillis : 250, |
| 152 | data : function ( params ) { |
| 153 | var default_data_to_return = { |
| 154 | term: params.term |
| 155 | }; |
| 156 | |
| 157 | return $.extend( default_data_to_return, current_data ); |
| 158 | }, |
| 159 | processResults: function ( data ) { |
| 160 | var terms = []; |
| 161 | if ( data ) { |
| 162 | $.each( data, function ( id, text ) { |
| 163 | terms.push( { id: id, text: text } ); |
| 164 | } ); |
| 165 | } |
| 166 | return { |
| 167 | results: terms |
| 168 | }; |
| 169 | }, |
| 170 | cache : true |
| 171 | } |
| 172 | }; |
| 173 | |
| 174 | $( this ).select2( select2_args ).addClass( 'enhanced' ); |
| 175 | |
| 176 | if ( $( this ).data( 'sortable' ) ) { |
| 177 | var $select = $( this ); |
| 178 | var $list = $( this ).next( '.select2-container' ).find( 'ul.select2-selection__rendered' ); |
| 179 | |
| 180 | $list.sortable( { |
| 181 | placeholder : 'ui-state-highlight select2-selection__choice', |
| 182 | forcePlaceholderSize: true, |
| 183 | items : 'li:not(.select2-search__field)', |
| 184 | tolerance : 'pointer', |
| 185 | stop : function () { |
| 186 | $( $list.find( '.select2-selection__choice' ).get().reverse() ).each( function () { |
| 187 | var id = $( this ).data( 'data' ).id; |
| 188 | var option = $select.find( 'option[value="' + id + '"]' )[ 0 ]; |
| 189 | $select.prepend( option ); |
| 190 | } ); |
| 191 | } |
| 192 | } ); |
| 193 | } |
| 194 | } ); |
| 195 | |
| 196 | } ).trigger( 'yith-framework-enhanced-select-init' ); |
| 197 | |
| 198 | } ); |