prestashop-module/retailcrm/views/js/retailcrm-tabs.min.js

37 lines
6.1 KiB
JavaScript
Raw Normal View History

function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}/**
* MIT License
*
* Copyright (c) 2020 DIGITAL RETAIL TECHNOLOGIES SL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
* @copyright 2020 DIGITAL RETAIL TECHNOLOGIES SL
* @license https://opensource.org/licenses/MIT The MIT License
*
* Don't forget to prefix your containers with your own identifier
* to avoid any conflicts with others containers.
*/var RCRMTabs=function a(b,c,d,e,f,g,h,i){var j=this,k=!!(8<arguments.length&&arguments[8]!==void 0)&&arguments[8],l=!(9<arguments.length&&arguments[9]!==void 0)||arguments[9];_classCallCheck(this,a),_defineProperty(this,"currentTab",""),_defineProperty(this,"withHistory",!1),_defineProperty(this,"callbacks",{}),_defineProperty(this,"tabsCallbacks",function(a){j.callbacks=a}),_defineProperty(this,"switchTab",function(a){j.isTabExists(a)&&j.activateTab(j.getTab(a))}),_defineProperty(this,"initializeTabs",function(){var a=j.parseUri().rcrmtab||"";$(j.triggerSelector).each(function(a,b){var c=$(b),d=j.getTab(c.data(j.dataTabId));j.isTriggerActive(c)?!j.isTabActive(d)&&j.activateTab(d):j.isTabActive(d)?j.deactivateTab(d):!d.hasClass(j.inactiveTabClass)&&d.addClass(j.inactiveTabClass),c.on("click",function(a){a.preventDefault(),j.switchTab(c.data(j.dataTabId))})}),a!==j.currentTab&&j.isTabExists(a)&&(j.deactivateTab(j.getTab(j.currentTab)),j.activateTab(j.getTab(a))),document.querySelectorAll(j.formSubmitTrigger).forEach(function(a){a.addEventListener("submit",function(a){var b=a.target;j.storeTabInAction(b)})}),j.withHistory&&$(window).bind("popstate",function(a){var b=a.originalEvent.state;"object"===_typeof(b)&&null!==b&&"string"==typeof b.rcrmtab&&0<b.rcrmtab.length&&j.switchTab(b.rcrmtab)})}),_defineProperty(this,"storeTabInAction",function(a){if(a instanceof HTMLFormElement){var b=location.href.replace(location.search,""),c=j.parseUri(a.action.replace(b,""));c.rcrmtab=j.currentTab,a.action=b+j.generateUri(c)}}),_defineProperty(this,"getTab",function(a){return $(document.getElementById(a))}),_defineProperty(this,"getTrigger",function(a){return $("[data-"+j.dataTabId+"=\""+a+"\"]")}),_defineProperty(this,"isTriggerActive",function(a){return a.hasClass(j.activeTriggerClass)}),_defineProperty(this,"isTabActive",function(a){return a.hasClass(j.activeTabClass)}),_defineProperty(this,"isTabExists",function(a){return 0<j.getTrigger(a).length&&1===j.getTab(a).length}),_defineProperty(this,"activateTab",function(a){if(j.deactivateTab(j.getTab(j.currentTab)),!a.hasClass(j.activeTabClass)){var b=j.getTrigger(a.prop("id")),c=$("."+j.activeTriggerClass);if(j.callbacks.hasOwnProperty(a.prop("id"))&&j.callbacks[a.prop("id")].hasOwnProperty("beforeActivate")&&j.callbacks[a.prop("id")].beforeActivate(),c.each(function(a,b){$(b).removeClass(j.activeTriggerClass)}),b.hasClass(j.activeTriggerClass)||(b.removeClass(j.inactiveTriggerClass),b.addClass(j.activeTriggerClass)),a.removeClass(j.inactiveTabClass),a.addClass(j.activeTabClass),j.currentTab=a.prop("id"),j.callbacks.hasOwnProperty(a.prop("id"))&&j.callbacks[a.prop("id")].hasOwnProperty("afterActivate")&&j.callbacks[a.prop("id")].afterActivate(),j.withHistory){var d=j.parseUri();d.rcrmtab=j.currentTab,window.history.pushState({rcrmtab:j.currentTab},j.currentTab,j.generateUri(d))}}}),_defineProperty(this,"deactivateTab",function(a){if(0!==a.length&&a.hasClass(j.activeTabClass)){var b=j.getTrigger(a.prop("id"));j.callbacks.hasOwnProperty(a.prop("id"))&&j.callbacks[a.prop("id")].hasOwnProperty("beforeDeactivate")&&j.callbacks[a.prop("id")].beforeDeactivate(),b.hasClass(j.activeTriggerClass)&&(b.removeClass(j.activeTriggerClass),b.addClass(j.inactiveTriggerClass)),a.removeClass(j.activeTabClass),a.addClass(j.inactiveTabClass),j.callbacks.hasOwnProperty(a.prop("id"))&&j.callbacks[a.prop("id")].hasOwnProperty("afterDeactivate")&&j.callbacks[a.prop("id")].afterDeactivate()}}),_defineProperty(this,"parseUri",function(a){return Object.fromEntries((a||location.search).substr(1).split("&").map(function(a){return a.split("=")}))}),_defineProperty(this,"generateUri",function(a){if(null!=a)return"?"+Object.entries(a).map(function(a){return a.join("=")}).join("&").replace(/\n+/igm,"").trim();throw new Error("Invalid URI data")}),this.tabSelector=b,this.triggerSelector=c,this.activeTabClass=d,this.inactiveTabClass=e,this.activeTriggerClass=f,this.inactiveTriggerClass=g,this.dataTabId=h,this.withHistory=l,this.formSubmitTrigger=i,k&&this.initializeTabs()};