{ "version": 3, "sources": [ "../../../../../Foundation/JavascriptCommon/code/scripts/common/urlUtils.js", "../../../../../Foundation/JavascriptCommon/code/scripts/common/formUtils.js", "../../../../../Foundation/JavascriptCommon/code/scripts/common/alertMessage.js", "../../../../../Foundation/JavascriptCommon/code/scripts/common/spinner.js", "AddToWishlistPopup/addToWishlist.js", "AddToWishlistPopup/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,AC9GA;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,ACvGA;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,AC7CA;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;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,ACtQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA", "file": "AddToWishlistPopup.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('common/formUtils',[\r\n],\r\n function () {\r\n\r\n // Clears and deactivates all invalid feedback text on form fields\r\n function clearInvalidFeedback(formId) {\r\n if (!formId.startsWith(\"#\")) formId = \"#\" + formId;\r\n $(formId + \" .is-invalid\").removeClass(\"is-invalid\");\r\n $(formId + \" .invalid-feedback\").empty();\r\n }\r\n\r\n // Fills in and activates invalid feedback text on form fields\r\n function displayInvalidFeedback(invalidFields, formId) {\r\n if (!formId.startsWith(\"#\")) formId = \"#\" + formId;\r\n if (invalidFields) {\r\n invalidFields.forEach(function (fieldMessage) {\r\n var field = $(formId + \" [name='\" + fieldMessage.FieldName + \"']\");\r\n field.addClass(\"is-invalid\");\r\n field.siblings(\".invalid-feedback\").append(fieldMessage.MessageText);\r\n });\r\n }\r\n }\r\n\r\n // Collects the data from all form fields and returns them as object,\r\n // using \"name\" attribute values from form fields as object property names.\r\n function collectFormData(formId) {\r\n if (!formId.startsWith(\"#\")) formId = \"#\" + formId;\r\n // the serializeArray() jQuery method doesn't take the values from disabled fields, so first I'll\r\n // temporarily enable all disabled fields, and then disable them again\r\n var disabledFields = $(formId).find(\":input:disabled\").prop(\"disabled\", false);\r\n var serializedData = $(formId).serializeArray();\r\n disabledFields.prop(\"disabled\", true);\r\n var formData = {};\r\n serializedData.forEach(function (data) {\r\n formData[data.name] = data.value;\r\n });\r\n // serializeArray does not return anything for unchecked checkboxes, so we'll add them now with value false\r\n $(formId + \" input[type='checkbox']:not(:checked)\").each(function (index, element) {\r\n formData[element.name] = false;\r\n });\r\n // serializeArray returns \"on\" for checked checkboxes, so we'll set them to true now\r\n $(formId + \" input[type='checkbox']:checked\").each(function (index, element) {\r\n formData[element.name] = true;\r\n });\r\n return formData;\r\n }\r\n\r\n // Goes through all input elements on the form and fills them with data from the\r\n // given object, matching \"name\" attribute of the input element with object property name.\r\n function populateFormWithData(formId, data) {\r\n if (!formId.startsWith(\"#\")) formId = \"#\" + formId;\r\n $(formId + \" :input\").each(function (index, element) { \r\n if (element.type === \"radio\" ||\r\n element.type === \"checkbox\")\r\n {\r\n if (data[element.name] !== undefined)\r\n $(element).prop(\"checked\", $(element).val().toString() === data[element.name].toString());\r\n }\r\n else if (element.type === \"text\" ||\r\n element.type === \"email\" ||\r\n element.type === \"tel\" ||\r\n element.type === \"password\" ||\r\n element.type === \"textarea\" ||\r\n element.type === \"select-one\")\r\n {\r\n if (data[element.name] !== undefined)\r\n $(element).val(data[element.name]);\r\n else\r\n $(element).val(null);\r\n }\r\n });\r\n }\r\n\r\n function disableFields(formId) {\r\n if (!formId.startsWith(\"#\")) formId = \"#\" + formId;\r\n $(formId + \" :input\").prop(\"disabled\", true);\r\n }\r\n\r\n function enableFields(formId) {\r\n if (!formId.startsWith(\"#\")) formId = \"#\" + formId;\r\n $(formId + \" :input\").prop(\"disabled\", false);\r\n }\r\n\r\n function initializeFloatingLabels(formId) {\r\n if (!formId.startsWith(\"#\")) formId = \"#\" + formId;\r\n $(formId + \" .floating-label-container\").each(function (index, element) {\r\n var inputElement = $(element).find(\":input\")[0];\r\n if (inputElement.value) $(element).addClass(\"active\");\r\n else $(element).removeClass(\"active\");\r\n });\r\n }\r\n\r\n //adds the form token to the object for use with [ValidateAntiforgeryToken] attribute\r\n function useToken(data) { \r\n var token = $('input[name=\"__RequestVerificationToken\"]').val();\r\n data.__RequestVerificationToken = token;\r\n }\r\n\r\n return {\r\n clearInvalidFeedback: clearInvalidFeedback,\r\n displayInvalidFeedback: displayInvalidFeedback,\r\n collectFormData: collectFormData,\r\n populateFormWithData: populateFormWithData,\r\n disableFields: disableFields,\r\n enableFields: enableFields,\r\n initializeFloatingLabels: initializeFloatingLabels,\r\n useToken: useToken\r\n };\r\n });\r\n\n", "define('common/alertMessage',[\r\n],\r\n function () {\r\n\r\n const alertSelector = \"#alertMessage\";\r\n const allButtonsSelector = alertSelector + \" .modal-footer button\";\r\n const buttonSelector = {\r\n ok: allButtonsSelector + \".ok\",\r\n yes: allButtonsSelector + \".yes\",\r\n no: allButtonsSelector + \".no\"\r\n };\r\n\r\n function show(messageText, okCallback) {\r\n setIcon();\r\n setButtons(\"ok\", okCallback);\r\n displayAlert(messageText);\r\n }\r\n\r\n function info(messageText, okCallback) {\r\n setIcon(\"info\");\r\n setButtons(\"ok\", okCallback);\r\n displayAlert(messageText);\r\n }\r\n\r\n function warning(messageText, okCallback) {\r\n setIcon(\"warning\");\r\n setButtons(\"ok\", okCallback);\r\n displayAlert(messageText);\r\n }\r\n \r\n function error(messageText, okCallback, displayDefaultMessage) {\r\n setIcon(\"error\");\r\n setButtons(\"ok\", okCallback); \r\n if (typeof messageText === 'undefined' || messageText === null) messageText = \"\";\r\n if (typeof displayDefaultMessage === 'undefined') displayDefaultMessage = true;\r\n if (displayDefaultMessage || messageText === \"\") {\r\n messageText = CP.Messages[\"General/Default Error Message\"] + messageText;\r\n }\r\n displayAlert(messageText);\r\n }\r\n\r\n function yesNoQuestion(messageText, yesCallback, noCallback) {\r\n setIcon(\"question\");\r\n setButtons(\"yes-no\", yesCallback, noCallback);\r\n displayAlert(messageText);\r\n }\r\n\r\n function setIcon(iconName) {\r\n $(alertSelector + \" .icons\").addClass(\"d-none\");\r\n $(alertSelector + \" i\").addClass(\"d-none\");\r\n if (iconName) {\r\n $(alertSelector + \" .icons\").removeClass(\"d-none\");\r\n $(alertSelector + \" i.\" + iconName).removeClass(\"d-none\");\r\n }\r\n }\r\n\r\n function setButtons(buttons, callback1, callback2) {\r\n $(allButtonsSelector).addClass(\"d-none\");\r\n $(buttonSelector.ok).off(\"click\");\r\n $(buttonSelector.yes).off(\"click\");\r\n $(buttonSelector.no).off(\"click\");\r\n if (buttons === \"yes-no\") {\r\n $(buttonSelector.yes).removeClass(\"d-none\");\r\n $(buttonSelector.no).removeClass(\"d-none\");\r\n $(buttonSelector.yes).on(\"click\", function () { hideAndCallback(callback1); });\r\n $(buttonSelector.no).on(\"click\", function () { hideAndCallback(callback2); });\r\n }\r\n else {\r\n $(buttonSelector.ok).removeClass(\"d-none\");\r\n $(buttonSelector.ok).on(\"click\", function () { hideAndCallback(callback1); });\r\n }\r\n }\r\n\r\n var alertModal;\r\n\r\n function displayAlert(messageText) {\r\n $(alertSelector + \" .alert-text\").empty().html(messageText);\r\n if (!alertModal) {\r\n // initializing alertModal\r\n var alertElement = document.querySelector(alertSelector);\r\n if (alertElement) {\r\n alertModal = bootstrap.Modal.getOrCreateInstance(alertElement, { backdrop: \"static\", keyboard: false });\r\n if (!alertModal) console.log(\"Alert modal not initialized for \" + alertSelector);\r\n }\r\n else console.log(\"There's no alert modal with selector \" + alertSelector);\r\n }\r\n if (alertModal) alertModal.show();\r\n }\r\n\r\n function hideAndCallback(callback) {\r\n if (callback) $(alertSelector).one(\"hidden.bs.modal\", callback);\r\n if (alertModal) alertModal.hide();\r\n }\r\n\r\n return {\r\n show: show,\r\n info: info,\r\n warning: warning,\r\n error: error,\r\n yesNoQuestion: yesNoQuestion\r\n };\r\n });\r\n\n", "define('common/spinner',[\r\n],\r\n function () {\r\n\r\n var spinnerShownAt = {};\r\n\r\n function show(spinnerSelector) {\r\n $(spinnerSelector).removeClass(\"d-none\");\r\n var image = $(spinnerSelector).find(\"img\");\r\n if (image.length) {\r\n var alt = $(image).attr(\"alt\");\r\n if (!alt)\r\n $(image).attr(\"alt\", \"Spinner\");\r\n }\r\n // mark the time when this spinner was displayed\r\n spinnerShownAt[spinnerSelector] = Date.now();\r\n }\r\n\r\n function hide(spinnerSelector, callbackWhenHidden) {\r\n // This logic ensures that the spinner is displayed for at least 500ms.\r\n // Otherwise it just flickers and that doesn't look good for the user.\r\n var waitTime = 500 - (Date.now() - spinnerShownAt[spinnerSelector]);\r\n if (waitTime > 0) {\r\n setTimeout(function () {\r\n $(spinnerSelector).addClass(\"d-none\");\r\n if (callbackWhenHidden) callbackWhenHidden();\r\n }, waitTime);\r\n }\r\n else {\r\n $(spinnerSelector).addClass(\"d-none\");\r\n if (callbackWhenHidden) callbackWhenHidden();\r\n }\r\n }\r\n\r\n function getSpinnerHtml(spinnerId) {\r\n return '
';\r\n }\r\n\r\n return {\r\n show: show,\r\n hide: hide,\r\n getSpinnerHtml: getSpinnerHtml\r\n };\r\n });\r\n\n", "define('AddToWishlistPopup/addToWishlist',[\r\n \"common/urlUtils\",\r\n \"common/formUtils\",\r\n \"common/alertMessage\",\r\n \"common/spinner\"\r\n],\r\nfunction (urlUtils, formUtils, alertMessage, spinner) {\r\n\r\n const allProductOptionsSelector = \"[id^=product_options_]\";\r\n const allAddToListButtonsSelector = allProductOptionsSelector + \" button.list, .add-all button.list\";\r\n const allSelectListIconsSelector = allProductOptionsSelector + \" button.list i, .add-all button.list i\";\r\n const popupSelector = \"#add-to-wishlist-popup\";\r\n const formId = \"#new-wishlist-form\";\r\n\r\n var needToFetchLists = true;\r\n var itemAddedText;\r\n\r\n function isNumber(value) {\r\n\r\n }\r\n\r\n var optionsIndex = 0;\r\n function optionsSelector() {\r\n // this functions gives us the current product options selector\r\n if (isNaN(optionsIndex) && optionsIndex.startsWith(\"all_\")) return \".add-all[data-options-index=\" + optionsIndex + \"]\";\r\n else return \"#product_options_\" + optionsIndex;\r\n }\r\n\r\n var buttonsSpinner = {\r\n show: function () { spinner.show(optionsSelector() + \" .add-to-spinner\"); },\r\n hide: function () { spinner.hide(optionsSelector() + \" .add-to-spinner\"); }\r\n };\r\n\r\n var popupSpinner = {\r\n show: function () { spinner.show(popupSelector + \" .spinner-wrapper\"); },\r\n hide: function () { spinner.hide(popupSelector + \" .spinner-wrapper\"); }\r\n };\r\n\r\n function init() {\r\n $(allAddToListButtonsSelector).off(\"click\").on(\"click\", addToListClicked);\r\n $(popupSelector + \" .create-new-list-item\").off(\"click\").on(\"click\", createNewListClicked);\r\n $(popupSelector + \" .new-wishlist-submit-button\").off(\"click\").on(\"click\", createListButtonClicked);\r\n $(popupSelector + \" .new-wishlist-cancel-button\").off(\"click\").on(\"click\", hidePopup);\r\n $(popupSelector + \" .continue-shopping-button\").off(\"click\").on(\"click\", hidePopup);\r\n itemAddedText = $(popupSelector + \" .item-added-text\").text();\r\n\r\n autoTriggerAddToList();\r\n }\r\n\r\n function addToListClicked(event) {\r\n optionsIndex = $(this).closest(\"[data-options-index]\").data(\"optionsIndex\");\r\n if ($(popupSelector).data(\"isAuthenticated\") === \"False\") {\r\n // User has to log in, only then they can add to list.\r\n buttonsSpinner.show();\r\n // Redirect to login page with redirectUrl that will bring the user back here after login or register.\r\n var loginPageUrl = $(popupSelector).data(\"loginPageUrl\");\r\n var redirectAfterLoginUrl = urlUtils.putParamIntoUrl(\"addToListIndex\", optionsIndex, window.location.href);\r\n if (!(isNaN(optionsIndex) && optionsIndex.startsWith(\"all_\"))) {\r\n redirectAfterLoginUrl = urlUtils.putParamIntoUrl(\"addToListVariantSku\", productOptions[optionsIndex].currentVariant.variantSku, redirectAfterLoginUrl);\r\n }\r\n window.location.href = urlUtils.putParamIntoUrl(\"redirectUrl\", redirectAfterLoginUrl, loginPageUrl);\r\n return;\r\n }\r\n if (needToFetchLists) {\r\n getLists();\r\n }\r\n else {\r\n if ($(optionsSelector() + \" button.list\").data(\"plugin_webuiPopover\")) {\r\n // popup already displayed for this button - hide it (we're using the button as toggle)\r\n hidePopup();\r\n }\r\n else {\r\n showPopup();\r\n }\r\n }\r\n }\r\n\r\n function createNewListClicked(event) {\r\n display(\"form\");\r\n }\r\n\r\n function existingListClicked(event) {\r\n addToList({\r\n WishlistId: $(this).data(\"wishlistId\"),\r\n WishlistName: $(this).data(\"wishlistName\")\r\n });\r\n }\r\n\r\n function createListButtonClicked(event) {\r\n event.preventDefault();\r\n var postData = formUtils.collectFormData(formId);\r\n addToList(postData);\r\n }\r\n\r\n function getLists() {\r\n buttonsSpinner.show();\r\n\r\n $.ajax({\r\n type: \"GET\",\r\n url: \"/customapi/Wishlist/GetAddToListWishlists\",\r\n dataType: \"json\",\r\n data: null,\r\n success: function (data) {\r\n if (data.status === \"OK\") {\r\n $(popupSelector + \" .wishlist-items\").empty().html(data.content);\r\n $(popupSelector + \" .wishlist-item\").off(\"click\").on(\"click\", existingListClicked);\r\n needToFetchLists = false;\r\n showPopup();\r\n } else if (data.status === \"ERROR\") {\r\n alertMessage.error(data.message);\r\n }\r\n },\r\n error: function (jq, status, errorThrown) {\r\n alertMessage.error(status + \": \" + errorThrown);\r\n },\r\n complete: function () {\r\n buttonsSpinner.hide();\r\n }\r\n\r\n });\r\n }\r\n\r\n function display(what) {\r\n $(popupSelector + \" .wishlist-popup-section\").addClass(\"d-none\"); // first hide all sections\r\n if (what === \"confirmation\") {\r\n $(popupSelector + \" .added-to-wishlist\").removeClass(\"d-none\");\r\n }\r\n else if (what === \"form\") {\r\n $(popupSelector + \" .create-list-form\").removeClass(\"d-none\");\r\n $(formId + \" #new-wishlist-name\").val(\"\");\r\n $(formId + \" #new-wishlist-name\").focus();\r\n }\r\n else {\r\n // decide based on whether there are any lists already or not\r\n if ($(popupSelector + \" .wishlist-item\").length > 0) {\r\n // there are some wishlists to choose from\r\n $(popupSelector + \" .choose-list\").removeClass(\"d-none\");\r\n }\r\n else {\r\n // there are no wishlists - display the form to enter the first one\r\n $(popupSelector + \" .create-list-form\").removeClass(\"d-none\");\r\n }\r\n }\r\n }\r\n\r\n function showPopup() {\r\n display();\r\n var listButtonSelector = optionsSelector() + \" button.list\";\r\n $(listButtonSelector).webuiPopover({\r\n trigger: \"manual\",\r\n placement: \"bottom-left\",\r\n width: 400,\r\n type: \"html\",\r\n url: popupSelector,\r\n animation: \"fade\",\r\n multi: false,\r\n arrow: true,\r\n closeable: true,\r\n //dismissible: true, works only if trigger is \"click\"\r\n onHide: function (popoverElement) {\r\n // Clone popup HTML to the end of the body because it will disappear when we destroy popover.\r\n // Popup will be cloned from there by WebuiPopover the next time we display it.\r\n $(popupSelector).clone(true).appendTo(\"body\").hide();\r\n $(listButtonSelector).webuiPopover(\"destroy\");\r\n }\r\n });\r\n $(listButtonSelector).webuiPopover(\"show\");\r\n }\r\n\r\n function hidePopup(event) {\r\n $(optionsSelector() + \" button.list\").webuiPopover(\"hide\");\r\n }\r\n\r\n function addToList(postData)\r\n {\r\n formUtils.clearInvalidFeedback(formId);\r\n popupSpinner.show();\r\n\r\n if (isNaN(optionsIndex) && optionsIndex.startsWith(\"all_\")) {\r\n postData.BulkAdd = $(optionsSelector()).data(\"bulkAdd\");\r\n } else {\r\n postData.Quantity = $(optionsSelector() + \" .quantity-selector input\").val();\r\n postData.ProductSku = productOptions[optionsIndex].productSku;\r\n postData.VariantSku = productOptions[optionsIndex].currentVariant.variantSku;\r\n }\r\n formUtils.useToken(postData);\r\n\r\n $.ajax({\r\n type: \"POST\",\r\n url: \"/customapi/Wishlist/AddToWishlist\",\r\n dataType: \"json\",\r\n data: postData,\r\n success: function (data) {\r\n if (data.status === \"OK\") {\r\n $(popupSelector + \" .item-added-text\").text(\r\n itemAddedText\r\n .replace(\"{list_name}\", postData.WishlistName)\r\n .replace(\"{quantity}\", data.numberOfItemsAdded)\r\n );\r\n $(popupSelector + \" .added-to-wishlist .variant-display\").empty().html(data.variantDisplay);\r\n urlUtils.pushParamIntoLink(\"listId\", data.wishlistId, $(popupSelector + \" .go-to-list\"));\r\n if (!postData.WishlistId) needToFetchLists = true; // new list was created, we'll need to refresh the list of lists\r\n $(allSelectListIconsSelector).removeClass(\"d-none\"); // display the icon because now we definitely have at least one list\r\n display(\"confirmation\");\r\n } else if (data.status === \"ERROR\") {\r\n // Something's not right.\r\n // Display the error messages (if any), and field validation messages (if any) and stay on the page.\r\n if (data.message) alertMessage.error(data.message);\r\n formUtils.displayInvalidFeedback(data.invalidFormFields, formId);\r\n }\r\n },\r\n error: function (jq, status, errorThrown) {\r\n alertMessage.error(status + \": \" + errorThrown);\r\n },\r\n complete: function () {\r\n popupSpinner.hide();\r\n }\r\n\r\n });\r\n \r\n }\r\n\r\n function autoTriggerAddToList() {\r\n\r\n setTimeout(function () {\r\n // first we have to determine from query parameters which Add to List button to trigger\r\n var addToListIndex = urlUtils.popParamFromLink(\"addToListIndex\");\r\n var addToListVariantSku = urlUtils.popParamFromLink(\"addToListVariantSku\");\r\n if (!addToListIndex) return;\r\n\r\n optionsIndex = 0;\r\n\r\n if (isNaN(addToListIndex)) {\r\n optionsIndex = addToListIndex;\r\n } else if (productOptions[addToListIndex] && productOptions[addToListIndex].currentVariant.variantSku === addToListVariantSku) {\r\n // Product options index exists and the variant SKU matches.\r\n optionsIndex = addToListIndex;\r\n } else {\r\n // We'll try to find the product options by just variant SKU (because some product options indexes might have changed if the page was reloaded).\r\n optionsIndex = productOptions.findIndex((po) => po && po.currentVariant.variantSku === addToListVariantSku);\r\n }\r\n\r\n var buttonSelector = optionsSelector() + \" button.list\";\r\n if ($(buttonSelector).length) {\r\n $(buttonSelector).trigger(\"click\");\r\n // scroll the button into view if needed\r\n var pageTop = $(window).scrollTop();\r\n var pageBottom = pageTop + $(window).height();\r\n var elementTop = $(buttonSelector).offset().top;\r\n var elementBottom = elementTop + $(buttonSelector).height();\r\n if (elementTop < pageTop || elementBottom > pageBottom) {\r\n $(\"html,body\").animate({ scrollTop: $(buttonSelector).offset().top - 80 });\r\n }\r\n }\r\n }, 1000); // this has to be done with a slight delay because otherwise there are some problems with popup positioning\r\n }\r\n\r\n return {\r\n init: init\r\n };\r\n});\r\n\n", "require([\r\n \"AddToWishlistPopup/addToWishlist\"\r\n],\r\n function (addToWishlist) {\r\n\r\n addToWishlist.init();\r\n window.Coria = window.Coria || {};\r\n window.Coria.reInitAddToWishlistPopup = addToWishlist.init;\r\n\r\n});\r\n\ndefine(\"AddToWishlistPopup/main\", function(){});\n\n" ] }