1//// Utility functions 2 3/* MASK VALIDATION */ 4function only_numbers(event) { 5 /* 0-9 or numpad 0-9, disallow shift, ctrl, and alt */ 6 if ((!event.shiftKey && !event.ctrlKey && !event.altKey) && ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105))) { 7 return true; 8 } else if (event.keyCode != 9 && event.keyCode != 8 && event.keyCode != 13 && event.keyCode != 46 && event.keyCode != 37 && event.keyCode != 39) { /* not esc, del, left, right or enter */ 9 event.preventDefault(); 10 } 11} 12 13/* MASK VALIDATION */ 14function alphanumeric(event) { 15 if ( 16 /* 0-9 and a-z and numpad 0-9, disallow shift, ctrl, and alt */ 17 ( 18 ((!event.shiftKey && !event.ctrlKey && !event.altKey) && ((event.keyCode >= 48 && event.keyCode <= 90) || (event.keyCode >= 96 && event.keyCode <= 105))) || 19 /* A-Z characters */ 20 ((event.shiftKey) && (event.keyCode >= 65 && event.keyCode <= 90)) || 21 /* allow enter key as it may be needed for form submission */ 22 (event.keyCode = 13) 23 ) 24 ) { 25 /* check textbox value now and tab over if necessary */ 26 } else if (event.keyCode != 9 && event.keyCode != 8 && event.keyCode != 46 && event.keyCode != 37 && event.keyCode != 39) { /* not esc, del, left or right */ 27 event.preventDefault(); 28 } /* else the key should be handled normally */ 29} 30 31function isInteger(qty) { 32 return ((!isNaN(qty)) && (isFinite(qty))) ? true : false; 33} 34 35function isValidQty(qty) { 36 return (isInteger(qty) && (qty > 0) && (qty <= maximumQuantityLimitForCart)) ? true : false; 37} 38 39function isValidEmail(email) { 40 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 41 return re.test($.trim(email)); 42} 43 44function isAlphanumericDashUnderscore(string) 45{ 46 var regex = new RegExp("^[a-zA-Z0-9-_]+$"); 47 48 return (regex.test(string.trim())) ? true : false; 49} 50 51$(document).ready(function () { 52 function addToFav(partNum) { 53 return $.ajax({ 54 type: "POST", 55 url: base_index_url + "my_account/favourites/create", 56 data: {"partNum": partNum} 57 }); 58 } 59 60 function removeFromFavourite(partNum) { 61 return $.ajax({ 62 type: "POST", 63 url: base_index_url + "my_account/favourites/delete", 64 data: {"partNum": partNum} 65 }); 66 } 67 68 $("#wrapper").on("click", ".add-product-to-favourite", function() { 69 var self = $(this); 70 var partNum = self.attr("data-part-num"); 71 72 if (self.hasClass("is-favourite")) { 73 removeFromFavourite(partNum).done(function (response) { 74 self.removeClass("is-favourite"); 75 Notifications.success(partNum + " " + window.favouriteRemoveSuccess); 76 }).fail(function (jqXHR, textStatus, errorThrown) { 77 Notifications.fail(window.genericFail); 78 }); 79 } else { 80 addToFav(partNum).done(function (response) { 81 self.addClass("is-favourite"); 82 Notifications.success(partNum + " " + window.favouriteAddSuccess); 83 }).fail(function (jqXHR, textStatus, errorThrown) { 84 Notifications.fail(window.genericFail); 85 }); 86 } 87 }); 88}); 89 90//// ProductStockIndicator 91$(document).ready(function() { 92 $("#wrapper").on("click", "button.show-warehouses-stock-btn", function(e) { 93 var $this = $(this); 94 95 var partNum = $this.attr('data-part-num'); 96 var warehouse = $this.attr('data-warehouse'); 97 var warehousePartnum = warehouse + '-' + partNum; 98 99 $("div.stock-indicator-warehouse-grid").each(function(index) { 100 var element = $(this); 101 var elementWarehousePartnum = element.attr('data-warehouse') + '-' + element.attr('data-part-num'); 102 103 if(elementWarehousePartnum != warehousePartnum) { 104 element.hide(); 105 } 106 }); 107 108 $this.next().toggle(); 109 }); 110 111 $("#wrapper").on("click", "button.ws-close", function(e) { 112 $(this).parent().hide(); 113 }); 114}); 115 116//// product_compare 117function addProductToCompare(slug, warehouse) { 118 var addProduct = processCompareRequest("add", slug, warehouse); 119 120 addProduct.then( 121 function(results) { 122 setCompareCheckBox(true, slug, warehouse, ""); 123 updateCompareUrl(results); 124 }, 125 function(jqXHR, textStatus, errorThrown) { 126 setCompareCheckBox(false, slug, warehouse, jqXHR.responseText); 127 } 128 ); 129} 130 131function removeProductToCompare(slug, warehouse) { 132 var removeProduct = processCompareRequest("remove", slug, warehouse); 133 134 removeProduct.then( 135 function(results) { 136 setCompareCheckBox(false, slug, warehouse, ""); 137 removeProductFromCompareTableView(slug, warehouse, results.count); 138 updateCompareUrl(results); 139 }, 140 function(jqXHR, textStatus, errorThrown) { 141 } 142 ); 143} 144 145function processCompareRequest(action, slug, warehouse) { 146 return $.ajax({ 147 url: base_index_url + "compare/" + action, 148 type:"POST", 149 data:{ 150 "slug" : slug, 151 "warehouse" : warehouse 152 }, 153 dataType:"json" 154 }).promise(); 155} 156 157function setCompareCheckBox(action, slug, warehouse, message) { 158 $('input.compare-this[data-part="' + slug + '"][data-warehouse="' + warehouse + '"]') 159 .prop('checked', action); 160 161 if (!_.isEmpty(message)) { 162 Notifications.fail(message); 163 } 164} 165 166function removeProductFromCompareTableView(slug, warehouse, count) { 167 var table = $('table.product_compare_table'); 168 169 if(table.length > 0) { 170 table.find('tr > td[data-part="' + slug + '"][data-warehouse="' + warehouse + '"]').remove(); 171 } 172 173 if(count == 0) { 174 $('.no_products_for_comparison').show(); 175 table.remove(); 176 } 177} 178 179function updateCompareUrl(results) { 180 window.compareUrl = results.url; 181} 182 183function viewComparisons() { 184 window.location = window.compareUrl ? window.compareUrl : base_index_url + "compare/products"; 185} 186 187$(document).ready(function () { 188 $("#wrapper").on("change", "input.compare-this", function () { 189 var $this = $(this); 190 var slug = $this.attr('data-part'); 191 var warehouse = $this.attr('data-warehouse'); 192 var checked = $this.is(':checked'); 193 194 if (checked) { 195 addProductToCompare(slug, warehouse); 196 } else { 197 removeProductToCompare(slug, warehouse); 198 } 199 }); 200 201 $("#wrapper").on("click", "button.remove_compare_product", function () { 202 var $this = $(this); 203 var part = $this.attr('data-part'); 204 var warehouse = $this.attr('data-warehouse'); 205 206 removeProductToCompare(part, warehouse); 207 }); 208}); 209 210//// Notifications 211var Notifications = function () 212{ 213 var defaultOptions = { 214 "closeButton": true, 215 "debug": false, 216 "newestOnTop": true, 217 "progressBar": false, 218 "positionClass": "md-toast-bottom-right", 219 "preventDuplicates": false, 220 "onclick": null, 221 "showDuration": 300, 222 "hideDuration": 1000, 223 "timeOut": 5000, 224 "extendedTimeOut": 1000, 225 "showEasing": "swing", 226 "hideEasing": "linear", 227 "showMethod": "fadeIn", 228 "hideMethod": "fadeOut", 229 }; 230 231 function showNotificationType(type, message, options) 232 { 233 toastr.options = _.merge(defaultOptions, options); 234 235 if (!_.isUndefined(message.title)) { 236 toastr[type](message.content, message.title); 237 } else { 238 toastr[type](message); 239 } 240 } 241 242 function success(message) 243 { 244 showNotificationType("success", message); 245 } 246 247 function warning(message) 248 { 249 showNotificationType("warning", message); 250 } 251 252 function fail(message) 253 { 254 showNotificationType("error", message); 255 } 256 257 function info(message) 258 { 259 showNotificationType("info", message); 260 } 261 262 function loading(message) 263 { 264 showLoadingModal( 265 title = "", 266 message, 267 disallowClose = false, 268 showProgressBar = true, 269 color = "primary-color" 270 ); 271 } 272 273 function persist(message) 274 { 275 showLoadingModal( 276 title = "", 277 message, 278 disallowClose = true, 279 showProgressBar = true, 280 color = "primary-color" 281 ); 282 } 283 284 function modalPrimary(title, message) 285 { 286 showLoadingModal( 287 title, 288 message, 289 disallowClose = false, 290 showProgressBar = false, 291 color = "primary-color" 292 ); 293 } 294 295 function modalDanger(title, message) 296 { 297 showLoadingModal( 298 title, 299 message, 300 disallowClose = false, 301 showProgressBar = false, 302 color = "danger-color" 303 ); 304 } 305 306 function showLoadingModal(title, message, disallowClose, showProgressBar, color) 307 { 308 var header = $("#global-modal-header").removeClass("primary-color danger-color").addClass("hide"); 309 var modalDialogType = $("#global-modal-dialog").removeClass("cascading-modal"); 310 var modalTitle = $("#global-modal-title").html(""); 311 var progressBar = $("#global-modal-progress-bar").addClass("hide"); 312 313 if (!_.isEmpty(title)) { 314 header.addClass(color).removeClass("hide"); 315 modalDialogType.addClass("cascading-modal"); 316 modalTitle.html(title); 317 } 318 319 if (showProgressBar) { 320 progressBar.removeClass("hide"); 321 } 322 323 var options = {}; 324 if (disallowClose) { 325 options = { 326 backdrop: "static", 327 keyboard: false 328 }; 329 } 330 331 $("#global-modal-message").html(message); 332 $("#global-modal").modal(options); 333 } 334 335 function addToCart(products) 336 { 337 closeLoading(); 338 339 _.forEach(products, function (product) { 340 var type = "success"; 341 var productMessage = getProductMessage(product); 342 var options = {}; 343
344 if (!product.success) { 345 type = "error"; 346 options = { 347 "timeOut": 0, 348 "extendedTimeOut": 0 349 }; 350 } else if (product.onBackorder) { 351 type = "warning"; 352 } 353 354 showNotificationType(type, productMessage, options); 355 }); 356 } 357 358 function getProductMessage(product) 359 { 360 return { 361 "title": hidePartNumber ? product.title : (product.part_num + " - " + product.title), 362 "content": product.response 363 }; 364 } 365 366 function closeAll() 367 { 368 toastr.clear(); 369 } 370 371 function closeLoading() 372 { 373 var loadingModal = $("#global-modal"); 374 375 if ((loadingModal.data("bs.modal") || {})._isShown) { 376 loadingModal.modal("hide"); 377 } 378 } 379 380 return { 381 addToCart: addToCart, 382 success: success, 383 warning: warning, 384 fail: fail, 385 info: info, 386 loading: loading, 387 persist: persist, 388 modalPrimary: modalPrimary, 389 modalDanger: modalDanger, 390 closeAll: closeAll, 391 closeLoading: closeLoading, 392 }; 393}(); 394 395//// mdbConfig 396$(window).on("load", function() { 397 $(".has-tooltip").tooltip(); 398 399 $(".button-collapse").sideNav(); 400 401 $(".custom-scrollbar").each(function() { 402 ps = new PerfectScrollbar($(this)[0]); 403 }); 404 405 $(".stock-indicator-warehouse-grid-button").popover({ 406 container: "body", 407 html: true, 408 content: function() { 409 popoverContent = $(this).parent().find(".stock-indicator-warehouse-grid").html(); 410 return popoverContent; 411 } 412 }); 413});
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.