1(function ($) { 2 "use strict"; 3 4 $.widget("pektsekye.pofwProductOptions", { 5 6 optionPrices : {}, 7 valuePrices : {}, 8 9 10 _create : function () { 11 12 $.extend(this, this.options); 13 14 this.priceDiv = this.isOnSale ? $('#product-'+ this.productId +' .summary ins .woocommerce-Price-amount') : $('#product-'+ this.productId +' .summary .woocommerce-Price-amount'); 15 16 var bdi = this.priceDiv.find('bdi'); 17 if (bdi.length){ 18 this.priceDiv = bdi; 19 } 20 21 this.form = this.element.closest('form'); 22 23 this.form.on("submit", $.proxy(this.validate, this)); 24 25 this._on({ 26 "change .pofw-option" : $.proxy(this.updatePrice, this) 27 }); 28 }, 29 30 31 updatePrice : function(){ 32 var el,vId,vIds,ll; 33 34 var price = this.productPrice; 35 36 var elements = this.element.find('.pofw-option'); 37 38 var l = elements.length; 39 while (l--){ 40 el = $(elements[l]); 41 42 if (el[0].type == 'select-one'){ 43 vId = el.val(); 44 if (vId && this.valuePrices[vId]){ 45 price += this.valuePrices[vId]; 46 } 47 } else if (el[0].type == 'select-multiple'){ 48 vIds = el.val(); 49 if (vIds){ 50 ll = vIds.length; 51 while (ll--){ 52 vId = vIds[ll]; 53 if (this.valuePrices[vId]){ 54 price += this.valuePrices[vId]; 55 } 56 } 57 } 58 } else if (el[0].type == 'radio' || el[0].type == 'checkbox'){ 59 if (el[0].checked){ 60 vId = el[0].value; 61 if (vId && this.valuePrices[vId]){ 62 price += this.valuePrices[vId]; 63 } 64 } 65 } else if (el[0].type == 'text' || el[0].type == 'textarea'){ 66 if (el.val() != ''){ 67 var startIndex = el[0].name.indexOf('[') + 1; 68 var endIndex = el[0].name.indexOf(']'); 69 var oId = parseInt(el[0].name.substring(startIndex, endIndex), 10); 70 if (this.optionPrices[oId]){ 71 price += this.optionPrices[oId]; 72 } 73 } 74 } 75 } 76 77 var formatedPrice = price.toFixed(this.numberOfDecimals).replace('.', this.decimalSeparator); 78 79 formatedPrice = this.addThousendSeparator(formatedPrice); 80 81 if (this.currencyPosition == 'left_space'){ 82 formatedPrice = ' ' + formatedPrice; 83 } else if (this.currencyPosition == 'right_space'){ 84 formatedPrice += ' '; 85 } 86 87 if (this.currencyPosition == 'left' || this.currencyPosition == 'left_space'){ 88 this.priceDiv.contents().last()[0].textContent = formatedPrice; 89 } else { 90 this.priceDiv.contents().first()[0].textContent = formatedPrice; 91 } 92 }, 93 94 95 validate : function(){ 96 var firstNotValidInput; 97 98 var formValid = true; 99 100 this.element.find('.pofw-required.pofw-not-valid').removeClass('pofw-not-valid'); 101 this.element.find('.pofw-required .pofw-required-text').remove(); 102 103 var requiredText = this.requiredText; 104 this.element.find('.pofw-required').each(function(index, el) { 105 var valid = true; 106 var optionRow = $(el); 107 var input = optionRow.find('.pofw-option').first(); 108 if (input[0].type == 'select-one' || input[0].type == 'select-multiple'){ 109 valid = input.val() != '' && input.val() != null; 110 } else if (input[0].type == 'radio' || input[0].type == 'checkbox'){ 111 valid = optionRow.find('.pofw-option:checked').length > 0; 112 } else if (input[0].type == 'text' || input[0].type == 'textarea'){ 113 valid = input.val() != ''; 114 } 115 116 if (!valid){ 117 optionRow.addClass('pofw-not-valid'); 118 optionRow.append('<div class="pofw-required-text">'+ requiredText +'</div>'); 119 if (firstNotValidInput == undefined){ 120 firstNotValidInput = input; 121 } 122 formValid = false; 123 } 124 }); 125 126 if (firstNotValidInput != undefined){ 127 firstNotValidInput.focus(); 128 } 129 130 return formValid; 131 }, 132 133 addThousendSeparator : function(nStr){ 134 if (this.thousandSeparator == ''){ 135 return nStr; 136 } 137 nStr += ''; 138 var x = nStr.split('.'); 139 var x1 = x[0]; 140 var x2 = x.length > 1 ? '.' + x[1] : ''; 141 var rgx = /(\d+)(\d{3})/; 142 while (rgx.test(x1)) { 143 x1 = x1.replace(rgx, '$1' + this.thousandSeparator + '$2'); 144 } 145 return x1 + x2; 146 } 147 148 }); 149 150})(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.