{"version":3,"file":"DetailedSearch.min.js","sources":["DetailedSearch.js"],"sourcesContent":["// ReSharper disable StringLiteralTypo\n// ReSharper disable IdentifierTypo\n// ReSharper disable UndeclaredGlobalVariableUsing\n(function($, _, root) {\n 'use strict';\n var assetId = 'uc214-detailedsearch';\n var utils = new Utils();\n\n $(function domReady() {\n if (root.umwAssets && root.umwAssets[assetId]) {\n root.umwAssets[assetId].forEach(function(contextModel) {\n if (contextModel) {\n var mainPanelId = contextModel.mainPanelID;\n var $mainPanel = $('#' + mainPanelId);\n\n if ($mainPanel.length === 1) {\n var searchProccessor = new SearchProccessor($mainPanel, contextModel, utils);\n searchProccessor.init();\n } else if ($mainPanel.length === 0) {\n console.warn(assetId + ': detailed search main panel element was not found by id#' + mainPanelId);\n } else {\n console.warn(assetId + ': found > 1 detailed search main panel elements with id#' + mainPanelId);\n }\n }\n });\n }\n });\n\n function SearchProccessor($mainPanel, contextModel, utils) {\n var _$body = $('body');\n var _$mainPanel = $mainPanel;\n var _contextModel = contextModel;\n var _utils = utils;\n\n var _isFirstLoading = true;\n var _cache = { empty: {} };\n var _$searchInput, _$popupContainer, _$searchClearBtn;\n var _searchDelay = 1000;\n var _popupOpened = false;\n var _searchInProcess = false;\n var _productListController = null;\n var _clearBtnClick = false;\n const detailedSearchEvents = {\n show: 'detailedsearch.popup:show',\n hide: 'detailedsearch.popup:hide',\n onstatechange: 'detailedsearch.popup:onstatechange'\n };\n\n function _init() {\n _$searchClearBtn = _$mainPanel.find('.js-search-clear-input-btn');\n _$searchInput = _$mainPanel.find('.js-search-input');\n\n if (contextModel.alternativePopupContainerSelector) {\n _$popupContainer = $(contextModel.alternativePopupContainerSelector);\n } else {\n _$popupContainer = $('.js-detailed-search-popup');\n }\n\n if (root.PubSub) {\n root.PubSub.subscribe('detailedsearch', function (msg, data) {\n if(data.detailedSearchId !== _contextModel.mainPanelID) return; \n switch (msg) {\n case detailedSearchEvents.show:\n _togglePopup(true);\n break;\n case detailedSearchEvents.hide:\n if (!_searchInProcess) _togglePopup(false);\n break;\n }\n });\n }\n\n $(document).on('click',\n function (e) {\n if (!_$searchInput[0].contains(e.target) && !_$popupContainer[0].contains(e.target)) {\n if (_clearBtnClick) {\n _clearBtnClick = false;\n if(_popupOpened){\n return;\n }\n }\n _togglePopup(false);\n }\n });\n\n /* No need in submit button. Was requested to use clear button instead. Don't delete - can be used in future projects.\n var _$searchBtn = _$mainPanel.find('.js-search-btn');\n _$searchBtn.on('click',\n function(e) {\n var term = $.trim(_$searchInput.val());\n if (term && term.length && term.length >= _contextModel.minTermLength) {\n root.location = root.R + _contextModel.searchUrl + encodeURIComponent(term);\n } else {\n e.preventDefault();\n }\n });\n */\n\n _$searchClearBtn.on('click',\n function () {\n _clearBtnClick = true;\n _$searchInput.val('').focus();\n _$mainPanel.attr('data-input-has-term', 'false');\n }\n );\n\n _$searchInput\n .on('keyup',\n function (e) {\n if (e.key && typeof (e.key) !== 'undefined' && e.key.length && e.key !== 'Unidentified' && !e.repeat) {\n var term = $.trim(_$searchInput.val());\n // Has terms data required to show different icons depends on input state.\n if (term && term.length && term.length > 0) {\n _$mainPanel.attr('data-input-has-term', 'true');\n } else {\n _$mainPanel.attr('data-input-has-term', 'false');\n }\n if (e.key.length === 1 || e.key === 'Backspace' || e.key === 'Delete') {\n if (_searchInProcess) {\n return;\n }\n _searchInProcess = true;\n setTimeout(function () {\n _search();\n _searchInProcess = false;\n }, _searchDelay);\n }\n }\n })\n .on('keypress', function (e) {\n if (e.key && typeof (e.key) !== 'undefined' && e.key.length && e.key !== 'Unidentified' && !e.repeat && e.key === 'Enter') {\n e.preventDefault();\n var term = $.trim(_$searchInput.val());\n if (term && term.length && term.length) {\n root.location = root.R + _contextModel.searchUrl + encodeURIComponent(term);\n }\n }\n })\n .on('focus',\n function () {\n if (root.PubSub) {\n root.PubSub.publish('popup.lockRender');\n }\n _search();\n });\n }\n\n function _generatePopupHtml(searchResultModel) {\n if (_contextModel.popupTemplate) {\n return _.template(_contextModel.popupTemplate, searchResultModel);\n } else {\n console.error('Popup template does not exists in the context model.');\n return '';\n }\n }\n\n function _togglePopup(showOrHide) {\n if (_popupOpened === showOrHide) return;\n // Don't allow to toggle popup state if it's already opened.\n if(showOrHide) {\n //console.log(document.documentElement.getBoundingClientRect().width , window.innerWidth);\n const windowWidth = window.innerWidth;\n const documentWidth = document.documentElement.getBoundingClientRect().width;\n\n let scrollCompensation = windowWidth - documentWidth;\n\n if(scrollCompensation > 0) {\n $(\"body\").get(0).style.setProperty('--scrollbar-compensate', `${scrollCompensation}px`);\n }\n\n _$popupContainer.removeClass('hidden');\n _$body.addClass('detailed-search-modal-is-shown');\n _popupOpened = true;\n } else {\n $(\"body\").get(0).style.setProperty('--scrollbar-compensate', `0`);\n _$popupContainer.addClass('hidden');\n _$body.removeClass('detailed-search-modal-is-shown');\n _popupOpened = false;\n if (root.PubSub) {\n root.PubSub.publish('popup.unlockRender');\n }\n }\n if (root.PubSub) {\n root.PubSub.publish(detailedSearchEvents.onstatechange, { toggleState: showOrHide, detailedSearchId: _contextModel.mainPanelID });\n }\n };\n\n function _setLoadingUI() {\n if (_isFirstLoading) {\n _isFirstLoading = false;\n\n var popupHtml = _generatePopupHtml({ isLoading: true });\n _$popupContainer.empty();\n _$popupContainer.append(popupHtml);\n _togglePopup(true);\n }\n }\n\n function _proccessSearchResult(searchResultModel, searchInput) {\n _$popupContainer.empty();\n\n var searchResultModelEx = $.extend(searchResultModel,\n {\n isLoading: false,\n searchHref: root.R + _contextModel.searchUrl + encodeURIComponent(searchInput),\n labels: _contextModel.labels,\n });\n\n _.each(searchResultModelEx.documentsSection.documents, function (document) {\n // Strip html tags before embedding it into the markup. Documents can contain html which is not compatible with simple text presentation for teaser in detailed search popup.\n document.teaser = document.teaser.replace(/(<([^>]+)>)/gi, '');\n });\n var popupHtml = _generatePopupHtml(searchResultModelEx);\n _$popupContainer.empty();\n _$popupContainer.append(popupHtml);\n\n if (searchResultModelEx.productsSection.productListAssetContext) {\n var productListAssetContext = JSON.parse(searchResultModelEx.productsSection.productListAssetContext);\n if (productListAssetContext &&\n root.createProductListController &&\n typeof (root.createProductListController) == 'function') {\n productListAssetContext.skipFilterEvents = true;\n _productListController = createProductListController(productListAssetContext);\n if (_productListController) {\n _productListController.init();\n }\n }\n }\n\n if (searchResultModelEx.productsSection.productsCount && _$popupContainer.find('.lipscore-rating-small').length && lipscore) {\n lipscore.reInitWidgets();\n }\n\n _togglePopup(true);\n }\n\n function _search() {\n var searchInput = $.trim(_$searchInput.val());\n if (searchInput && searchInput.length && searchInput.length >= _contextModel.minTermLength) {\n\n _setLoadingUI();\n\n var cacheKey = searchInput;\n if (_cache[cacheKey]) {\n _proccessSearchResult(_cache[cacheKey], searchInput);\n } else {\n root.reporWebshopSearchEvent(searchInput);\n $.ajax({\n url: root.R + 'handlers/public/ItemSearch.ashx',\n type: 'GET',\n data: {\n action: 'detailedsearch',\n term: searchInput,\n productListResultsCount: _contextModel.productListResultsCount,\n pageResultsCount: _contextModel.pageResultsCount,\n documentResultsCount: _contextModel.documentResultsCount,\n eventResultsCount: _contextModel.eventResultsCount,\n imageWidth: _contextModel.imageWidth\n }\n })\n .success(function (result) {\n _cache[cacheKey] = result;\n _proccessSearchResult(result, searchInput);\n })\n .error(function (errResp) {\n var errorMessage = _utils.extractErrorMessageFromResponse(errResp);\n console.error('Failed to make search request with term \"' + searchInput + '\". ', errorMessage);\n });\n }\n }\n }\n\n return { init: _init }\n }\n\n function Utils() {\n return {\n extractErrorMessageFromResponse: function(errorResponse) {\n var message;\n if (typeof errorResponse === 'object' && errorResponse !== null) {\n // Extract error message\n try {\n var parsedResponseBody = JSON.parse(errorResponse.responseText);\n message = parsedResponseBody.ExceptionMessage ? parsedResponseBody.ExceptionMessage : (parsedResponseBody.Message ? parsedResponseBody.Message : errorResponse.statusText);\n } catch (e) {\n message = errorResponse.statusText;\n }\n } else {\n message = errorResponse;\n }\n\n return message;\n }\n }\n }\n\n})(jQuery, _, window);"],"names":["$","_","root","assetId","utils","extractErrorMessageFromResponse","errorResponse","parsedResponseBody","JSON","parse","responseText","message","ExceptionMessage","Message","statusText","e","SearchProccessor","$mainPanel","contextModel","_$searchInput","_$popupContainer","_$searchClearBtn","_$body","_$mainPanel","_contextModel","_utils","_isFirstLoading","_cache","empty","_popupOpened","_searchInProcess","_productListController","_clearBtnClick","detailedSearchEvents","show","hide","onstatechange","_generatePopupHtml","searchResultModel","popupTemplate","template","console","error","_togglePopup","showOrHide","scrollCompensation","window","innerWidth","document","documentElement","getBoundingClientRect","width","get","style","setProperty","removeClass","addClass","PubSub","publish","toggleState","detailedSearchId","mainPanelID","_proccessSearchResult","searchInput","searchResultModelEx","extend","isLoading","searchHref","R","searchUrl","encodeURIComponent","labels","popupHtml","each","documentsSection","documents","teaser","replace","append","productsSection","productListAssetContext","createProductListController","skipFilterEvents","init","productsCount","find","length","lipscore","reInitWidgets","_search","cacheKey","trim","val","minTermLength","reporWebshopSearchEvent","ajax","url","type","data","action","term","productListResultsCount","pageResultsCount","documentResultsCount","eventResultsCount","imageWidth","success","result","errResp","errorMessage","alternativePopupContainerSelector","subscribe","msg","on","contains","target","focus","attr","key","repeat","setTimeout","preventDefault","location","umwAssets","forEach","mainPanelId","warn","jQuery"],"mappings":"CAGA,SAAUA,EAAGC,EAAGC,gBAEZ,IAAIC,EAAU,uBACVC,EAAQ,IA6QZ,WACI,MAAO,CACHC,gCAAiC,SAASC,GAEtC,GAA6B,iBAAlBA,GAAgD,OAAlBA,EAErC,IACI,IAAIC,EAAqBC,KAAKC,MAAMH,EAAcI,cAClDC,EAAUJ,EAAmBK,kBAA0DL,EAAmBM,SAAuCP,EAAcQ,WACjK,MAAOC,GACLJ,EAAUL,EAAcQ,gBAG5BH,EAAUL,EAGd,OAAOK,KAvQnB,SAASK,EAAiBC,EAAYC,EAAcd,GAChD,IAOIe,EAAeC,EAAkBC,EAPjCC,EAAStB,EAAE,QACXuB,EAAcN,EACdO,EAAgBN,EAChBO,EAASrB,EAETsB,GAAkB,EACl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