PageSourceSearch

https://www.lexicon.com/on/demandware.static/-/Sites-LEX-US-NCOM-L…/v1790280091520/glp/dynamic-product-load.js

js lexicon.com collected 2026-09-24 22:57:46 UTC 7,348 bytes, 146 lines download raw bytes

1(function() {
2/*jshint eqeqeq:false, curly:false, latedef:false */
3    //list of data need to pass from backend
4	//span[id='productName']
5	//span[id='shortDescription']
6	//span[id='thumbnailImage']
7	//span[id='price']
8    //"use strict";
9	$.fn.dynamicProductDataUpdate = function(callback) {
10		return this.each(function() {
11		    var $this = $(this);
12			$this.hide();
13			//$this.after("<img class='dynamicLoadIcon' src='images/ajax-loader.gif' alt='Loading icon />");
14			$.ajax({
15				dataType : "html",	
16	            url: app.util.ajaxUrl(app.urls.dynamicProductLoad),//put the url here
17	            data: {dataid : $this.attr('skuid')},
18	            success: function (responseData) {
19	                responseValid = true;
20	                try {
21	                    $responseData = jQuery(responseData);
22	                }
23	                catch (e) {
24	                    responseValid = false;
25	                }
26	                
27	                if (responseValid) {
28	                    // Replace img elements with alternate to prevent loading on each ajax call
29	                    // responseData = responseData.replace(/<img src=/ig, '<img data-src=');
30
31	                    var dynamicProductName = $(responseData).find(".product-name").html() == null ? 'No Data' : $(responseData).find(".product-name").html();
32	                    var dynamicShortDescription = $(responseData).find(".product-description").html() == null ? 'No Data' : $(responseData).find(".product-description").html();
33	                    var dynamicProductPromo = $(responseData).find(".product-promo").html() == null ? 'No Data' : $(responseData).find(".product-promo").html();
34	                    var dynamicAvailability = $(responseData).find(".availability").html() == null ? 'No Data' : $(responseData).find(".availability").html();
35	                    // var dynamicDescription = $(responseData).find("span[id='description']").html() == null ? $(responseData).filter("#description").html() : $(responseData).find("span[id='description']").html(); 
36	                    var dynamicPrice = $(responseData).find(".product-pricing").html() == null ? 'No Data' : $(responseData).find(".product-pricing").html();
37						var dynamicRating = $(responseData).find(".product-rating").html() == null ? '' : $(responseData).find(".product-rating").html();
38	                    //var dynamicInventoryStatus = $(responseData).find("span[id='inventoryStatus']").html() == null ? $(responseData).filter("#inventoryStatus").html()  : $(responseData).find("span[id='inventoryStatus']").html();
39	                    var dynamicThumbnailImage = $(responseData).find(".product-image").html() == null ? $(responseData).filter("#thumbnailImage").html() : $(responseData).find(".product-image").html();
40	                    var dynamicAddToCartButton = $(responseData).find("#addToCart").html() == null ? 'No Data' : $(responseData).find("#addToCart").html();
41	                    var dynamicUrl = $(responseData).find(".productname-link").attr('href');
42	                    var urlParams = dynamicUrl.split('?')[1].split('&');
43	                    var color = "";
44	                    for (var x = 0; x < urlParams.length; x++) {
45	                        var index = urlParams[x].indexOf("color=");
46	                        if (index > 0) var color = urlParams[x].substr(index + 6);
47	                    }
48
49	                    $this.find(".dynamic-name").html(dynamicProductName);
50	                    $this.find(".dynamic-short-description").html(dynamicShortDescription);
51	                    $this.find(".dynamic-product-promo").html(dynamicProductPromo);
52	                    $this.find(".dynamic-availability").html(dynamicAvailability);
53	                    //$this.find(".dynamic-description").html(dynamicDescription);
54	                    $this.find(".dynamic-price").html(dynamicPrice);
55	            		$this.find(".dynamic-rating").html(dynamicRating);
56	                    // $this.find(".dynamic-inventory-status").html(dynamicInventoryStatus);
57	                    if ($this.find(".dynamic-thumbnail-image[data-width]").length > 0) {
58	                        // Change thumbnail to png and custom width
59	                        var thumbWidth = $this.find(".dynamic-thumbnail-image").data('width');
60	                        var thumbObj = $('<div>' + dynamicThumbnailImage + '</div>');
61	                        var newSrc = ($('img', thumbObj).attr('src')).split('?')[0].replace('.jpg', '.png') + '?sw=' + thumbWidth + '&sh=' + thumbWidth + '&sm=fit';
62
63	                        $('img', thumbObj).attr('src', newSrc);
64	                        dynamicThumbnailImage = thumbObj.html();
65	                    }
66	                    $this.find(".dynamic-thumbnail-image").html(dynamicThumbnailImage);
67
68	                    $this.find(".dynamic-add-to-cart").html(dynamicAddToCartButton);
69	                    $this.find(".dynamic-url").attr('href', $(responseData).find(".productname-link").attr('href'));
70	                    //$this.siblings(".dynamicLoadIcon").hide();
71	                    $this.show();
72	                    if ((color != "") && (!$this.attr('data-color'))) {
73	                        $this.attr('data-color', color);
74	                        $this.trigger('data-attribute-changed');
75	                    }
76
77                        if(typeof BV !== 'undefined') BV.inline_ratings.render();
78	                }
79
80	                $this.data('available', responseValid);
81                    
82		      		if (typeof callback === 'function') callback.apply($this, []);
83	            },
84	            error: function () {
85	                
86	            }
87			});
88		});
89	}
90	$.fn.addToCartContent3 = function(callback){
91		return this.on("click",".cart-button",function(e){
92			e.preventDefault();
93		    var $button = $( e.target );
94			if($button.hasClass('btn-disabled')) {
95				return;
96			}
97			$button.addClass('btn-disabled');
98			
99	        var productID = $(this).data("productid");
100	        var data = {
101	    			cartAction : "add",
102	    			pid : productID,
103	    			Quantity : 1
104	    		};
105	    	
106	        app.cart.add(data, function (response) {
107	        	
108	    		// check SAP inventory availability
109	    		var $container = $button.parents('.dynamic-update-product-container').find('.availability');
110	    		var showMiniCart = app.sap.checkAvailability(response, $container);
111	    		var $cart = $(".fluid-templates-CartTemplate"); 
112	    			
113	    		//show the mini cart unless SAP availability is out of stock
114	    		if(showMiniCart){
115	    			if($cart.length>0){
116	    				app.page.refresh();
117	    			} else {
118	    				app.minicart.show(response);
119	    			}
120	    		} else {
121	    			$button.blur();
122	    			$button.attr('disabled', true);
123	    			$button.text(app.resources.SOLD_OUT);
124	    			app.minicart.init();
125	    		}
126
127	    		if (typeof callback === 'function') callback.apply($button.parents('.dynamic-update-product-container'), []);
128	    	});
129	    	//re-enable button
130	 		var t = window.setTimeout(function(){
131	 			$button.removeClass('btn-disabled');
132	 		}, 500);	 		
133		});
134	}
135
136})(jQuery);
137
138
139
140$(document).ready(function() { 
141	$(".dynamic-update-product-container").dynamicProductDataUpdate(typeof dplCallback !== 'undefined' ? dplCallback : null);
142	$(".dynamic-add-to-cart").addToCartContent3(typeof atcCallback !== 'undefined' ? atcCallback : null);
143});
144
145
146

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.