mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-03 19:53:19 +03:00
36 lines
4.9 KiB
JavaScript
36 lines
4.9 KiB
JavaScript
/**
|
|
* 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.
|
|
*/$(function(){var t={init:function(){this.selects.init(),this.player.init(),this.tabs.init(),this.uploadForm.init(this.settingsTabs.init()),this.popup.init(),this.toggleBox(),this.trimConsultant(),this.showSettings()},selects:{init:function(){var t=this;try{$(".jq-select").SumoSelect(),$("li.opt").each((t,e)=>{if(0===$(e).find("label").html().length){let t=$(e).closest("ul").closest("div").parent().find("select");$(e).find("label").html(t.attr("placeholder")),$(e).addClass("disabled")}}),t.update(),$(document).on("change",".jq-select",function(){t.update()})}catch(t){console.warn("Cannot initialize select: "+t.message)}},update:function(){var t={};let e=$(".retail-tab__enabled").find("select:not(#RETAILCRM_API_DELIVERY_DEFAULT, #RETAILCRM_API_PAYMENT_DEFAULT)");e.each((e,i)=>{var a=$(i).val();a&&a.length&&(t[e]=$('option[value="'+$(i).val()+'"]',$(i)).index())});let i=Object.values(t);e.each((e,a)=>{$("option",a).each((n,s)=>{-1===$.inArray(n,i)||void 0!==t[e]&&t[e]==n?a.sumo.enableItem(n):a.sumo.disableItem(n)})})}},player:{init:function(){window.player={},window.onYouTubeIframeAPIReady=function(){window.player=new YT.Player("player",{height:"100%",width:"100%",videoId:window.RCRMPROMO})};var t=document.createElement("script");t.src="https://www.youtube.com/iframe_api",document.body.appendChild(t)}},settingsTabs:{init:function(){if("undefined"==typeof RCRMTabs)return;let e=new RCRMTabs('div[id^="rcrm_tab_"]',".retail-menu__btn","retail-tab__enabled","retail-tab__disabled","retail-menu__btn_active","retail-menu__btn_inactive","tab-trigger",".rcrm-form-submit-trigger"),i={afterActivate:function(){t.selects.update()}},a={beforeActivate:function(){$("#main-submit").hide()},afterDeactivate:function(){$("#main-submit").show()}};return e.tabsCallbacks({rcrm_tab_delivery_types:i,rcrm_tab_order_statuses:i,rcrm_tab_payment_types:i,rcrm_tab_consultant:a,rcrm_tab_orders_upload:a}),e.initializeTabs(),e}},uploadForm:{init:function(t){"undefined"!=typeof RetailcrmUploadForm&&new RetailcrmUploadForm(t)}},tabs:{init:function(){$(".retail-tabs__btn").on("click",this.swithTab)},swithTab:function(t){t.preventDefault();var e=$(this).attr("href");$(".retail-tabs__btn_active").removeClass("retail-tabs__btn_active"),$(".retail-tabs__item_active").removeClass("retail-tabs__item_active").fadeOut(150,function(){$(e).addClass("retail-tabs__item_active").fadeIn(150)}),$(this).addClass("retail-tabs__btn_active")}},popup:{init:function(){var t=this;$("[data-popup]").on("click",function(e){var i=$(this).data("popup");t.open($(i))}),$(".retail-popup-wrap").on("click",function(e){if($(e.target).hasClass("js-popup-close")){var i=$(this).find(".retail-popup");t.close(i)}})},open:function(t){t&&(t.closest(".retail-popup-wrap").fadeIn(200),t.addClass("open"),player.playVideo())},close:function(t){var e=t.closest(".retail-popup-wrap");t.removeClass("open"),e.fadeOut(200),player.stopVideo()}},toggleBox:function(){$(".toggle-btn").on("click",function(t){t.preventDefault();var e=$(this).attr("href"),i=$(e);$(this).closest(".retail-btns").addClass("retail-btns_hide").slideUp(100),i.slideDown(100)})},trimConsultant:function(){let t=$("#rcrm_tab_consultant textarea");t.text(t.text().trim())},showSettings:function(){$(".retail.retail-wrap.hidden").removeClass("hidden")}};t.init()}); |