1jQuery(document).ready(function($){ 2 3 4 5 (function(){ 6 //initialize datepicker 7 if( xoo_aff_localize.datepicker_data ){ 8 var data = JSON.parse( xoo_aff_localize.datepicker_data ); 9 if( $.isEmptyObject( data ) ) return; 10 $.each( data, function( index, field ){ 11 $( 'input[name='+field.id+']' ).datepicker(field.args); 12 } ) 13 } 14 15 }()); 16 17 18 var all_states = JSON.parse(xoo_aff_localize.states); 19 20 //-------------------- XXXXXXXXXXXXXXX -------------------- // 21 22 var SelectCountry = function( $select ){ 23 24 var self = this; 25 self.$selectCountry = $select; 26 self.id = self.$selectCountry.attr('id'); 27 self.$form = self.$selectCountry.closest( 'form' ); 28 self.$selectState = self.$form.find('.xoo-aff-states[data-country_field="'+self.id+'"]'); 29 self.$selectPhoneCode = self.$form.find('.xoo-aff-phone_code[data-country_field="'+self.id+'"]'); 30 31 //Methods 32 self.states = self.$selectState.length ? self.states() : false; 33 //Events 34 self.$selectCountry.on( 'change', { country: self }, this.onChange ); 35 self.$selectCountry.trigger('change'); //on load 36 37 } 38 39 SelectCountry.prototype.onChange = function( event ){ 40 var self = event.data.country; 41 if( self.states ){ 42 self.states.updateStateField( event ); 43 } 44 45 if( self.$selectPhoneCode.length ){ 46 self.updatePhoneCodeField(); 47 } 48 } 49 50 //PhoneCode field handler 51 SelectCountry.prototype.updatePhoneCodeField = function(){ 52 var country = this, 53 $codeOption = country.$selectPhoneCode.find( 'option[value="'+country.$selectCountry.val()+'"]' ); 54 55 if( $codeOption ){ 56 $codeOption.prop('selected','selected'); 57 } 58 } 59 60 //State field handler 61 SelectCountry.prototype.states = function(){ 62 63 var country = this, 64 $selectState = country.$selectState; 65 66 var Handler = { 67 68 init: function(){ 69 Handler.$statePlaceholder = $selectState.find('option[value="placeholder"]'); 70 Handler.$selectStateCont = $selectState.closest('.xoo-aff-input-group') 71 Handler.$inputState = Handler.createStateInput(); 72 }, 73 74 getStates: function(){ 75 var states = all_states[ country.$selectCountry.val() ]; 76 return states === undefined || states.length === 0 ? null : states; 77 }, 78 79 createStateInput: function(){ 80 return $( '<input type="text" />' ) 81 .prop( 'id', $selectState.attr('id') ) 82 .prop( 'name', $selectState.attr('name') ) 83 .prop('placeholder', Handler.$statePlaceholder.html() ) 84 .addClass( $selectState.attr('class') ); 85 }, 86 87 updateStateField: function( event ){ 88 89 var country = event.data.country; 90 91 //Remove all current states 92 $selectState.find('option').not(Handler.$statePlaceholder).remove(); 93 94 if( country.$selectCountry.val() ){ 95 var active_states = Handler.getStates(); 96 97 if( !active_states ){ 98 $selectState.remove(); 99 Handler.$selectStateCont.append( Handler.$inputState ); 100 } 101 else{ 102 Handler.$inputState.remove(); 103 Handler.$selectStateCont.append( $selectState ); 104 $.each( active_states, function( state_key, label ){ 105 $selectState.append( '<option value="'+state_key+'">'+label+'</option>' ); 106 } ) 107 } 108 } 109 110 } 111 112 } 113 114 Handler.init(); 115 116 return Handler; 117 } 118 119 $.each( $('select.xoo-aff-country'), function( index, el ){ 120 new SelectCountry( $(el)); 121 } ); 122 123 124 125})
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.