{ "version": 3, "sources": [ "../../../../../Foundation/JavascriptCommon/code/scripts/common/urlUtils.js", "ProductTile/productTileComponent.js", "ProductTile/main.js" ], "names": [], "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,AC1KA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,AC/GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA", "file": "ProductTile.js", "sourcesContent": [ "define('common/urlUtils',[\r\n],\r\n function () {\r\n\r\n // Takes the url and parses the query string parameters out of it.\r\n // Returns the parameters and their string values as object { paramName1: value1, paramName2: value2, ...},\r\n // or an empty object in case there are no parameters in url.\r\n function parseQueryParamsFromUrl(url) {\r\n url = url ? url : window.location.search; // default url parameter if not set\r\n // take just the query search part of url (lose the leading question mark)\r\n var query = decomposeUrl(url).search;\r\n if (query.indexOf(\"?\") >= 0) query = query.substring(query.indexOf(\"?\") + 1);\r\n var urlParams = {},\r\n match,\r\n search = /([^&=]+)=?([^&]*)/g,\r\n decode = function (s) { return decodeURI(decodeURIComponent(s)); };\r\n\r\n while (match = search.exec(query))\r\n urlParams[decode(match[1])] = decode(match[2]);\r\n\r\n return urlParams;\r\n }\r\n\r\n // Takes the url, decomposes it into three components: path, search, hash,\r\n // and returns those three components in an object.\r\n // When searching for hash string which is directly after path (without search parameters) we're ignoring '#/'.\r\n // That is not a hash, that is Angular routing and it's actually part of the path.\r\n function decomposeUrl(url) {\r\n var path = '';\r\n var search = '';\r\n var hash = '';\r\n if (url.indexOf('?') >= 0) {\r\n // there is search string already in the url\r\n path = url.substring(0, url.indexOf('?'));\r\n search = url.substring(url.indexOf('?'));\r\n if (search.indexOf('#') >= 0) {\r\n // there is also a hash string in the url\r\n hash = search.substring(search.indexOf('#'));\r\n search = search.substring(0, search.indexOf('#'));\r\n }\r\n } else if (url.indexOf('#') >= 0 && url.indexOf('#') != url.indexOf('#/')) {\r\n // no search string, but there is hash string\r\n path = url.substring(0, url.indexOf('#'));\r\n hash = url.substring(url.indexOf('#'));\r\n } else {\r\n // no search string, no hash string\r\n path = url ? url : '';\r\n }\r\n return {\r\n path: path, // path also includes the protocol and hostname (if they existed in the given url)\r\n search: search,\r\n hash: hash\r\n }\r\n }\r\n\r\n // Adds a new query string parameter into the given url.\r\n // Returns the newly constructed url.\r\n function putParamIntoUrl(paramName, paramValue, url) {\r\n // first we'll split the url into 3 components\r\n var urlComp = decomposeUrl(url);\r\n // add the new query string parameter into search string\r\n urlComp.search = (urlComp.search ? urlComp.search + '&' : '?') + paramName + '=' + encodeURIComponent(paramValue);\r\n // return the new url\r\n return urlComp.path + urlComp.search + urlComp.hash;\r\n }\r\n\r\n // Reads the specified query string parameter from a given url.\r\n // Returns the value of that parameter (a string value). \r\n function getParamFromUrl(paramName, url) {\r\n return parseQueryParamsFromUrl(url)[paramName];\r\n }\r\n\r\n // Modifies the given DOM element's href property, or the current page's URL (if\r\n // no domElement has been given) by adding new query string parameter with the\r\n // given value. \r\n function pushParamIntoLink(paramName, paramValue, domElement) {\r\n var url;\r\n if (domElement) url = $(domElement).attr('href'); // url from DOM element\r\n else url = window.location.href; // current page url\r\n\r\n var params = parseQueryParamsFromUrl(url);\r\n\r\n // making sure that we find the parameter no matter how it's written (case insensitive)\r\n for (var p in params) {\r\n if (p.toLowerCase() === paramName.toLowerCase()) {\r\n paramName = p;\r\n break;\r\n }\r\n }\r\n\r\n params[paramName] = paramValue; // update (or add) the parameter\r\n var newSearchString = $.param(params); // and construct a new search string.\r\n\r\n var urlComp = decomposeUrl(url);\r\n if (domElement) {\r\n // set new href property on DOM element\r\n var newHref = urlComp.path + (newSearchString ? ('?' + newSearchString) : '') + urlComp.hash;\r\n $(domElement).attr('href', newHref);\r\n } else {\r\n if (history && history.pushState) { // because some older browsers (IE 9 or older) don't support this\r\n // for other pages put new URL to browser's address bar using window.history\r\n history.replaceState(\r\n null,\r\n null,\r\n urlComp.path +\r\n (newSearchString ? ('?' + newSearchString) : '') +\r\n urlComp.hash\r\n );\r\n }\r\n }\r\n }\r\n\r\n // Reads the query string parameter from the domElement's href property, or from\r\n // the current page's URL (if no domElement has been given). Removes the parameter\r\n // from the URL and puts new URL into the domElement's href property, or into the\r\n // browser's address bar.\r\n // Returns the value of that parameter (a string value).\r\n function popParamFromLink(paramName, domElement) {\r\n var url;\r\n if (domElement) url = $(domElement).attr('href'); // url from DOM element\r\n else url = window.location.href; // current page url\r\n\r\n var params = parseQueryParamsFromUrl(url);\r\n var retVal;\r\n\r\n // making sure that we find the parameter no matter how it's written (case insensitive)\r\n for (var p in params) {\r\n if (p.toLowerCase() === paramName.toLowerCase()) {\r\n paramName = p;\r\n break;\r\n }\r\n }\r\n\r\n if (params[paramName]) {\r\n // the requested parameter exists in the url\r\n retVal = params[paramName]; // Its value will be returned from the function.\r\n delete params[paramName]; // Remove the parameter from the array,\r\n var newSearchString = $.param(params); // and construct a new search string.\r\n var urlComp = decomposeUrl(url);\r\n if (domElement) {\r\n // set new href property on DOM element\r\n var newHref = urlComp.path + (newSearchString ? ('?' + newSearchString) : '') + urlComp.hash;\r\n $(domElement).attr('href', newHref);\r\n } else {\r\n if (history && history.pushState) { // because some older browsers (IE 9 or older) don't support this\r\n // for other pages put new URL to browser's address bar using window.history\r\n history.replaceState(\r\n null,\r\n null,\r\n urlComp.path +\r\n (newSearchString ? ('?' + newSearchString) : '') +\r\n urlComp.hash\r\n );\r\n }\r\n }\r\n }\r\n return retVal;\r\n }\r\n\r\n\r\n return {\r\n parseQueryParamsFromUrl: parseQueryParamsFromUrl,\r\n decomposeUrl: decomposeUrl,\r\n putParamIntoUrl: putParamIntoUrl,\r\n getParamFromUrl: getParamFromUrl,\r\n pushParamIntoLink: pushParamIntoLink,\r\n popParamFromLink: popParamFromLink\r\n }\r\n });\r\n\n", "define('ProductTile/productTileComponent',[\r\n \"common/urlUtils\"\r\n],\r\nfunction (urlUtils) {\r\n\r\n function initClickHandlers() {\r\n $(\".product-tile .variant-selector .color-selector .selector\").off(\"click\").on(\"click\", colorSelectorClicked);\r\n $(\".product-tile .variant-selector .list-selector\").off(\"change\").on(\"change\", listSelectorChanged);\r\n }\r\n\r\n const selectorType = {\r\n color: 1,\r\n list: 2\r\n };\r\n\r\n function colorSelectorClicked(event) {\r\n $(this).siblings().removeClass(\"active\"); // deactivate all other selectors\r\n if ($(this).hasClass(\"active\")) {\r\n // It was already active. Deactivate it now.\r\n $(this).removeClass(\"active\");\r\n setVariant(this, { variantSku: \"\"}); // set to the default variant (no particular variant selected)\r\n }\r\n else {\r\n // activate the clicked selector\r\n $(this).addClass(\"active\");\r\n setVariant(this, $(this).data()); // set to the variant data written in that selector\r\n }\r\n }\r\n\r\n function listSelectorChanged(event) {\r\n\r\n setVariant(this, $(this.selectedOptions[0]).data());\r\n //selectVariant(this, selectorType.list);\r\n }\r\n\r\n function setVariant(clickedElement, variantData) {\r\n var imageElement = $(clickedElement).closest(\".product-tile\").find(\"img\");\r\n if (!$(imageElement).data(\"originalSrc\")) {\r\n // store original image url, in case we need to put it back\r\n $(imageElement).data(\"originalSrc\", $(imageElement).attr(\"src\"));\r\n }\r\n var currentImageUrl = $(imageElement).attr(\"src\");\r\n var newImageUrl = $(imageElement).data(\"originalSrc\"); // this is the default image\r\n\r\n var linkElement = $(clickedElement).closest(\".product-tile\").find(\"a\");\r\n\r\n if (variantData.variantSku) {\r\n if (variantData.imageUrl) newImageUrl = variantData.imageUrl;\r\n urlUtils.pushParamIntoLink(\"v\", variantData.variantSku, linkElement); // add variant query parameter into the link\r\n } else {\r\n urlUtils.popParamFromLink(\"v\", linkElement); // remove variant query parameter from link\r\n }\r\n\r\n if (newImageUrl !== currentImageUrl) {\r\n $(imageElement)\r\n .addClass(\"opacity-05\") // dim the image\r\n .one(\"load\", function () {\r\n $(this).removeClass(\"opacity-05\"); // set the load event to un-dim the image\r\n })\r\n .attr(\"src\", newImageUrl) // change the image source\r\n .each(function () {\r\n // Workaround for situations where the load event doesn't get triggerred because the image is taken from cache, or the\r\n // image changes so quickly that our \"onload\" event didn't have a chance to be set up yet.\r\n setTimeout(() => { $(imageElement).removeClass(\"opacity-05\"); }, 2000); // just in case \"onload\" didn't do it already, we'll clear the opacity class after 2 seconds\r\n });\r\n }\r\n\r\n $(linkElement).data(\"variantSku\", variantData.variantSku); // this will be used by the GTM click event\r\n }\r\n\r\n function selectVariant(clickedElement, selectorType) {\r\n\r\n var imageElement = $(clickedElement).closest(\".product-tile\").find(\"img\");\r\n if (!$(imageElement).data(\"originalSrc\")) {\r\n // store original image url, in case we need to put it back\r\n $(imageElement).data(\"originalSrc\", $(imageElement).attr(\"src\"));\r\n }\r\n\r\n var newImageUrl = $(imageElement).data(\"originalSrc\"); // this is the default image\r\n\r\n if (selectorType === selectorType.color) {\r\n $(clickedElement).siblings().removeClass(\"active\"); // deactivate all other selectors\r\n }\r\n\r\n var linkElement = $(clickedElement).closest(\".product-tile\").find(\"a\");\r\n\r\n if ($(clickedElement).hasClass(\"active\")) {\r\n // It was already active. Deactivate it now.\r\n $(clickedElement).removeClass(\"active\");\r\n // remove the variant query parameter from the link\r\n urlUtils.popParamFromLink(\"v\", linkElement);\r\n }\r\n else\r\n {\r\n // activate the clicked selector\r\n $(clickedElement).addClass(\"active\");\r\n // and apply its image, if it has one assigned\r\n if ($(clickedElement).data(\"imageUrl\")) newImageUrl = $(clickedElement).data(\"imageUrl\");\r\n // add the selected variant query parameter into the link\r\n var variantSku = $(clickedElement).data(\"variantSku\");\r\n if (variantSku) urlUtils.pushParamIntoLink(\"v\", variantSku, linkElement);\r\n }\r\n\r\n $(imageElement).attr(\"src\", newImageUrl);\r\n }\r\n\r\n return {\r\n initClickHandlers: initClickHandlers\r\n };\r\n\r\n});\n", "require([\r\n \"ProductTile/productTileComponent\"\r\n],\r\nfunction (productTileComponent) {\r\n\r\n productTileComponent.initClickHandlers();\r\n\r\n});\ndefine(\"ProductTile/main\", function(){});\n\n" ] }