PageSourceSearch

https://www.bioforce.co.nz/process/x_g/cdX4gW01-QkvTkMyb/mv_displa…nents_ProductDisplay_CatView3_split_test.js

js bioforce.co.nz collected 2026-10-02 23:24:05 UTC 3,655 bytes, 94 lines download raw bytes

1if ( !document.IncludedFiles ) document.IncludedFiles = [];
2document.IncludedFiles['https://www.bioforce.co.nz/process/x_g/cdX4gW01%2dQkvTkMyb/mv_display/components_ProductDisplay_CatView3_split_test.js'] = 1;
3//Included: components/ProductDisplay/CatView3/split_test.js
4(function() {
5	var productOverride = window.productOverride = {
6
7		/**
8		 * fuction for reloading all products over ajax & applying the changes to the interface
9		 * @param selector 	{Object} 	containing the object of an element
10		 * @param value 	{string} 	containing the value for overrding the data
11		 */
12		override:function(selector, value){
13			selector.innerHTML = value;
14		},
15
16		/**
17		 * receive a string of promotion, and create an element for a new feature protion label
18		 *
19		 * @param {string} promotion - containing promotion label
20		 */
21		promotionLabel:function(promotion){
22			var stringCount = promotion.length;
23			var classes = ["feature"];
24			if(stringCount > 4){
25				classes.push("long");
26			}
27
28			// creating a bytes of receive promotion label string
29			var bytes = [];
30			for (var i = 0; i < stringCount; ++i) {
31				var code = promotion.charCodeAt(i);
32				bytes = bytes.concat([code & 0xff, code / 256 >>> 0]);
33			}
34
35			// join the array of bytes
36			// and create feature class according to the result
37			var numbers = bytes.join('');
38			classes.push('feature-' + ('%d', (numbers % 3) + 1));
39			var featured_class = classes.join(' ');
40
41			// create new element for override feature
42			var newFeature = document.createElement('mark');
43			newFeature.className = featured_class;
44			newFeature.innerText = promotion;
45			return newFeature;
46		},
47
48		/**
49		 * fuction for overriding the product elements
50		 * @param split_test 	{Object} 	containing the object of split test data
51		 */
52		overrideData: function(split_test){
53			var wrap = document.querySelector('.product-collection');
54			for (x in split_test) {
55				var productWrapper = wrap.querySelector(".product-card[data-sku='" + split_test[x].sku +"']");
56				if(productWrapper && split_test[x].version == 'alternate') {
57
58					// inject the override text for the product title
59					var title = productWrapper.querySelector('[data-property="title"] a') || productWrapper.querySelector(".item-title");
60					productOverride.override(title, split_test[x].title)
61
62					// inject the override promotion label if exist otherwise create one
63					var feature = productWrapper.querySelector('[data-property="feature"]') || productWrapper.querySelector(".feature");
64					if(feature && split_test[x].label){
65						productOverride.override(feature, split_test[x].label);
66					}else if(split_test[x].label){
67						var newFeature = productOverride.promotionLabel(split_test[x].label);
68						productWrapper.querySelector('header').appendChild(newFeature);
69					}
70					var productFooter = productWrapper.querySelector("footer");
71					var originalPrice = productFooter.querySelector('.original-price');
72					if(originalPrice){
73						productFooter.removeChild(originalPrice);
74					}
75					if(split_test[x].no_format.discount > 0) {
76
77						// create a new flat price element
78						// inject the override text
79						// then insert it on footer
80						var newOriginalPrice = document.createElement('s');
81						newOriginalPrice.className = "original-price";
82						newOriginalPrice.innerText = split_test[x].flat;
83						productFooter.insertBefore(newOriginalPrice, productFooter.firstChild);
84					}
85
86					// inject the override text for the product price
87					productOverride.override(productWrapper.querySelector(".price"), split_test[x].unit);
88				}
89			}
90		}
91	}
92	document.querySelector('#catview-list').classList.remove('split-test');
93})();
94

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.