{"version":3,"file":"default/js/pages.js","mappings":";;;;;;;;;;AAAa;;AAEb;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;;;;;;;;;;;ACZa;;AAEb;;AAEA;AACA;AACA,UAAU,QAAQ;AAClB,YAAY,QAAQ;AACpB;AACA;AACA;;AAEA,oBAAoB,kBAAkB;AACtC;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA,UAAU,OAAO;AACjB,YAAY,OAAO;AACnB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAY,YAAY;AACxB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,KAAK;;AAEL;AACA;AACA,cAAc,QAAQ;AACtB,gBAAgB,SAAS;AACzB;AACA;AACA;AACA;AACA,SAAS;AACT,KAAK;;AAEL;AACA;AACA,cAAc,QAAQ;AACtB,gBAAgB,OAAO;AACvB;AACA;AACA;AACA;AACA,SAAS;AACT,KAAK;;AAEL;AACA;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB,cAAc,OAAO;AACrB,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,KAAK;AACL;AACA;AACA,cAAc,QAAQ;AACtB;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,KAAK;AACL;AACA;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,cAAc,QAAQ;AACtB,gBAAgB,QAAQ;AACxB;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;;AAEA;AACA,KAAK;;AAEL;AACA;AACA,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB;AACA;AACA;AACA,wBAAwB,sBAAsB;AAC9C;AACA;;AAEA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB,gBAAgB,QAAQ;AACxB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,KAAK;;AAEL;AACA;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,uBAAuB;AAC1C;;AAEA;AACA;AACA;AACA,gBAAgB,QAAQ;AACxB;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAS;;AAET;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,KAAK;;AAEL;AACA;AACA,cAAc,QAAQ;AACtB,gBAAgB,QAAQ;AACxB;AACA;AACA;;AAEA;;AAEA;AACA,wBAAwB;AACxB;AACA;;AAEA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;;;;;;UCnZA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;;;;;ACtBa;;AAEb,qBAAqB,mBAAO,CAAC,gFAAQ;AACrC;AACA;AACA;AACA;AACA,uBAAuB,mBAAO,CAAC,8FAAe;AAC9C;AACA,CAAC","sources":["webpack://sfra-startup-kit/./cartridges/app_ballantynes/cartridge/client/default/js/util.js","webpack://sfra-startup-kit/./cartridges/app_ballantynes/cartridge/client/default/js/utils/pages.js","webpack://sfra-startup-kit/webpack/bootstrap","webpack://sfra-startup-kit/./cartridges/app_ballantynes/cartridge/client/default/js/pages.js"],"sourcesContent":["\"use strict\";\n\nmodule.exports = function (include) {\n if (typeof include === \"function\") {\n include();\n } else if (typeof include === \"object\") {\n Object.keys(include).forEach(function (key) {\n if (typeof include[key] === \"function\") {\n include[key]();\n }\n });\n }\n};\n","\"use strict\";\n\nvar storage = window.sessionStorage || {};\n\n/**\n* Generates a hash value from the given input string\n* @param {string} input - the input string\n* @returns {number} - a 32-bit hash value\n*/\nfunction toHash(input) {\n var hval = 0x811c9dc5;\n\n for (var i = 0; i < input.length; i++) {\n hval = hval ^ (input.charCodeAt(i) & 0xFF);\n hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);\n }\n\n return hval >>> 0;\n}\n\n/**\n* Returns an array of state, title, and url\n* @param {Array} args - an array of arguments\n* @returns {Array} - an array of state, title, and url\n*/\nfunction getState(args) {\n if (args.length === 1 && typeof args[0] === \"object\") {\n var state = args[0].state || {};\n var title = args[0].title || \"\";\n var url = args[0].url || \"\";\n\n return [state, title, decodeURI(url)];\n }\n\n return args;\n}\n\n/**\n* Retrieves all page events from local storage\n* @returns {Object} an object containing all page events\n*/\nfunction getAllPageEvents() {\n try {\n var events = storage.getItem(\"page_events\");\n return events ? JSON.parse(events) : {};\n } catch (error) {\n return {};\n }\n}\n\n/**\n* PageEvents constructor\n*\n* @constructor\n* @returns {PageEvents} - an instance of PageEvents\n*/\nfunction PageEvents() {\n var pageEvents = getAllPageEvents();\n var pageID = toHash(decodeURI(window.location.href));\n var currentPageEvents = pageEvents[pageID] || {};\n\n this.clicks = currentPageEvents.clicks || [];\n this.lastClickedRegionLink = currentPageEvents.lastClickedRegionLink || null;\n this.lastClickedProduct = currentPageEvents.lastClickedProduct || null;\n this.lastScrolledPosition = currentPageEvents.lastScrolledPosition || null;\n this.pageID = pageID;\n}\n\nPageEvents.prototype = {\n /**\n * Adds an element to the clicks array and saves it\n * @param {Object} element - the element to add\n */\n addClick: function (element) {\n if (this.isExists(element)) {\n return;\n }\n\n this.clicks.push(element);\n this.save();\n },\n\n /**\n * Checks if an element is present in the clicks array\n * @param {Object} element - the element to check\n * @returns {boolean} - true if the element is present, false otherwise\n */\n isExists: function (element) {\n return this.clicks.some(function (click) {\n return element.eventName == click.eventName && click.url === element.url;\n });\n },\n\n /**\n * Gets the clicks for the given event name\n * @param {string} name - the event name\n * @returns {Array} - an array of clicks for the given event name\n */\n getClicks: function (name) {\n return this.clicks.filter(function (click) {\n return click.eventName === name;\n });\n },\n\n /**\n * Saves the last clicked product ID\n * @param {string} productID - the ID of the last clicked product\n */\n setLastClickedProduct: function (productID) {\n this.lastClickedProduct = productID;\n this.save();\n },\n\n /**\n * Saves the last clicked region link\n * @param {string} link - the last clicked region link\n */\n setLastClickedRegionLink: function (link) {\n this.lastClickedRegionLink = link;\n this.save();\n },\n\n /**\n * Saves the last scrolled position\n * @param {number} position - the last scrolled position\n */\n setLastScrolledPosition: function (position) {\n this.lastScrolledPosition = position;\n this.save();\n },\n\n /**\n * Stores page events in local storage\n * @param {string} pageURL - decoded page URL\n * @param {string} pageID - page ID generated from page URL\n * @param {Object} pageEvents - all page events\n * @param {Object} currentPageEvents - page events for the current page\n * @param {Array} clicks - array of click events\n * @param {Object} lastClickedProduct - last clicked product\n * @param {number} lastScrolledPosition - last scrolled position\n * @param {Object} lastClickedRegionLink - last clicked region link\n */\n save: function () {\n var pageURL = decodeURI(window.location.href);\n var pageID = this.pageID || toHash(pageURL);\n\n var pageEvents = getAllPageEvents();\n var currentPageEvents = pageEvents[pageID];\n\n if (!currentPageEvents) {\n currentPageEvents = {\n pageID: pageID,\n pageURL: pageURL\n };\n }\n\n currentPageEvents.clicks = this.clicks || [];\n currentPageEvents.lastClickedProduct = this.lastClickedProduct || null;\n currentPageEvents.lastScrolledPosition = this.lastScrolledPosition || null;\n currentPageEvents.lastClickedRegionLink = this.lastClickedRegionLink || null;\n pageEvents[pageID] = currentPageEvents;\n\n storage.setItem(\"page_events\", JSON.stringify(pageEvents));\n },\n /**\n * Removes the page event from the page events list\n * @param {string} pageID - ID of the page event to be removed\n */\n clear: function () {\n var pageEvents = getAllPageEvents();\n\n this.clicks = [];\n this.lastClickedRegionLink = null;\n this.lastClickedProduct = null;\n this.lastScrolledPosition = null;\n\n delete pageEvents[this.pageID];\n\n storage.setItem(\"page_events\", JSON.stringify(pageEvents));\n },\n /**\n * Constructor for PageEvents\n * @param {string} pageID - the page ID\n */\n clone: function (pageID) {\n var pageEvents = getAllPageEvents();\n var sourcePageEvents = pageEvents[pageID] || {};\n\n this.clicks = sourcePageEvents.clicks || [];\n this.lastClickedRegionLink = sourcePageEvents.lastClickedRegionLink || null;\n this.lastClickedProduct = sourcePageEvents.lastClickedProduct || null;\n this.lastScrolledPosition = sourcePageEvents.lastScrolledPosition || null;\n this.save();\n }\n};\n\n/**\n* Constructor for CurrentPage object\n* @constructor\n*/\nfunction CurrentPage() {\n this.pageURL = decodeURI(window.location.href);\n this.pageID = toHash(this.pageURL || \"\");\n this.events = new PageEvents();\n}\n\nCurrentPage.prototype = {\n /**\n * This method fetches the data stored in the session storage specific for the current page.\n * @param {string} [key] - the key of the data to retrieve\n * @returns {Object} the data stored in local storage\n */\n get: function () {\n var data = {};\n try {\n data = JSON.parse(storage.getItem(this.pageID));\n } catch (error) {\n data = arguments[0];\n }\n\n return arguments.length ? data[arguments[0]] : data;\n },\n\n /**\n * Sets the data to the session storage scoped to the current page\n * @param {string} key - the key of the data to be set\n * @param {string} value - the value of the data to be set\n */\n set: function () {\n var data = this.get() || {};\n for (var i = 0; i < arguments.length; i += 2) {\n data[arguments[i]] = arguments[i + 1];\n }\n\n storage.setItem(this.pageID, JSON.stringify(data));\n },\n\n /**\n * Re-initializes the page events\n */\n refresh: function () {\n this.events = this.events || new PageEvents();\n this.events.clear();\n }\n};\n\n/**\n* Constructor for Pages object\n* @constructor\n*/\nfunction Pages() {\n this.current = new CurrentPage();\n this.lastVisitedLink = null;\n}\n\nPages.prototype = {\n /**\n * A function to get and set items in the storage\n * @param {string} key - the key of the item to be stored/retrieved\n * @param {string} value - the value of the item to be stored\n * @returns {string} - the value of the item stored/retrieved\n */\n prop: function () {\n if (arguments.length > 1) {\n storage.setItem(arguments[0], arguments[1]);\n return arguments[1];\n }\n\n return storage.getItem(arguments[0]);\n },\n\n /**\n * Removes an item from the storage\n * @param {string} arguments[0] - the item to be removed from the storage\n */\n delete: function () {\n storage.removeItem(arguments[0]);\n }\n};\n\n/**\n* Constructor for the PageHistory class\n* Initializes the page history and replaces the current URL\n*/\nfunction PageHistory() {\n this.init();\n this.replace({ url: this.current.url });\n}\n\nPageHistory.prototype = {\n /**\n * Custom history object to store page navigation history\n * @returns {Object} customHistory - an object containing the page navigation history\n */\n init: function () {\n var customHistory = {};\n try {\n customHistory = JSON.parse(window.pages.prop(\"custom_history\"));\n } catch (error) {\n return {};\n }\n\n Object.assign(this, customHistory);\n\n this.current = {\n url: decodeURI(window.location.href)\n };\n\n // The below code checks if the current page is the same as the last page in the history.\n // If they are the same, it means that the page was reloaded, and in such cases, the state set to reloaded and the history should not be updated.\n if (customHistory && customHistory.current.url == this.current.url) {\n this.prev = customHistory.prev;\n this.state = \"page:reloaded\";\n return;\n }\n\n // Retrieves the padding value from the custom history.\n // If the padding value is not set, it defaults to the length of the history.\n // This padding value is important for keeping the window history object and custom history object synchronized.\n var padding = customHistory ? customHistory.padding : window.history.length;\n var allUrls = customHistory ? customHistory.all : [];\n\n // Find the index of the current page in the history.\n // If the page is not found, it means that the page is new and should be added to the history.\n var pageIndex = allUrls.findIndex(function (h) {\n return h.url == decodeURI(window.location.href);\n });\n\n // Determines the state of the page by checking the existence of the URL in the custom history object and the length of the native history.\n // If the page is new, it is pushed to the history and the state is set as \"pushed\".\n // Otherwise, if the page is popped from the history via the back button, the state is set as \"popped\".\n if (!customHistory || (customHistory\n && customHistory.current.url !== decodeURI(window.location.href))) {\n if (pageIndex < 0 || window.history.length >= allUrls.length + padding) {\n allUrls.push(this.current);\n this.state = \"page:pushed\";\n pageIndex = allUrls.length - 1;\n } else {\n this.state = \"page:popped\";\n }\n }\n\n // Sets the previous page URL to the page before the current page.\n // However, if the current page is the first page in the history, then the previous page URL is set to empty.\n this.prev = allUrls.length > 1 ? allUrls[pageIndex - 1] : {};\n this.all = allUrls;\n this.padding = padding;\n this.pageIndex = pageIndex;\n\n this.updateHistory();\n },\n\n /**\n * Push a new state to the browser history and initialize the page\n */\n push: function () {\n window.history.pushState.apply(window.history, getState(arguments));\n if (decodeURI(window.location.href) == this.current.url) {\n return;\n }\n\n this.init();\n\n window.pages = new Pages() || {};\n },\n\n /**\n * Replaces the current page state in the history\n * @param {Object} arguments - the arguments object\n * @returns {Object} - the new page state\n */\n replace: function () {\n window.history.replaceState.apply(window.history, getState(arguments));\n\n var replacingUrl = this.current.url;\n\n // This code updates the current page URL to the replaced URL and also updates the browsing history accordingly.\n this.current = {url: decodeURI(window.location.href)};\n this.all[this.pageIndex] = this.current;\n this.updateHistory();\n\n // Moves the page events associated with the page to the replaced one by copying it.\n window.pages.current.events.clone(toHash(replacingUrl));\n },\n\n /**\n * Stores the custom history of the page in window.pages\n */\n updateHistory: function () {\n var customHistory = {\n current: this.current,\n prev: this.prev,\n all: this.all,\n padding: this.padding,\n pageIndex: this.pageIndex\n };\n\n window.pages.prop(\"custom_history\", JSON.stringify(customHistory));\n window.pages = new Pages() || {};\n }\n};\n\nwindow.pages = new Pages();\nwindow.pageHistory = new PageHistory();\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","\"use strict\";\n\nvar processInclude = require(\"./util\");\n// eslint-disable-next-line no-undef\n$(document).ready(function () {\n // eslint-disable-next-line no-undef\n if ($(\".page\").data(\"backToScrollEnabled\")) {\n processInclude(require(\"./utils/pages\"));\n }\n});\n"],"names":[],"sourceRoot":""}