{"version":3,"file":"umw.tabbuilder.min.js","sources":["umw.tabbuilder.js"],"sourcesContent":["(function ($, _) {\n 'use strict';\n\n const dataAttributes = {\n containerSelector: 'umw-tab-container',\n tabName: 'umw-tab-name',\n tabClass: 'umw-tab-class',\n position: 'umw-tab-position'\n };\n\n const $umwTabsContainers = $('.js-umw-tabs-check-if-empty');\n\n $(function () {\n var selectorsMap = {}, tabContainerMap = {};\n $('[data-' + dataAttributes.containerSelector + ']').each(function () {\n var $content = $(this);\n $content.find('script').remove(); // Clear scripts inside the moving nodes in order to prevent double-executing\n\n let hasContent = false;\n\n if($content.hasClass('uc-product-view__product-tab-pane-description')) {\n hasContent = true;\n } else {\n hasContent = $.trim($content.text()).length > 0 || $content.find('iframe').length > 0 || $content.find('img').length > 0;\n }\n\n if (hasContent) {\n var containerSelector = $content.data(dataAttributes.containerSelector);\n\n var $tabsContainer;\n if (selectorsMap[containerSelector]) {\n $tabsContainer = selectorsMap[containerSelector];\n } else {\n // Multiple elements can be found by a single selector. We can not clone content to every found tabs container because scripts of cloned content will become broken.\n // Therefore, always use the first found element as a single tabs container\n $tabsContainer = selectorsMap[containerSelector] = $(containerSelector).first();\n }\n\n if (!$tabsContainer.length) {\n console.error('[UMW]: Tab builder - Cannot find tabs container by \"' + containerSelector + '\" selector');\n return;\n }\n\n // Get or define unique tab container id attribute\n var tabContUniqueId = $tabsContainer.attr('id');\n if (!tabContUniqueId) {\n $tabsContainer.attr('id', tabContUniqueId = _.uniqueId('tabCont'));\n }\n\n // The same tabs container can be found by different selector. Merge if the same container was already found by different selector\n if (!tabContainerMap[tabContUniqueId]) {\n tabContainerMap[tabContUniqueId] = [];\n }\n\n var tabDetails = {\n $content: $content,\n tabName: _getTabTitle($content),\n position: $content.data(dataAttributes.position),\n containerId: _getTabContainerId($content),\n tabClass: $content.data(dataAttributes.tabClass)\n }\n\n tabContainerMap[tabContUniqueId].push(tabDetails);\n }\n });\n\n if (!_.isEmpty(tabContainerMap)) {\n\n // Check URL for speific parameter \"tab\", to preselect tab at build\n const searchParams = new URLSearchParams(window.location.search);\n let urlPreselectedTabName = null;\n\n for (let param of searchParams) {\n if (param[0] === \"tab\") {\n urlPreselectedTabName = param[1].toLowerCase();\n break;\n }\n }\n\n _.each(tabContainerMap, function (tabDetailsList, containerUniqueId) {\n var $tabsContainer = $('#' + containerUniqueId);\n var hasActiveTabs = false;\n var sourceContainerIds = [];\n var overrideActiveState = false;\n\n var $navTabs = $tabsContainer.find('.nav-tabs');\n if ($navTabs.length > 0) {\n $navTabs.detach();\n\n hasActiveTabs = $navTabs.find('.active').length > 0;\n } else {\n $navTabs = _$createElem('ul', 'nav nav-tabs', { 'role': 'tablist' });\n }\n\n var $tabPanes = $tabsContainer.find('.tab-content');\n if ($tabPanes.length > 0) {\n $tabPanes.detach();\n } else {\n $tabPanes = _$createElem('div', 'tab-content');\n }\n\n var sorted = _.sortBy(tabDetailsList, 'position');\n var grouped = _.groupBy(sorted, 'tabName');\n\n // Add all source containers IDs to array to compare with Url seach param\n if (urlPreselectedTabName) {\n _.each(grouped, function (contentParts) {\n sourceContainerIds.push(contentParts[0].containerId);\n });\n overrideActiveState = _.indexOf(sourceContainerIds, urlPreselectedTabName) > 0 ? true : false;\n }\n\n _.each(grouped, function (contentParts, tabName) {\n var tabId = _.uniqueId(containerUniqueId + '_tab');\n var isActiveTab = !hasActiveTabs && (hasActiveTabs = true); // Set tab as active if there are no active tabs yet\n if (overrideActiveState) { // Override selected tab if selected tab parameter for selected tab passet by URL\n isActiveTab = false;\n if (urlPreselectedTabName === contentParts[0].containerId) {\n isActiveTab = true;\n }\n }\n\n // Nav tab\n if ($(\"body\").hasClass(\"bs5\")) {\n const $tabNavAnchor = _$createElem('button', isActiveTab ? 'nav-link active' : 'nav-link', { 'type': 'button', 'id': tabId + '-tab', 'data-bs-toggle': 'pill', 'data-bs-target': '#' + tabId, 'role': 'tab', 'aria-controls': tabId, 'aria-selected': 'false' }, tabName);\n const liClass = 'nav-item' + (contentParts[0] && contentParts[0].tabClass ? ' ' + contentParts[0].tabClass : '');\n _$createElem('li', liClass, { 'role': 'presentation' }).append($tabNavAnchor).appendTo($navTabs);\n } else {\n const $tabNavAnchor = _$createElem('a', null, { 'href': '#' + tabId, 'aria-controls': tabId, 'role': 'tab', 'data-toggle': 'tab' }, tabName);\n const liClass = ((isActiveTab ? 'active' : '') + (contentParts[0] && contentParts[0].tabClass ? ' ' + contentParts[0].tabClass : '')).trim();\n _$createElem('li', liClass, { 'role': 'presentation' }).append($tabNavAnchor).appendTo($navTabs);\n }\n\n // Tab pane\n const tabClass = 'tab-pane ' + ((isActiveTab ? ' active' : '') + (contentParts[0] && contentParts[0].tabClass ? ' ' + contentParts[0].tabClass : '')).trim();\n var $tabPane = _$createElem('div', tabClass, { 'id': tabId, 'role': 'tabpanel' }).appendTo($tabPanes);\n _.each(contentParts, function (part) {\n // Prepare the content\n part.$content.detach();\n\n // Make the content visible in case it is hidden: inline styles or \"hidden\" attribute\n part.$content.removeClass('hidden').show(); \n part.$content.removeAttr('hidden');\n\n part.$content.appendTo($tabPane);\n });\n });\n\n $tabsContainer.append($navTabs, $tabPanes);\n\n $tabsContainer.show();\n });\n } else {\n // Markup trash collector, if empty container exists. \n // In case specific control builds the tabs but can't check content model of related to him controls at the same page, which participates in tab building process. \n $umwTabsContainers.each(function () {\n var $this = $(this);\n if ($this.text().length === 0) $this.remove();\n });\n }\n });\n\n function _$createElem(tag, className, attributes, textContent) {\n var elem = document.createElement(tag);\n\n if (className) {\n elem.className = className;\n }\n\n if (attributes) {\n _.each(attributes, function (attrValue, attrName) {\n elem.setAttribute(attrName, attrValue);\n });\n }\n\n if (textContent) {\n elem.textContent = textContent;\n }\n\n return $(elem);\n }\n\n function _getTabTitle($tabContent) {\n var tabTitle = $tabContent.data(dataAttributes.tabName); // Preferred way\n if (!tabTitle) {\n tabTitle = $tabContent.prevAll('input:hidden.TabTitle').val() ||\n $tabContent.find('.js-tab-name,.Title,.MainTitle').first().text() ||\n _.uniqueId('Tab ');\n }\n\n return tabTitle;\n }\n\n function _getTabContainerId($tabContent) {\n var tabContainerId = $tabContent.attr('id');\n if (tabContainerId) {\n tabContainerId = tabContainerId.toLowerCase();\n }\n return tabContainerId;\n }\n})(jQuery, _);"],"names":["$","_","dataAttributes","containerSelector","tabName","tabClass","position","$umwTabsContainers","_$createElem","tag","className","attributes","textContent","elem","document","createElement","each","attrValue","attrName","setAttribute","selectorsMap","tabContainerMap","tabContUniqueId","tabDetails","$content","this","find","remove","let","hasContent","hasClass","trim","text","length","data","$tabsContainer","first","attr","uniqueId","$tabContent","tabTitle","prevAll","val","_getTabTitle","containerId","tabContainerId","toLowerCase","_getTabContainerId","push","console","error","isEmpty","$this","param","searchParams","URLSearchParams","window","location","search","urlPreselectedTabName","tabDetailsList","containerUniqueId","hasActiveTabs","sourceContainerIds","overrideActiveState","$navTabs","$tabPanes","detach","role","sorted","sortBy","grouped","groupBy","contentParts","indexOf","$tabNavAnchor","tabId","isActiveTab","type","id","data-bs-toggle","data-bs-target","aria-controls","aria-selected","append","appendTo","href","data-toggle","$tabPane","part","removeClass","show","removeAttr","jQuery"],"mappings":"CAAA,SAAWA,EAAGC,gBAGV,MAAMC,EAAiB,CACnBC,kBAAmB,oBACnBC,QAAS,eACTC,SAAU,gBACVC,SAAU,oBAGRC,EAAqBP,EAAE,+BAwJ7B,SAASQ,EAAaC,EAAKC,EAAWC,EAAYC,GAC9C,IAAIC,EAAOC,SAASC,cAAcN,GAgBlC,OAdIC,IACAG,EAAKH,UAAYA,GAGjBC,GACAV,EAAEe,KAAKL,EAAY,SAAUM,EAAWC,GACpCL,EAAKM,aAAaD,EAAUD,KAIhCL,IACAC,EAAKD,YAAcA,GAGhBZ,EAAEa,GAvKbb,EAAE,WACE,IAAIoB,EAAe,GAAIC,EAAkB,GAqDzC,GApDArB,EAAE,SAAWE,EAAeC,kBAAoB,KAAKa,KAAK,WACtD,IAYQb,EAiBAmB,EAUAC,EAvCJC,EAAWxB,EAAEyB,MACjB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