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 setTimeout(function(){ 32 Popup.$self.removeClass('xoo-wl-user-added'); 33 }, 400) 34 35 return false; 36 } 37 }) 38 } 39 } 40 41 Popup.init(); 42 43 44 var Form = function( $form ){ 45 46 var self = this; 47 self.$form = $form;
48 self.$productIDInput = self.$form.find( 'input[name="_xoo_wl_product_id"]' ); 49 self.productID = self.$productIDInput.val(); 50 self.$noticeCont = self.$form.siblings( '.xoo-wl-notices' ); 51 self.$header = self.$form.siblings( '.xoo-wl-header' ); 52 53 self.validationPassed = self.validationPassed.bind(this); 54 self.showNotice = self.showNotice.bind(this); 55 56 self.$form.on( 'submit', { form: self }, self.submit ); 57 58 } 59 60 Form.prototype.submit = function( event ){ 61 62 event.preventDefault(); 63 var form = event.data.form; 64 if( !form.validationPassed() ) return; 65 66 var formData = form.$form.serialize()+'&action=xoo_wl_form_submit', 67 $button = form.$form.find('button[type="submit"]'), 68 buttonHTML = $button.html(); 69 70 $button.html( xoo_wl_localize.html.spinner ).addClass('xoo-wl-processing'); 71 72 $.ajax({ 73 url: xoo_wl_localize.adminurl, 74 type: 'POST', 75 data: formData, 76 success: function(response){ 77 78 $button.removeClass('xoo-wl-processing').html(buttonHTML); 79 80 if( response.notice ){ 81 form.showNotice(response.notice); 82 } 83 else{ 84 console.log(response); 85 } 86 87 if( response.error === 0){ 88 if( Popup.$self.hasClass('xoo-wl-popup-active') ){ 89 Popup.$self.addClass('xoo-wl-user-added'); 90 } 91 form.$form.add(form.$header).hide(); 92 } 93 } 94 }); 95 96 } 97 98 99 Form.prototype.validationPassed = function(){ 100 101 var form = this, 102 errors = [], 103 errorHTML = ''; 104 105 if( !form.productID ){ 106 errors.push( xoo_wl_localize.notices.empty_id ); 107 } 108 109 $.each( errors, function( index, error ){ 110 errorHTML += error; 111 } ) 112 113 form.showNotice(errorHTML); 114 115 return errors.length ? false : true; 116 } 117 118 119 Form.prototype.showNotice = function( notice ){ 120 var form = this 121 form.$noticeCont.html(notice).show(); 122 } 123 124 125 126 $.each( $( 'body' ).find( '.xoo-wl-form' ), function( index, el ){ 127 new Form( $(el) ); 128 } ); 129 130 131 //WooCommerce Product Variation on select 132 $('body').on( 'change', 'form.variations_form .variation_id', function(){ 133 134 var $atcForm = $(this).closest('form.variations_form'), 135 variationsData = $atcForm.data('product_variations'), 136 selectedVariation = $(this).val(), 137 $waitlistContainer = $atcForm.siblings('.xoo-wl-btn-container'); 138 139 if( !$waitlistContainer.length && $waitlistContainer.closest('.product').length ){ 140 $waitlistContainer = $($waitlistContainer.closest('.product').find('.xoo-wl-btn-container').get(0)); 141 } 142 143 if( !$waitlistContainer.length ) return; 144 145 var $waitlistBtn = $waitlistContainer.find( 'button.xoo-wl-open-form-btn' ), 146 $productIDinput = $waitlistContainer.find('input[name="_xoo_wl_product_id"]'); 147 148 $waitlistContainer.hide(); 149 150 151 if( !selectedVariation || selectedVariation == 0 ){ 152 selectedVariation = $atcForm.find('input[name="product_id"]').val(); 153 } 154 155 156 $.each( variationsData, function ( index, variation ) { 157 158 if ( variation.variation_id != selectedVariation ) return; 159 160 let showBtn = false; 161 162 // outofstock 163 if ( xoo_wl_localize.waitlist_show.includes( 'outofstock' ) && ! variation.is_in_stock ) { 164 showBtn = true; 165 } 166 167 // backorder 168 else if ( xoo_wl_localize.waitlist_show.includes( 'backorder' ) && variation.backorders_allowed ) { 169 showBtn = true; 170 } 171 172 // backorder but out of stock 173 else if ( xoo_wl_localize.waitlist_show.includes( 'backorder_out' ) && variation.backorders_allowed && variation.availability_html.includes('available-on-backorder') ) { 174 showBtn = true; 175 } 176 177 // instock 178 else if (xoo_wl_localize.waitlist_show.includes( 'instock' ) && variation.is_in_stock ) { 179 showBtn = true; 180 } 181 182 if ( showBtn ) $waitlistContainer.show(); 183 184 185 return false; 186 187 }); 188 189 190 191 //Set product IDS 192 if( $waitlistBtn.length ){ 193 $waitlistBtn.attr( 'data-product_id', selectedVariation ) 194 } 195 if( $productIDinput.length ){ 196 $productIDinput.val( selectedVariation ); 197 } 198 199 }) 200 201 $('body .variation_id').trigger('change'); 202 203 $('body').on( 'click', 'button.xoo-wl-btn-toggle', function(){ 204 205 var toggleClass = 'xoo-wl-active', 206 $container = $(this).parents('.xoo-wl-btn-container'); 207 208 if( $container.hasClass( toggleClass ) ){ 209 $container.removeClass( toggleClass ) 210 } 211 else{ 212 $container.addClass( toggleClass ).
213 $container.find( 'input[name="_xoo_wl_product_id"]' ).val( $(this).data('product_id') ); 214 } 215 216 } ); 217 218 219})
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.