{"version":3,"sources":["webpack:///./cartridges/app_accelerator_core/cartridge/client/default/js/modules/module.wishlist-trigger.js","webpack:///./cartridges/app_accelerator_core/cartridge/client/default/js/wishlist/wishlistUtils.js"],"names":["_handleWishlistResponse","response","success","updateTriggersByID","pid","type","listIsEmpty","modules","tracking","init","trackEvent","trackObject","asyncParams","listValue","inWishlist","progress","_wishlistRequest","url","options","arguments","length","undefined","useGET","$","ajax","dataType","data","optionId","optionVal","selectedValueId","error","_handleWishlistTrigger","evt","triggerData","getTriggerData","isRemove","window","SFRA","Urls","wishlistRemoveProduct","wishlistAddProduct","preventDefault","_handleInWishlistCheckResponse","itemsInList","forEach","currentID","_requestInWishlistCheck","itemList","wishlistInList","JSON","stringify","setupWishlistTriggers","existInWishlist","callbackOnElements","elements","currentTrigger","triggerType","getTriggerType","push","removeAttribute","setAttribute","addEventListener","triggerEl","getAttribute","concat","updateTriggerState","productContainer","getProductContainer","customLabel","triggerLabel","triggerTitle","isCTA","socialShareEl","document","querySelector","classList","remove","add","Resources","wishlistAdd","wishlistRemove","title","labelTarget","textContent","hasAttribute","getPidValue","getOptions","updateWishlistTriggers","containerEl","wishlistTriggers","querySelectorAll","call"],"mappings":";;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAa;;AAEsC;AACV;AACoB;AACgC;;AAE7F;AACA;AACA;AACA;AACA;AACA,SAASA,uBAAuBA,CAACC,QAAQ,EAAE;EACvC,IAAIA,QAAQ,CAACC,OAAO,EAAE;IAClBC,kFAAkB,CAACF,QAAQ,CAACG,GAAG,EAAEH,QAAQ,CAACI,IAAI,KAAK,QAAQ,EAAEJ,QAAQ,CAACK,WAAW,CAAC;IAElF,IAAIL,QAAQ,CAACI,IAAI,KAAK,QAAQ,EAAE;MAC5BE,wDAAO,CAACC,QAAQ,CAACC,IAAI,CAAC,IAAI,EAAE;QACxBC,UAAU,EAAE,iBAAiB;QAC7BC,WAAW,EAAE;UACTC,WAAW,EAAE;YACTR,GAAG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,EAAE;EACtC,OAAO;IACH3B,QAAQ,EAAE2B,SAAS,CAACsB,YAAY,CAAC,sBAAsB,CAAC;IACxDhF,GAAG,EAAEiF,yEAAW,CAACvB,SAAS,CAAC;IAC3B5C,OAAO,EAAEoE,wEAAU,CAACxB,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACvCjD,SAAS,EAAEiD,SAAS,CAACC,YAAY,CAAC,uBAAuB;EAC7D,CAAC;AACL;;AAEA;AACA;AACA;AACO,SAASwB,sBAAsBA,CAACC,WAAW,EAAErD,QAAQ,EAAE;EAC1D,IAAIsD,gBAAgB,GAAGD,WAAW,CAACE,gBAAgB,CAAC,+BAA+B,CAAC;EAEpF,EAAE,CAAC9C,OAAO,CAAC+C,IAAI,CAACF,gBAAgB,EAAE,UAAAlC,cAAc;IAAA,OAAIU,kBAAkB,CAACV,cAAc,EAAEpB,QAAQ,CAAC;EAAA,EAAC;AACrG,C","file":"module-wishlist-trigger.js","sourcesContent":["'use strict';\n\nimport * as progress from '../components/progress';\nimport modules from '../helpers/modules';\nimport {callbackOnElements} from '@borngroup/born-utilities';\nimport {updateTriggersByID, getTriggerData, getTriggerType} from '../wishlist/wishlistUtils';\n\n/**\n * appends params to a url\n * @param {string} data - data returned from the server's ajax call\n * @param {Object} icon - icon that was clicked to add a product to the wishlist\n */\nfunction _handleWishlistResponse(response) {\n if (response.success) {\n updateTriggersByID(response.pid, response.type === 'remove', response.listIsEmpty);\n\n if (response.type !== 'remove') {\n modules.tracking.init(null, {\n trackEvent: 'add_to_wishlist',\n trackObject: {\n asyncParams: {\n pid: response.pid,\n listValue: response.listValue\n }\n }\n });\n }\n\n } else if (response.inWishlist) {\n //If `success`` is false, and the item is already in the wishlist, update the trigger to reflect that.\n updateTriggersByID(response.pid);\n }\n\n progress.hideLoader();\n}\n\n/**\n * Requests a Wishlist endpoint call to the server.\n */\nfunction _wishlistRequest(url, pid, options = {}, listValue, useGET) {\n $.ajax({\n url: url,\n type: useGET ? 'GET' : 'POST',\n dataType: 'json',\n data: {\n pid: pid,\n optionId: options.optionId,\n optionVal: options.selectedValueId,\n listValue: listValue\n },\n success: _handleWishlistResponse,\n error: _handleWishlistResponse\n });\n}\n\n/**\n * Handles an event (typically a click) on a `wishlist-trigger` element.\n * @param {[type]} evt [description]\n * @return {[type]} [description]\n */\nfunction _handleWishlistTrigger(evt) {\n let triggerData = getTriggerData(this),\n url = triggerData.isRemove ? window.SFRA.Urls.wishlistRemoveProduct : window.SFRA.Urls.wishlistAddProduct;\n\n evt.preventDefault();\n\n if (!url || !triggerData.pid) {\n return;\n }\n\n progress.showLoader(this);\n\n _wishlistRequest(url, triggerData.pid, triggerData.options, triggerData.listValue, triggerData.isRemove);\n}\n\n/**\n * Handles the response for the `InWishlist` endpoint request.\n * @param {[type]} response [description]\n * @return {[type]} [description]\n */\nfunction _handleInWishlistCheckResponse(response) {\n if (response.success) {\n response.itemsInList.forEach(currentID => updateTriggersByID(currentID));\n }\n}\n\n/**\n * Uses `itemList` to request a server check on the items that are already part of the current user's wishlist.\n * @param {[type]} itemList [description]\n * @return {[type]} [description]\n */\nfunction _requestInWishlistCheck(itemList) {\n return $.ajax({\n url: window.SFRA.Urls.wishlistInList,\n type: 'POST',\n dataType: 'json',\n data: {\n itemList: JSON.stringify(itemList)\n },\n success: _handleInWishlistCheckResponse\n });\n}\n\n/**\n * Initializes `wishlist-trigger` elements.\n * @param {[type]} options [description]\n * @return {[type]} [description]\n */\nfunction setupWishlistTriggers(options) {\n let existInWishlist = [];\n\n callbackOnElements(options.elements, function(currentTrigger) {\n let triggerType = getTriggerType(currentTrigger);\n\n existInWishlist.push(getTriggerData(currentTrigger));\n\n currentTrigger.removeAttribute('data-wishlist-trigger');\n currentTrigger.setAttribute('data-wishlist-trigger-ready', triggerType);\n\n currentTrigger.addEventListener('click', _handleWishlistTrigger);\n });\n\n return _requestInWishlistCheck(existInWishlist);\n}\n\nexport const init = setupWishlistTriggers;\n","'use strict';\n\nimport {callbackOnElements} from '@borngroup/born-utilities';\nimport {getProductContainer, getPidValue, getOptions} from '../product/productUtils';\n\nexport function getTriggerType(triggerEl) {\n return triggerEl.getAttribute('data-wishlist-trigger') || triggerEl.getAttribute('data-wishlist-trigger-ready') || 'cta';\n}\n\n/**\n * Multiple items with the same ID might exist on the same page, ensure they're all accounted for.\n * @param {[type]} currentID [description]\n * @param {Boolean} isRemove [description]\n * @return {[type]} [description]\n */\nexport function updateTriggersByID(currentID, isRemove, listIsEmpty) {\n callbackOnElements(`[data-pid=\"${currentID}\"] [data-wishlist-trigger-ready]`, function(currentTrigger) {\n updateTriggerState(currentTrigger, isRemove, listIsEmpty);\n });\n}\n\n/**\n * Updates the provided `triggerEl` state to reflect a requested server or event change.\n */\nexport function updateTriggerState(triggerEl, isRemove, listIsEmpty) {\n let productContainer = getProductContainer(triggerEl),\n triggerType = getTriggerType(triggerEl),\n customLabel = '',\n triggerLabel = '',\n triggerTitle = '',\n isCTA = triggerType === 'cta',\n socialShareEl = document.querySelector('[data-wishlist-component=\"share\"]');\n\n if (isRemove) {\n triggerEl.classList.remove('set--in-wishlist');\n productContainer.classList.remove('set--in-wishlist');\n productContainer.classList.add('set--removed-wishlist');\n triggerEl.removeAttribute('data-wishlist-remove');\n\n customLabel = triggerEl.getAttribute('data-wishlist-label-add');\n\n //These might differ in the future, so keep separate.\n triggerTitle = customLabel || window.SFRA.Resources.wishlistAdd;\n triggerLabel = customLabel || window.SFRA.Resources.wishlistAdd;\n } else {\n triggerEl.classList.add('set--in-wishlist');\n productContainer.classList.add('set--in-wishlist');\n productContainer.classList.remove('set--removed-wishlist');\n triggerEl.setAttribute('data-wishlist-remove', true);\n\n customLabel = triggerEl.getAttribute('data-wishlist-label-remove');\n\n triggerTitle = customLabel || window.SFRA.Resources.wishlistRemove;\n triggerLabel = customLabel || window.SFRA.Resources.wishlistRemove;\n }\n\n triggerEl.title = triggerTitle;\n\n if (isCTA) {\n let labelTarget = triggerEl.querySelector('[data-wishlist-trigger-component=\"label\"]') || triggerEl;\n\n labelTarget.textContent = customLabel || triggerLabel;\n }\n\n if (socialShareEl) {\n if (listIsEmpty) {\n socialShareEl.classList.add('hidden');\n } else {\n socialShareEl.classList.remove('hidden');\n }\n }\n}\n\n/**\n * Gets common Wishlist Trigger data such as PID, selected options, etc.\n */\nexport function getTriggerData(triggerEl) {\n return {\n isRemove: triggerEl.hasAttribute('data-wishlist-remove'),\n pid: getPidValue(triggerEl),\n options: getOptions(triggerEl)[0] || {},\n listValue: triggerEl.getAttribute('data-tracking-context')\n };\n}\n\n/**\n * Updates the wishlist triggers for a given container.\n */\nexport function updateWishlistTriggers(containerEl, isRemove) {\n let wishlistTriggers = containerEl.querySelectorAll('[data-wishlist-trigger-ready]');\n\n [].forEach.call(wishlistTriggers, currentTrigger => updateTriggerState(currentTrigger, isRemove));\n}\n"],"sourceRoot":""}