1// global srp_enhanced_params. 2jQuery( function( $ ) { 3 'use strict' ; 4 5 function getEnhancedSelectFormatString() { 6 return { 7 'language' : { 8 errorLoading : function() { 9 // Workaround for https://github.com/select2/select2/issues/4355 instead of i18n_ajax_error. 10 return srp_enhanced_params.i18n_searching ; 11 } , 12 inputTooLong : function( args ) { 13 var overChars = args.input.length - args.maximum ; 14 15 if( 1 === overChars ) { 16 return srp_enhanced_params.i18n_input_too_long_1 ; 17 } 18 19 return srp_enhanced_params.i18n_input_too_long_n.replace( '%qty%' , overChars ) ; 20 } , 21 inputTooShort : function( args ) { 22 var remainingChars = args.minimum - args.input.length ; 23 24 if( 1 === remainingChars ) { 25 return srp_enhanced_params.i18n_input_too_short_1 ; 26 } 27 28 return srp_enhanced_params.i18n_input_too_short_n.replace( '%qty%' , remainingChars ) ; 29 } , 30 loadingMore : function() { 31 return srp_enhanced_params.i18n_load_more ; 32 } , 33 maximumSelected : function( args ) { 34 if( args.maximum === 1 ) { 35 return srp_enhanced_params.i18n_selection_too_long_1 ; 36 } 37 38 return srp_enhanced_params.i18n_selection_too_long_n.replace( '%qty%' , args.maximum ) ; 39 } , 40 noResults : function() { 41 return srp_enhanced_params.i18n_no_matches ; 42 } , 43 searching : function() { 44 return srp_enhanced_params.i18n_searching ; 45 } 46 } 47 } ; 48 } 49 50 try { 51 $( document.body ).on( 'srp-enhanced-init' , function( ) { 52 if( $( 'select.srp_select2' ).length ) { 53 //Select2 with customization 54 $( 'select.srp_select2' ).each( function( ) { 55 var select2_args = { 56 allowClear : $( this ).data( 'allow_clear' ) ? true : false , 57 placeholder : $( this ).data( 'placeholder' ) , 58 minimumResultsForSearch : 10 , 59 } ; 60 61 if( parseFloat( srp_enhanced_params.srp_wc_version ) > parseFloat( '2.2.0' ) ) { 62 $( this ).select2( select2_args ) ; 63 } else { 64 $( this ).chosen( select2_args ) ; 65 } 66 } ) ; 67 } 68 if( $( 'select.rs-pages-and-posts-search' ).length ) { 69 // Ajax pages and posts search boxes. 70 $( 'select.rs-pages-and-posts-search' ).each( function() { 71 var select2_args = { 72 allowClear : $( this ).data( 'allow_clear' ) ? true : false , 73 placeholder : $( this ).data( 'placeholder' ) , 74 minimumInputLength : $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : 3 , 75 escapeMarkup : function( m ) { 76 return m ; 77 } , 78 ajax : { 79 url : srp_enhanced_params.ajax_url , 80 dataType : 'json' , 81 delay : 250 , 82 data : function( params ) { 83 return { 84 term : params.term , 85 action : 'json_search_pages_and_posts' , 86 sumo_security : srp_enhanced_params.fp_pages_and_posts_search_nonce , 87 exclude : $( this ).data( 'exclude' ) 88 } ; 89 } , 90 processResults : function( data ) { 91 var terms = [ ] ; 92 if( data ) { 93 $.each( data , function( id , text ) { 94 terms.push( { 95 id : id , 96 text : text 97 } ) ; 98 } ) ; 99 } 100 return { 101 results : terms 102 } ; 103 } , 104 cache : true 105 } } ; 106 107 select2_args = $.extend( select2_args , getEnhancedSelectFormatString() ) ; 108 109 $( this ).selectWoo( select2_args ).addClass( 'enhanced' ) ; 110 } ) ; 111 } 112 113 if ( $( 'select.srp_select2_search' ).length ) { 114 //Multiple select with ajax search 115 $( 'select.srp_select2_search' ).each( function () { 116 117 var select2_args = { 118 allowClear : $( this ).data( 'allow_clear' ) ? true : false , 119 placeholder : $( this ).data( 'placeholder' ) , 120 minimumInputLength : $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : 3 , 121 escapeMarkup : function ( m ) { 122 return m ; 123 } , 124 ajax : { 125 url : srp_enhanced_params.ajax_url , 126 dataType : 'json' , 127 delay : 250 , 128 data : function ( params ) { 129 return { 130 term : params.term , 131 action : $( this ).data( 'action' ) ? $( this ).data( 'action' ) : '' , 132 srp_security : $( this ).data( 'nonce' ) ? $( this ).data( 'nonce' ) : srp_enhanced_params.search_nonce , 133 } ; 134 } , 135 processResults : function ( data ) { 136 var terms = [ ] ; 137 if ( data ) { 138 $.each( data , function ( id , term ) { 139 terms.push( { 140 id : id , 141 text : term 142 } ) ; 143 } ) ; 144 } 145 return { 146 results : terms 147 } ; 148 } , 149 cache : true 150 } 151 } ; 152 153 $( this ).select2( select2_args ) ; 154 } ) ; 155 } 156 157 if ( $( '.srp_datepicker' ).length ) { 158 $( '.srp_datepicker' ).on( 'change' , function ( ) { 159 if ( $( this ).val() === '' ) { 160 $( this ).next( ".srp_alter_datepicker_value" ).val( '' ) ; 161 } 162 } ) ; 163 164 $( '.srp_datepicker' ).each( function ( ) { 165 $( this ).datepicker( { 166 altField : $( this ).next( ".srp_alter_datepicker_value" ) , 167 altFormat : 'yy-mm-dd' , 168 changeMonth : true , 169 changeYear : true 170 } ) ; 171 } ) ; 172 } 173 } ) ; 174 $( document.body ).trigger( 'srp-enhanced-init' ) ; 175 176 if ( parseFloat( srp_enhanced_params.srp_wc_version) <= ( '2.2.0' ) ){ 177 $( 'select.rs-customer-search' ).ajaxChosen( { 178 method : 'GET' , 179 url : srp_enhanced_params.ajax_url , 180 dataType : 'json' , 181 afterTypeDelay : 100 , 182 data : { 183 action : 'woocommerce_json_search_customers' , 184 security : srp_enhanced_params.search_customers 185 } 186 } , function ( data ) { 187 var terms = { } ; 188 189 $.each( data , function ( i , val ) { 190 terms[i] = val ; 191 } ) ; 192 return terms ; 193 } ) ; 194 195 $( "select.rs-product-search" ).ajaxChosen( { 196 method : 'GET' , 197 url : srp_enhanced_params.ajax_url , 198 dataType : 'json' , 199 afterTypeDelay : 100 , 200 data : { 201 action : 'woocommerce_json_search_products_and_variations' , 202 security : srp_enhanced_params.search_products 203 } 204 } , function ( data ) { 205 var terms = { } ; 206 207 $.each( data , function ( i , val ) { 208 terms[i] = val ; 209 } ) ; 210 return terms ; 211 } ) ; 212 } 213 } catch( err ) { 214 window.console.log( err ) ; 215 } 216 217} ) ;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.