1jQuery(document).ready(function( $ ){ 2 3 4 5 var Popup = { 6 7 $self: $('.xoo-wl-popup'), 8 9 init: function(){ 10 11 Popup.$noticeCont = Popup.$self.find('.xoo-wl-notices'); 12 Popup.$header = Popup.$self.find('.xoo-wl-header'); 13 Popup.$form = Popup.$self.find('.xoo-wl-form'); 14 15 $('body').on( 'click', '.xoo-wl-btn-popup', this.open ); 16 $('.xoo-wl-modal').on( 'click', this.close ); 17 }, 18 19 open: function(e){ 20 Popup.$self.add( $('html, body') ).addClass('xoo-wl-popup-active'); 21 Popup.$self.find( 'input[name="_xoo_wl_product_id"]' ).val( $(this).attr('data-product_id') ); 22 Popup.$form.add(Popup.$header).show(); 23 Popup.$noticeCont.hide(); 24 }, 25 26 close: function( event ){ 27 $.each( event.target.classList, function( key, value ){ 28 if( value == 'xoo-wl-modal' || value == 'xoo-wl-close' ){ 29 $('html, body').add( Popup.$self ).removeClass('xoo-wl-popup-active'); 30 $('body').trigger('xoo_wl_popup_closed'); 31 return false; 32 } 33 }) 34 } 35 } 36 37 Popup.init(); 38 39 40 var Form = function( $form ){ 41 42 var self = this; 43 self.$form = $form;
44 self.$productIDInput = self.$form.find( 'input[name="_xoo_wl_product_id"]' ); 45 self.productID = self.$productIDInput.val(); 46 self.$noticeCont = self.$form.siblings( '.xoo-wl-notices' ); 47 self.$header = self.$form.siblings( '.xoo-wl-header' ); 48 49 self.validationPassed = self.validationPassed.bind(this); 50 self.showNotice = self.showNotice.bind(this); 51 52 self.$form.on( 'submit', { form: self }, self.submit ); 53 54 } 55 56 Form.prototype.submit = function( event ){ 57 58 event.preventDefault(); 59 var form = event.data.form; 60 if( !form.validationPassed() ) return; 61 62 var formData = form.$form.serialize()+'&action=xoo_wl_form_submit'; 63 64 $.ajax({ 65 url: xoo_wl_localize.adminurl, 66 type: 'POST', 67 data: formData, 68 success: function(response){ 69 if( response.notice ){ 70 form.showNotice(response.notice); 71 } 72 else{ 73 console.log(response); 74 } 75 76 if( response.error === 0){ 77 form.$form.add(form.$header).hide(); 78 } 79 } 80 }); 81 82 } 83 84 85 Form.prototype.validationPassed = function(){ 86 87 var form = this, 88 errors = [], 89 errorHTML = ''; 90 91 if( !form.productID ){ 92 errors.push( xoo_wl_localize.notices.empty_id ); 93 } 94 95 $.each( errors, function( index, error ){ 96 errorHTML += error; 97 } ) 98 99 form.showNotice(errorHTML); 100 101 return errors.length ? false : true; 102 } 103 104 105 Form.prototype.showNotice = function( notice ){ 106 var form = this 107 form.$noticeCont.html(notice).show(); 108 } 109 110 111 112 $.each( $( 'body' ).find( '.xoo-wl-form' ), function( index, el ){ 113 new Form( $(el) ); 114 } ); 115 116 117 //WooCommerce Product Variation on select 118 $('body').on( 'change', 'form.variations_form .variation_id', function(){ 119 120 var $atcForm = $(this).parents('form.variations_form'), 121 variationsData = $atcForm.data('product_variations'), 122 selectedVariation = $(this).val(), 123 $waitlistContainer = $atcForm .siblings('.xoo-wl-btn-container'); 124 125 if( !$waitlistContainer.length ) return; 126 127 var $waitlistBtn = $waitlistContainer.find( 'button.xoo-wl-open-form-btn' ), 128 $productIDinput = $waitlistContainer.find('input[name="_xoo_wl_product_id"]'); 129 130 $waitlistContainer.hide(); 131 132 133 if( !selectedVariation || selectedVariation == 0 ){ 134 selectedVariation = $atcForm.find('input[name="product_id"]').val(); 135 } 136 137 $.each( variationsData, function( index, variation ){ 138 139 if( variation.variation_id != selectedVariation || variation.is_in_stock ) return; 140 141 $waitlistContainer.show(); 142 143 return false; 144 } ); 145 146 //Set product IDS 147 if( $waitlistBtn.length ){ 148 $waitlistBtn.attr( 'data-product_id', selectedVariation ) 149 } 150 if( $productIDinput.length ){ 151 $productIDinput.val( selectedVariation ); 152 } 153 154 }) 155 156 $('body .variation_id').trigger('change'); 157 158 $('body').on( 'click', 'button.xoo-wl-btn-toggle', function(){ 159 160 var toggleClass = 'xoo-wl-active', 161 $container = $(this).parents('.xoo-wl-btn-container'); 162 163 if( $container.hasClass( toggleClass ) ){ 164 $container.removeClass( toggleClass ) 165 } 166 else{ 167 $container.addClass( toggleClass ). 168 $container.find( 'input[name="_xoo_wl_product_id"]' ).val( $(this).data('product_id') ); 169 } 170 171 } ); 172 173 174})
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.