1var productHistory = new function () { 2 this.isUserLoggedIn = null; 3 this.productList = new Array(); 4 var self = this; 5 this.currencySymbol = '$'; 6 7 this.addToList = function (productDetails) { 8 //If the product is in the history already, delete it and add it to the first place 9 var exists = this.removeIfExists(productDetails); 10 11 this.productList.unshift(productDetails); 12 13 //if there are more than 5 products, remove the last one 14 if (this.productList.length > 5) { 15 this.productList.pop(); 16 } 17 18 return exists; 19 } 20 21 this.addToHistory = function(productDetails) { 22 var exists = this.addToList(productDetails); 23 24 if (!exists && this.isUserLoggedIn && !productDetails.isSaved) { 25 ns$.ajax({ 26 url: '/api/1.0/Product/index.aspx?historyProductIds=' + productDetails.id, 27 type: "POST", 28 data: { postData: '{}' }, 29 contentType: "application/json;charset=utf-8", 30 }); 31 32 productDetails.isSaved = true; 33 } 34 35 ns$.jStorage.set("productHistory", this.productList); 36 } 37 38 this.removeIfExists = function(productDetails) { 39 var result = ns$.grep(this.productList, function (e) { return e.id == productDetails.id; }); 40 if (result.length == 0) return false; 41 productDetails.isSaved = result[0].isSaved; 42 this.productList.splice(this.productList.indexOf(result[0]), 1); 43 return true; 44 } 45 46 this.isUserAuthenticated = function() { 47 if (this.isUserLoggedIn == null) { 48 this.isUserLoggedIn = (ns$(".product-history-isUserLoggedIn").first().val() == "True"); 49 } 50 return this.isUserLoggedIn; 51 } 52 53 this.retrieveProductHistory = function () { 54 if (this.isUserAuthenticated()) { 55 this.syncClientHistory(); 56 } 57 else { 58 this.getLocalHistory(); 59 } 60 if (!this.productList) this.productList = new Array(); 61 } 62 63 this.renderProductHistory = function (amount, sender) { 64 if (this.productList.length > 0) 65 var maxItems; 66 67 if (amount > this.productList.length) 68 maxItems = this.productList.length; 69 else 70 maxItems = amount; 71 $sender = ns$("#" + sender); 72 73 if (maxItems > 0) { 74 $("#" + sender).closest(".product-history-module-container").show(); 75 } 76 77 for (i = 0; i < maxItems; i++) { 78 var showPrice = ($sender.find(".product-history-showprice").val() == "True"); 79 var showThumb = ($sender.find(".product-history-showthumb").val() == "True"); 80 this.currencySymbol = ($sender.find(".product-history-currency").val()); 81 82 var productHistoryLayout = '<div class="featured-products-item">' + 83 '<a href="' + this.productList[i].url + '">' + this.productList[i].name + '</a>' 84 85 if (showThumb && !this.productList[i].img == '') { 86 productHistoryLayout = productHistoryLayout + 87 '<div class="featured-products-item-img"><a href="' + this.productList[i].url + '">' + 88 '<img src="' + this.productList[i].img + '"/></a></div>' 89 } 90 91 if (showPrice) { 92 productHistoryLayout = productHistoryLayout + '<div class="featured-products-item-price">' + this.productList[i].price + '</div>' 93 } 94 95 productHistoryLayout = productHistoryLayout + '</div>' 96 97 $sender.append(productHistoryLayout); 98 } 99 } 100 101 this.syncClientHistory = function() { 102 this.getLocalHistory(); 103 104 if (!this.productList) {
105 this.getServerHistory(''); 106 } else { 107 var result = ns$.grep(this.productList, function (e) { return e.isSaved == false; }); 108 109 if (result.length > 0) { 110 var ProductIds = ''; 111 112 for (i = 0; i < result.length; i++) { 113 ProductIds = ProductIds + result[i].id + ','; 114 } 115 116 ProductIds = ProductIds.substring(0, ProductIds.length - 1) 117 118 this.getServerHistory(ProductIds); 119 } 120 } 121 } 122 123 this.getLocalHistory = function() { 124 this.productList = ns$.jStorage.get("productHistory"); 125 } 126 127 this.getServerHistory = function(productIds) { 128 ns$.ajax({ 129 url: '/api/1.0/Product/index.aspx?historyProductIds=' + productIds, 130 type: "POST", 131 data: { postData: '{}' }, 132 contentType: "application/json;charset=utf-8", 133 success: function (data) { 134 for (i = 0; i < data.length; i++) { 135 var productDetails = {}; 136 productDetails.id = data[i]._id; 137 productDetails.url = data[i]._virtualUrl.replace('~', ''); 138 if (data[i]._imageGallery) { 139 if(data[i]._imageGallery.length >= 1) productDetails.img = data[i]._imageGallery[0]._thumbnailImage._path; 140 } 141 else { 142 productDetails.img = ''; 143 } 144 productDetails.name = data[i]._name; 145 productDetails.price = self.currencySymbol + data[i]['<SalePrice>k__BackingField']; 146 productDetails.isAuthenticated = "True"; 147 productDetails.isSaved = true; 148 149 self.addToList(productDetails); 150 } 151 ns$.jStorage.set("productHistory", self.productList); 152 } 153 154 }); 155 } 156 157 this.HistoryActionQueue = new Array(); 158 159 this.execute_queue = function () { 160 for (var i in this.HistoryActionQueue) this.HistoryActionQueue[i].call(null); 161 } 162 163 this.saveToHTPPS = function () { 164 var win = ns$(".httpsHistoryiframe").first()[0].contentWindow; 165 var siteSecureUrl = ns$(".httpsHistoryiframe").attr("sitesecureurl"); 166 win.postMessage( 167 self.productList, 168 siteSecureUrl 169 ); 170 win 171 } 172 173 174 ns$(document).ready(function () { 175 self.retrieveProductHistory(); 176 177 self.execute_queue(); 178 ns$('.httpsHistoryiframe').on('load', function () { 179 self.saveToHTPPS(); 180 }); 181 182 183 }); 184}
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.