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