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