PageSourceSearch

https://www.priyaldairy.com/js/option_selection_2.1.min.js?v=734

js priyaldairy.com collected 2026-10-02 01:40:23 UTC 7,148 bytes, 156 lines download raw bytes

1if (void 0 === Brand) var Brand = {};
2
3function floatToString(t, e) {
4    var n = t.toFixed(e).toString();
5    return n.match(/^\.\d+/) ? "0" + n : n
6}
7Brand.each = function(t, e) {
8    for (var n = 0; n < t.length; n++) e(t[n], n)
9}, Brand.map = function(t, e) {
10    for (var n = [], r = 0; r < t.length; r++) n.push(e(t[r], r));
11    return n
12}, Brand.arrayIncludes = function(t, e) {
13    for (var n = 0; n < t.length; n++)
14        if (t[n] == e) return !0;
15    return !1
16}, Brand.uniq = function(t) {
17    for (var e = [], n = 0; n < t.length; n++) Brand.arrayIncludes(e, t[n]) || e.push(t[n]);
18    return e
19}, Brand.isDefined = function(t) {
20    return void 0 !== t
21}, Brand.getClass = function(t) {
22    return Object.prototype.toString.call(t).slice(8, -1)
23}, Brand.extend = function(t, e) {
24    function n() {}
25    n.prototype = e.prototype, t.prototype = new n, t.prototype.constructor = t, t.baseConstructor = e, t.superClass = e.prototype
26}, Brand.Product = function(t) {
27    Brand.isDefined(t) && this.update(t)
28}, Brand.Product.prototype.update = function(t) {
29    for (property in t) this[property] = t[property]
30}, Brand.Product.prototype.optionNames = function() {
31    return "Array" == Brand.getClass(this.options) ? this.options : []
32}, Brand.Product.prototype.optionValues = function(t) {
33    if (!Brand.isDefined(this.variants)) return null;
34    var e = Brand.map(this.variants, function(e) {
35        var n = "option" + (t + 1);
36        return null == e[n] ? null : e[n]
37    });
38    return null == e[0] ? null : Brand.uniq(e)
39}, Brand.Product.prototype.getVariant = function(t) {
40    var e = null;
41    return t.length != this.options.length ? e : (Brand.each(this.variants, function(n) {
42        for (var r = !0, o = 0; o < t.length; o++) {
43            n["option" + (o + 1)] != t[o] && (r = !1)
44        }
45        1 != r || (e = n)
46    }), e)
47}, Brand.OptionSelectors = function(t, e) {
48    return this.selectorDivClass = "selector-wrapper", this.selectorClass = "single-option-selector", this.variantIdFieldIdSuffix = "-variant-id", this.variantIdField = null, this.selectors = [], this.domIdPrefix = t, this.product = new Brand.Product(e.product), this.onVariantSelected = Brand.isDefined(e.onVariantSelected) ? e.onVariantSelected : function() {}, this.replaceSelector(t), this.selectors[0].element.onchange(), !0
49}, Brand.OptionSelectors.prototype.replaceSelector = function(t) {
50    var e = document.getElementById(t),
51        n = e.parentNode;
52    Brand.each(this.buildSelectors(), function(t) {
53        n.insertBefore(t, e)
54    }), e.style.display = "none", this.variantIdField = e
55}, Brand.OptionSelectors.prototype.insertSelectors = function(t, e) {
56    Brand.isDefined(e) && this.setMessageElement(e), this.domIdPrefix = "product-" + this.product.id + "-variant-selector";
57    var n = document.getElementById(t);
58    Brand.each(this.buildSelectors(), function(t) {
59        n.appendChild(t)
60    })
61}, Brand.OptionSelectors.prototype.buildSelectors = function() {
62    for (var t = 0; t < this.product.optionNames().length; t++) {
63        var e = new Brand.SingleOptionSelector(this, t, this.product.optionNames()[t], this.product.optionValues(t));
64        e.element.disabled = !1, this.selectors.push(e)
65    }
66    var n = this.selectorDivClass,
67        r = this.product.optionNames();
68    return Brand.map(this.selectors, function(t) {
69        var e = document.createElement("div");
70        if (e.setAttribute("class", n), r.length > 1) {
71            var o = document.createElement("label");
72            o.htmlFor = t.element.id, o.innerHTML = t.name, e.appendChild(o)
73        }
74        return e.appendChild(t.element), e
75    })
76}, Brand.OptionSelectors.prototype.selectedValues = function() {
77    for (var t = [], e = 0; e < this.selectors.length; e++) {
78        var n = this.selectors[e].element.value;
79        t.push(n)
80    }
81    return t
82}, Brand.OptionSelectors.prototype.updateSelectors = function(t) {
83    var e = this.selectedValues(),
84        n = this.product.getVariant(e);
85    n ? (this.variantIdField.disabled = !1, this.variantIdField.value = n.id) : this.variantIdField.disabled = !0, this.onVariantSelected(n, this)
86}, Brand.OptionSelectorsFromDOM = function(t, e) {
87    var n = e.optionNames || [],
88        r = e.priceFieldExists || !0,
89        o = e.delimiter || "/",
90        i = this.createProductFromSelector(t, n, r, o);
91    e.product = i, Brand.OptionSelectorsFromDOM.baseConstructor.call(this, t, e)
92}, Brand.extend(Brand.OptionSelectorsFromDOM, Brand.OptionSelectors), Brand.OptionSelectorsFromDOM.prototype.createProductFromSelector = function(t, e, n, r) {
93    if (!Brand.isDefined(n)) n = !0;
94    if (!Brand.isDefined(r)) r = "/";
95    var o = document.getElementById(t),
96        i = o.childNodes,
97        a = (o.parentNode, e.length),
98        s = [];
99    Brand.each(i, function(t, o) {
100        if (1 == t.nodeType && "option" == t.tagName.toLowerCase()) {
101            var i = t.innerHTML.split(new RegExp("\\s*\\" + r + "\\s*"));
102            0 == e.length && (a = i.length - (n ? 1 : 0));
103            var l = i.slice(0, a),
104                d = n ? i[a] : "",
105                c = (t.getAttribute("value"), {
106                    available: !t.disabled,
107                    id: parseFloat(t.value),
108                    price: d,
109                    option1: l[0],
110                    option2: l[1],
111                    option3: l[2]
112                });
113            s.push(c)
114        }
115    });
116    var l = {
117        variants: s
118    };
119    if (0 == e.length) {
120        l.options = [];
121        for (var d = 0; d < a; d++) l.options[d] = "option " + (d + 1)
122    } else l.options = e;
123    return l
124}, Brand.SingleOptionSelector = function(t, e, n, r) {
125    this.multiSelector = t, this.values = r, this.index = e, this.name = n, this.element = document.createElement("select");
126    for (var o = 0; o < r.length; o++) {
127        var i = document.createElement("option");
128        i.value = r[o], i.innerHTML = r[o], this.element.appendChild(i)
129    }
130    return this.element.setAttribute("class", this.multiSelector.selectorClass), this.element.id = t.domIdPrefix + "-option-" + e, this.element.onchange = function() {
131        t.updateSelectors(e)
132    }, !0
133}, Brand.money_format = "$ {{amount}}", Brand.formatMoney = function(t, e) {
134    "string" == typeof t && (t = t.replace(".", ""));
135    var n = "",
136        r = /\{\{\s*(\w+)\s*\}\}/,
137        o = e || this.money_format;
138
139    function i(t) {
140        return t.replace(/(\d+)(\d{3}[\.,]?)/, "$1,$2")
141    }
142    switch (o.match(r)[1]) {
143        case "amount":
144            n = i(floatToString(t / 100, 2));
145            break;
146        case "amount_no_decimals":
147            n = i(floatToString(t / 100, 0));
148            break;
149        case "amount_with_comma_separator":
150            n = floatToString(t / 100, 2).replace(/\./, ",");
151            break;
152        case "amount_no_decimals_with_comma_separator":
153            n = i(floatToString(t / 100, 0)).replace(/\./, ",")
154    }
155    return o.replace(r, n)
156};

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.