1( function( window, document, $ ) { 2 'use strict'; 3 4 var TMEPOJS; 5 6 function tm_set_subscription_period( epoObject, data ) { 7 var cart_id; 8 var $cart; 9 var subscription_period; 10 var variations_subscription_period; 11 var base; 12 var is_subscription; 13 var is_hidden; 14 var variation_id_selector; 15 var current_variation; 16 var $_cart; 17 var this_epo_totals_container = epoObject.this_epo_totals_container; 18 var main_product = epoObject.main_product; 19 var subscription_sign_up_fee; 20 var formatted_final_total; 21 var nativeProductPriceSelector; 22 var tcAPI = $.tcAPI ? $.tcAPI() : null; 23 var tc_totals_ob; 24 var args; 25 var html; 26 27 this_epo_totals_container.toArray().forEach( function( c ) { 28 var $this = $( c ); 29 tc_totals_ob = $this.data( 'tc_totals_ob' ); 30 cart_id = $this.attr( 'data-cart-id' ); 31 $cart = main_product.find( '.tm-extra-product-options.tm-cart-' + cart_id ); 32 subscription_period = $this.data( 'subscription-period' ); 33 variations_subscription_period = $this.data( 'variations-subscription-period' ); 34 base = $cart.find( '.tmcp-field' ).closest( '.tmcp-field-wrap' ); 35 is_subscription = $this.data( 'is-subscription' ); 36 37 if ( is_subscription ) { 38 base.find( '.tmperiod' ).remove(); 39 40 is_hidden = base.find( '.amount' ).is( '.hidden' ); 41 if ( is_hidden ) { 42 is_hidden = ' hidden'; 43 } else { 44 is_hidden = ''; 45 } 46 47 variation_id_selector = "input[name^='variation_id']"; 48 $_cart = $this.data( 'tm_for_cart' ); 49 50 if ( $_cart ) { 51 if ( $_cart.find( 'input.variation_id' ).length > 0 ) { 52 variation_id_selector = 'input.variation_id'; 53 } 54 current_variation = $_cart.find( variation_id_selector ).val(); 55 if ( ! current_variation ) { 56 current_variation = 0; 57 } 58 if ( variations_subscription_period[ $.epoAPI.math.toFloat( current_variation ) ] ) { 59 subscription_period = variations_subscription_period[ $.epoAPI.math.toFloat( current_variation ) ]; 60 } 61 } 62 63 base.find( '.amount' ).not( '.amount .amount' ).after( '<span class="tmperiod' + is_hidden + '"> ' + subscription_period + '</span>' ); 64 65 $this.find( '.tmperiod' ).remove(); 66 $this 67 .find( '.amount.options' ) 68 .after( '<span class="tmperiod">' + ' ' + subscription_period + '</span>' ); 69 $this 70 .find( '.amount.final' ) 71 .after( '<span class="tmperiod">' + ' ' + subscription_period + '</span>' ); 72 73 if ( tcAPI ) { 74 if ( tc_totals_ob ) { 75 subscription_sign_up_fee = tc_totals_ob.subscription_sign_up_fee; 76 args = { 77 symbol: '', 78 format: '', 79 decimal: tcAPI.localDecimalSeparator, 80 thousand: tcAPI.localThousandSeparator, 81 precision: TMEPOJS.currency_format_num_decimals 82 }; 83 formatted_final_total = $.epoAPI.applyFilter( 'tc_formatPrice', $.epoAPI.math.format( tc_totals_ob.product_total_price, args ), args ); 84 if ( subscription_sign_up_fee ) { 85 subscription_sign_up_fee = $.epoAPI.applyFilter( 'tc_formatPrice', $.epoAPI.math.format( subscription_sign_up_fee, args ), args ); 86 } 87 } 88 if ( epoObject.is_associated ) { 89 nativeProductPriceSelector = epoObject.main_product.find( tcAPI.associatedNativeProductPriceSelector ); 90 } else { 91 nativeProductPriceSelector = $( tcAPI.nativeProductPriceSelector ); 92 } 93 94 if ( subscription_sign_up_fee && formatted_final_total ) { 95 html = $.epoAPI.util.decodeHTML( 96 $.epoAPI.template.html( tcAPI.templateEngine.tc_formatted_price, { 97 price: formatted_final_total 98 } ) 99 ); 100 html = data.replace_suffixes_in_html( html, formatted_final_total, this_epo_totals_container ); 101 html = html + ' ' + 102 subscription_period + 103 ' ' + TMEPOJS.i18n_and_a + ' ' + 104 $.epoAPI.util.decodeHTML( 105 $.epoAPI.template.html( tcAPI.templateEngine.tc_formatted_price, { 106 price: subscription_sign_up_fee 107 } ) 108 ) + ' ' + 109 TMEPOJS.i18n_sign_up_fee; 110 html = data.replace_suffixes_in_html( html, subscription_sign_up_fee, this_epo_totals_container ); 111 nativeProductPriceSelector 112 .html( html ) 113 .show(); 114 }
114 else if ( formatted_final_total !== undefined ) { 115 html = $.epoAPI.util.decodeHTML( 116 $.epoAPI.template.html( tcAPI.templateEngine.tc_formatted_price, { 117 price: formatted_final_total 118 } ) 119 ) + ' ' + subscription_period; 120 html = data.replace_suffixes_in_html( html, formatted_final_total, this_epo_totals_container ); 121 nativeProductPriceSelector 122 .html( html ) 123 .show(); 124 } 125 } 126 } 127 } ); 128 } 129 130 function tc_adjust_tc_totals_ob( tc_totals_ob, data ) { 131 var subscription_options_total = 0; 132 var formatted_subscription_fee_total = ''; 133 var subscription_sign_up_fee; 134 var subscription_total; 135 var show_sign_up_fee = false; 136 var showTotal = data.showTotal; 137 var epoHolder = data.epoHolder; 138 var totalsHolder = data.totalsHolder; 139 var tm_set_price_totals = data.tm_set_price_totals; 140 var product_and_subscription_total = 0; 141 var formatted_product_and_subscription_total = ''; 142 143 epoHolder 144 .find( '.tmcp-sub-fee-field' ) 145 .filter( '.tcenabled' ) 146 .toArray() 147 .forEach( function( field ) { 148 var option_price = 0; 149 var options; 150 151 field = $( field ); 152 153 if ( field.is( ':checkbox, :radio, :input' ) ) { 154 if ( field.is( '.tmcp-checkbox, .tmcp-radio' ) ) { 155 if ( field.is( ':checked' ) ) { 156 option_price = field.data( 'raw_price' ); 157 showTotal = true; 158 field.data( 'isset', 1 ); 159 } else { 160 field.data( 'isset', 0 ); 161 } 162 } else if ( field.is( '.tmcp-select' ) ) { 163 option_price = field.find( 'option:selected' ).data( 'raw_price' ); 164 options = field.children( 'option:selected' ); 165 if ( ! ( options.val() === '' && options.attr( 'data-rulestype' ) === '' ) ) { 166 showTotal = true; 167 } 168 field.find( 'option' ).data( 'isset', 0 ); 169 field.find( 'option:selected' ).data( 'isset', 1 ); 170 } else if ( field.val() ) { 171 option_price = field.data( 'raw_price' ); 172 showTotal = true; 173 field.data( 'isset', 1 ); 174 } else { 175 field.data( 'isset', 0 ); 176 } 177 if ( ! option_price ) { 178 option_price = 0; 179 } 180 181 if ( field.is( '.tmcp-sub-fee-field' ) ) { 182 subscription_options_total = parseFloat( subscription_options_total ) + parseFloat( option_price ); 183 } 184 } 185 } ); 186 187 if ( totalsHolder.data( 'is-subscription' ) ) { 188 subscription_sign_up_fee = parseFloat( totalsHolder.data( 'subscription-sign-up-fee' ) ); 189 if ( ! Number.isFinite( subscription_sign_up_fee ) ) { 190 subscription_sign_up_fee = 0; 191 } 192 subscription_total = subscription_sign_up_fee + parseFloat( subscription_options_total ); 193 if ( ! Number.isFinite( subscription_total ) ) { 194 subscription_total = 0; 195 } 196 if ( subscription_total ) { 197 show_sign_up_fee = true; 198 } 199 subscription_total = data.tm_set_tax_price( subscription_total, totalsHolder, undefined, undefined, undefined, undefined, true ); 200 formatted_subscription_fee_total = tm_set_price_totals( subscription_total, totalsHolder, true ); 201 202 product_and_subscription_total = parseFloat( data.product_total_price ) + parseFloat( subscription_total ); 203 if ( ! Number.isFinite( product_and_subscription_total ) ) { 204 product_and_subscription_total = 0; 205 } 206 product_and_subscription_total = data.tm_set_tax_price( product_and_subscription_total, totalsHolder, undefined, undefined, undefined, undefined, true ); 207 formatted_product_and_subscription_total = tm_set_price_totals( product_and_subscription_total, totalsHolder, true ); 208 } 209 210 tc_totals_ob.formatted_subscription_fee_total = formatted_subscription_fee_total; 211 tc_totals_ob.subscription_sign_up_fee = subscription_total; 212 tc_totals_ob.show_sign_up_fee = show_sign_up_fee; 213 tc_totals_ob.product_and_subscription_total = product_and_subscription_total; 214 tc_totals_ob.formatted_product_and_subscription_total = formatted_product_and_subscription_total; 215 tc_totals_ob.sign_up_fee = TMEPOJS.i18n_subscription_sign_up_fee; 216 tc_totals_ob.showTotal = showTotal; 217 218 tc_totals_ob = data.replace_suffixes( 'formatted_subscription_fee_total', 'subscription_sign_up_fee', tc_totals_ob, totalsHolder ); 219 tc_totals_ob = data.replace_suffixes( 'formatted_product_and_subscription_total', 'product_and_subscription_total', tc_totals_ob, totalsHolder ); 220 221 return tc_totals_ob; 222 } 223 224 // document ready 225 $( function() { 226 TMEPOJS = window.TMEPOJS || null; 227 228 if ( ! TMEPOJS ) { 229 return; 230 } 231 232 $( window ).on( 'tm-epo-init-end', function( event, eventData ) { 233 if ( event && eventData && eventData.epo ) { 234 tm_set_subscription_period( eventData.epo, eventData.data ); 235 } 236 } ); 237 238 $( window ).on( 'tc-epo-after-update', function( event, eventData ) { 239 if ( event && eventData && eventData.data && eventData.data.epo_object ) { 240 tm_set_subscription_period( eventData.data.epo_object, eventData.data ); 241 } 242 } ); 243 244 $( window ).on( 'tm-epo-found-variation', function( event, eventData ) { 245 var totalsHolder; 246 var variation; 247 var variations; 248 249 if ( event && eventData && eventData.epo ) { 250 totalsHolder = eventData.totalsHolder; 251 variation = eventData.variation; 252 variations = totalsHolder.data( 'variations' ); 253 254 if ( variations && variation && variation.variation_id ) { 255 if ( variation.tc_subscription_sign_up_fee !== undefined ) { 256 totalsHolder.data( 'subscription-sign-up-fee', variation.tc_subscription_sign_up_fee ); 257 } else {
258 totalsHolder.data( 'subscription-sign-up-fee', 0 ); 259 } 260 261 if ( variation.tc_subscription_period !== undefined ) { 262 totalsHolder.data( 'subscription-period', variation.tc_subscription_period ); 263 } 264 } 265 } 266 } ); 267 268 $.epoAPI.addFilter( 'tc_adjust_tc_totals_ob', tc_adjust_tc_totals_ob, 10, 2 ); 269 } ); 270}( window, document, window.jQuery ) );
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.