1/* global asp_ssws_subscribe_form_params */ 2 3jQuery( function( $ ) { 4 'use strict'; 5 6 /** 7 * Is visually blocked? 8 * 9 * @param {JQuery Object} $node 10 */ 11 var is_blocked = function( $node ) { 12 return $node.is( '.processing' ) || $node.parents( '.processing' ).length; 13 }; 14 15 /** 16 * Block a node visually for processing. 17 * 18 * @param {JQuery Object} $node 19 */ 20 var block = function( $node ) { 21 $.blockUI.defaults.overlayCSS.cursor = 'wait'; 22 23 if ( ! is_blocked( $node ) ) { 24 $node.addClass( 'processing' ).block( { 25 message : null, 26 overlayCSS : { 27 background : '#fff', 28 opacity : 0.6 29 } 30 } ); 31 } 32 }; 33 34 /** 35 * Unblock a node after processing is complete. 36 * 37 * @param {JQuery Object} $node 38 */ 39 var unblock = function( $node ) { 40 $node.removeClass( 'processing' ).unblock(); 41 }; 42 43 /** 44 * Handle switch request. 45 */ 46 function handleSwitchRequest() { 47 if ( window.location.href.indexOf( 'switch-subscription' ) != - 1 && window.location.href.indexOf( 'item' ) != - 1 ) { 48 $( '.product form.cart' ).prop( 'action', '' ); 49 } 50 } 51 52 /** 53 * Returns true if the viewing device is Mobile. 54 * 55 * @returns {Boolean} 56 */ 57 function isMobile() { 58 if ( window.matchMedia( "(max-width: 767px)" ).matches ) { 59 return true; 60 } else { 61 return false; 62 } 63 } 64 65 /** 66 * Handle subscribe events via Modal. 67 */ 68 if ( typeof asp_ssws_subscribe_form_params !== 'undefined' ) { 69 $( '.asp-ssws-subscribe-via-modal' ).click( function( e ) { 70 e.preventDefault(); 71 72 var $this = $( this ), 73 wrapperClass = '.asp-product_level-subscribe-wrapper'; 74 75 block( $this ); 76 $.ajax( { 77 type : 'POST', 78 url : asp_ssws_subscribe_form_params.ajax_url, 79 data : { 80 action : 'asp_ssws_subscribe_via_modal', 81 security : asp_ssws_subscribe_form_params.subscribe_via_modal_nonce, 82 product_id : $this.data( 'product-id' ) 83 }, 84 success : function( response ) { 85 if ( response.success ) { 86 $.confirm( { 87 title : response.data.title, 88 content : response.data.html, 89 type : 'blue', 90 boxWidth : isMobile() ? false : '50%', 91 useBootstrap : false, 92 typeAnimated : true, 93 closeIcon : true, 94 onOpen : function() { 95 if ( $( wrapperClass ).length ) { 96 $( wrapperClass ).each( function() { 97 $( this ).asp_product_subscribe_form(); 98 } ); 99 } 100 }, 101 buttons : { 102 signup : { 103 text : asp_ssws_subscribe_form_params.i18n_subscribe_button_text, 104 btnClass : 'button', 105 isHidden : false, 106 isDisabled : false, 107 action : function( button ) { 108 var $wrapper = $( '.jconfirm-content-pane .asp-ssws-subscribe-wrapper' ).closest( '.jconfirm-box' ); 109 block( $wrapper ); 110 $.ajax( { 111 type : 'POST', 112 url : asp_ssws_subscribe_form_params.ajax_url, 113 data : { 114 action : 'asp_ssws_add_to_cart_subscription', 115 security : asp_ssws_subscribe_form_params.add_to_cart_subscription_nonce, 116 product_id : $this.data( 'product-id' ), 117 data : $wrapper.find( ':input[name],select[name]' ).serialize() 118 }, 119 success : function( response ) { 120 if ( response.success ) { 121 $.confirm( { 122 title : asp_ssws_subscribe_form_params.i18n_success_text, 123 content : response.data.message, 124 type : 'green', 125 boxWidth : isMobile() ? false : '25%', 126 useBootstrap : false, 127 typeAnimated : true, 128 closeIcon : true, 129 buttons : { 130 proceedtocart : { 131 text : asp_ssws_subscribe_form_params.i18n_proceed_to_cart_button_text, 132 btnClass : 'button', 133 action : function( button ) { 134 window.location.href = asp_ssws_subscribe_form_params.cart_url; 135 } 136 } 137 } 138 } ); 139 } else { 140 $.dialog( { 141 title : asp_ssws_subscribe_form_params.i18n_error_text, 142 content : response.data.message, 143 type : 'red', 144 boxWidth : isMobile() ? false : '25%', 145 useBootstrap : false, 146 typeAnimated : true, 147 closeIcon : true 148 } ); 149 } 150 }, 151 complete : function() { 152 unblock( $wrapper ); 153 } 154 } ); 155 return false;
156 } 157 } 158 } 159 } ); 160 } else { 161 $.dialog( { 162 title : asp_ssws_subscribe_form_params.i18n_error_text, 163 content : response.data.message, 164 type : 'red', 165 boxWidth : isMobile() ? false : '25%', 166 useBootstrap : false, 167 typeAnimated : true, 168 closeIcon : true 169 } ); 170 } 171 }, 172 complete : function() { 173 unblock( $this ); 174 } 175 } ); 176 return false; 177 } ); 178 } 179 180 /** 181 * Handle variable product subscribe events. 182 */ 183 var variations_form_handle = { 184 variationForm : $( '.variations_form' ), 185 cartForm : $( 'form.cart' ), 186 init : function() { 187 $( document ).on( 'found_variation.wc-variation-form', this.foundVariation ); 188 $( document ).on( 'reset_data', this.resetVariation ); 189 }, 190 foundVariation : function( e, variation ) { 191 variations_form_handle.resetVariation(); 192 193 if ( variation.asp_subscribe_form ) { 194 variations_form_handle.variationForm 195 .find( '.woocommerce-variation-add-to-cart' ) 196 .before( variation.asp_subscribe_form ); 197 variations_form_handle.variationForm 198 .find( '.single_add_to_cart_button' ) 199 .text( variation.asp_single_add_to_cart_text ); 200 201 if ( typeof asp_ssws_subscribe_form_params !== 'undefined' ) { 202 if ( variations_form_handle.variationForm.find( '.asp-product_level-subscribe-wrapper' ).length ) { 203 variations_form_handle.variationForm 204 .find( '.asp-product_level-subscribe-wrapper' ) 205 .each( function() { 206 $( this ).asp_product_subscribe_form(); 207 } ); 208 209 handleSwitchRequest(); 210 } 211 } 212 } 213 }, 214 resetVariation : function() { 215 if ( variations_form_handle.variationForm.find( '.asp-product_level-subscribe-wrapper' ).length ) { 216 variations_form_handle.variationForm 217 .find( '.asp-product_level-subscribe-wrapper' ) 218 .remove(); 219 } 220 221 if ( typeof asp_ssws_subscribe_form_params !== 'undefined' ) { 222 variations_form_handle.variationForm 223 .find( '.single_add_to_cart_button' ) 224 .removeClass( 'asp_single_subscribe_button' ) 225 .text( asp_ssws_subscribe_form_params.i18n_single_add_to_cart_text ); 226 } 227 } 228 }; 229 230 variations_form_handle.init(); 231 232 /** 233 * Handle cart subscribe events. 234 */ 235 var cart_subscribe_form = { 236 init : function() { 237 $( document ).on( 'change', '.asp-cart_level-subscribe-wrapper .asp-ssws-pay-option,.asp-cart_level-subscribe-wrapper .asp-ssws-pay-option-hidden', this.payOptionChanged ); 238 $( document ).on( 'change', '.asp-cart_level-subscribe-wrapper select[name="asp_ssws_subscribe_plan"]', this.planChanged ); 239 $( document ).on( 'change', '.asp-cart_level-subscribe-wrapper select[name="asp_ssws_subscribe_period_interval"]', this.planChanged ); 240 $( document ).on( 'change', '.asp-cart_level-subscribe-wrapper select[name="asp_ssws_subscribe_period"]', this.planChanged ); 241 $( document ).on( 'change', '.asp-cart_level-subscribe-wrapper select[name="asp_ssws_subscribe_length"]', this.planChanged ); 242 243 $( document ).on( 'updated_wc_div, updated_cart_totals', this.cartUpdated ); 244 $( document ).on( 'asp_ssws_cart_level_subscribe_input_changed', this.inputChanged ); 245 246 $( '.asp-cart_level-subscribe-wrapper .asp-ssws-pay-option:checked' ).trigger( 'change' ); 247 }, 248 payOptionChanged : function( e ) { 249 e.preventDefault(); 250 $( document.body ).trigger( 'asp_ssws_cart_level_subscribe_input_changed' ); 251 }, 252 planChanged : function( e ) { 253 e.preventDefault(); 254 $( document.body ).trigger( 'asp_ssws_cart_level_subscribe_input_changed' ); 255 }, 256 cartUpdated : function() { 257 $( document.body ).trigger( 'asp_ssws_update_cart_level_subscribe' ); 258 }, 259 getProcessingNode : function() { 260 if ( $( '.woocommerce-cart-form' ).length ) { 261 return $( '.asp-cart_level-subscribe-wrapper, .cart_totals' ); 262 } else if ( $( '.woocommerce-checkout' ).length ) { 263 return $( '.asp-cart_level-subscribe-wrapper, .woocommerce-checkout-payment, .woocommerce-checkout-review-order-table' ).closest( 'form' ); 264 } else { 265 return $( '.asp-cart_level-subscribe-wrapper' ); 266 } 267 }, 268 inputChanged : function() { 269 block( cart_subscribe_form.getProcessingNode() ); 270 $.ajax( { 271 type : 'POST', 272 url : asp_ssws_subscribe_form_params.ajax_url, 273 data : {
274 action : 'asp_ssws_buy_now_or_subscribe', 275 security : asp_ssws_subscribe_form_params.buynow_or_subscribe_nonce, 276 level : 'cart_level', 277 data : $( '.asp-cart_level-subscribe-wrapper' ).find( ':input[name],select[name]' ).serialize() 278 }, 279 success : function( response ) { 280 if ( response.success ) { 281 $( '.asp-cart_level-subscribe-wrapper' ).find( '.asp-ssws-subscribe-wrapper' ).remove(); 282 $( '.asp-cart_level-subscribe-wrapper' ).append( response.data.html ); 283 284 if ( $( '.woocommerce-cart-form' ).length ) { 285 $( document.body ).trigger( 'wc_update_cart' ); 286 } 287 288 $( document.body ).trigger( 'update_checkout' ); 289 $( document.body ).trigger( 'asp_ssws_update_cart_level_subscribe' ); 290 $( document.body ).trigger( 'asp_ssws_cart_level_subscribe_updated' ); 291 } 292 }, 293 complete : function() { 294 unblock( cart_subscribe_form.getProcessingNode() ); 295 } 296 } ); 297 return false; 298 } 299 }; 300 301 /** 302 * Handle subscribe events. 303 */ 304 $( function() { 305 if ( typeof asp_ssws_subscribe_form_params !== 'undefined' ) { 306 if ( $( '.asp-product_level-subscribe-wrapper' ).length ) { 307 $( '.asp-product_level-subscribe-wrapper' ).each( function() { 308 $( this ).asp_product_subscribe_form(); 309 } ); 310 311 handleSwitchRequest(); 312 } else { 313 cart_subscribe_form.init(); 314 } 315 } 316 } ); 317 318 // Product Add-Ons compat. 319 $( document ).on( 'updated_addons', function() { 320 if ( $( '#product-addons-total .subscription-details' ).length && $( '.asp-product_level-subscribe-wrapper' ).length ) { 321 $( '#product-addons-total' ).find( '.subscription-details' ).hide(); 322 } 323 } ); 324} );
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.