/** * Copyright © 2017 Codazon, Inc. All rights reserved. * See COPYING.txt for license details. */ require(['jquery', 'owlslider'], function($, owlSlider) { /* Common value */ var mBreakpoint = 768, $body = $('body'), $win = $(window), winwidth = window.outerWidth, deskPrefix = 'desk_', mobiPrefix = 'mobi_', disHovImg = $body.hasClass('product-disable-hover-img'), deskEvent = 'cdz_desktop', mobiEvent = 'cdz_mobile', winWidthChangedEvent = 'cdz_window_width_changed', itOneSec = false; if (typeof window.windowLoaded == 'undefined') window.windowLoaded = false; window.intervalOneSec = (func) => { if (!itOneSec) itOneSec = setInterval(() => $win.trigger('itOneSec'), 1000); $win.on('itOneSec', func); }; if (1){let t = $, i=t(window),e=!1,r={};function n(e,r){var n=e.filter(function(){var e=t(this);if(!e.is(":hidden")){var n=i.scrollTop(),a=n+i.height(),s=e.offset().top;return s+e.height()>=n-r&&s<=a+r}});e=e.not(n.trigger("unveil"))}t.fn.cdzLazy=function(a,s){var o=Math.random(),h=a||0,u=window.devicePixelRatio>1?"data-src-retina":"data-src";return r[o]={img:this,th:h},this.one("unveil",function(){var i=this.getAttribute(u),e=this.tagName.toLowerCase();(i=i||this.getAttribute("data-src"))&&("img"===e||"iframe"===e?this.setAttribute("src",i):t(this).css("background-image",`url(${i})`),"function"==typeof s&&s.call(this),delete r[o])}),n(this,h),e||(e=()=>{t.each(r,(t,i)=>{n(i.img,i.th)})},i.on("scroll.unveil resize.unveil lookup.unveil",e),intervalOneSec(e)),this};} if (window.codazon === undefined) window.codazon = {}; $body.on('contentUpdated', () => { require(['mage/apply/main'], (mage) => { if (mage) mage.apply(); }); }); /* jQuery functions */ $.fn.searchToggle = function(options) { var defaultConf = { toggleBtn: '[data-role=search_toggle]', searchForm: '[data-role=search_form]', toggleClass: 'input-opened', mbClass: 'mb-search' }, conf = $.extend({}, defaultConf, options); return this.each(function() { var $el = $(this), $searchForm = $(conf.searchForm, $el), mbSearch = () => { $el.addClass(conf.mbClass); $searchForm.removeClass('hidden-xs'); }, dtSearch = () => { $el.removeClass(conf.mbClass); $searchForm.addClass('hidden-xs'); }; $(conf.toggleBtn, $el).on('click', () => $el.toggleClass(conf.toggleClass)); themecore.isMbScreen() ? mbSearch() : dtSearch(); $win.on(deskEvent, dtSearch).on(mobiEvent, mbSearch); }); } /* Common functions */ window.themecore = function() { return this; }; var thc = themecore; thc.stickyMenu = () => { if ($('.js-sticky-menu').length) require(['themewidgets'], function() {$.codazon.stickyMenu({}, $('.js-sticky-menu'));}); }; thc.backToTop = () => { if ($('#back-top').length == 0) $('
').appendTo('body'); $('[data-role="back_top"]').each(function() { var $bt = $(this); $bt.on('click', function(e) { e.preventDefault(); $('html, body').animate({'scrollTop':0},800); }); function toggleButton(hide) { hide ? $bt.fadeOut(300) : $bt.fadeIn(300); } var hide = ($win.scrollTop() < 100); toggleButton(hide); $win.on('scroll', () => { var newState = ($win.scrollTop() < 100); if(newState != hide){ hide = newState; toggleButton(hide); } }); }); } thc.b64DecodeUnicode = (str) => { return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); }; thc.isMbScreen = (breakP) => { if (typeof breakP === 'undefined') breakP = mBreakpoint; return (window.innerWidth < breakP); }; thc.isDtScreen = (breakP) => { if (typeof breakP === 'undefined') breakP = mBreakpoint; return (window.innerWidth >= breakP); }; thc.uniqid = (prefix) => { return (prefix ? prefix : '') + Math.random().toString().substring(2,8); }; thc.triggerAdaptScreen = (breakP) => { if (typeof breakP === 'undefined') breakP = mBreakpoint; var eventSuffix = (breakP == mBreakpoint)? '' : '_' + breakP, winwidth = window.outerWidth, triggerMedia = () => { thc.isMbScreen(breakP) ? $win.trigger(mobiEvent + eventSuffix) : $win.trigger(deskEvent + eventSuffix); }, checkAdpatChange = () => { var curwidth = window.outerWidth; if ( ((winwidth < breakP) && (curwidth >= breakP) ) || ( (winwidth >= breakP) && (curwidth < breakP)) ) { $win.trigger('adaptchange' + eventSuffix); triggerMedia(); } winwidth = curwidth; }, t = false; $win.on('resize', () => { if(t) clearTimeout(t); t = setTimeout(checkAdpatChange, 50); }); triggerMedia(); }; thc.autoTrigger = () => { $body.on('click', '[data-autotrigger]', function(e) { e.preventDefault(); $($(this).data('autotrigger')).first().trigger('click'); }); } thc.moveElToNewContainer = (fromPrefix, toPrefix) => { $(`[id^="${fromPrefix}"]`).each(function() { $(this).children().appendTo('#' + toPrefix + this.id.substr(fromPrefix.length)); }); }; thc.moveFromSourceElement = () => { $('[data-movefrom]').each(function() { var $dest = $(this), $source = $($dest.data('movefrom')).first(); $dest.replaceWith($source); }); }; thc.setupMobile = () => { thc.moveElToNewContainer(deskPrefix, mobiPrefix); }; thc.setupDesktop = () => { thc.moveElToNewContainer(mobiPrefix, deskPrefix); }; thc.winWidthChangedEvent = () => { var curwidth = window.outerWidth; $win.on('resize', () => { if (window.outerWidth != curwidth) { curwidth = window.outerWidth; $win.trigger(winWidthChangedEvent, [curwidth]); } }); }; thc.scrollTo = () => { $body.on('click', '[data-scollto]', function(e) { e.preventDefault(); var $button = $(this), $dest = $($button.data('scollto')); if ($dest.is(':visible')) { $('html, body').animate({scrollTop: $dest.offset().top - 100}, 300); } else { if ($dest.parents('[role=tabpanel]').length) { $('a.switch[href="#' + $dest.parents('[role=tabpanel]').first().attr('id') + '"]').click(); setTimeout(() => { $('html, body').animate({scrollTop: $dest.offset().top - 100}, 300); }, 300); } } }); }; thc.updateFormKey = () => { $('.product-item form [name=form_key]').val($('input[name=form_key]').first().val()); } thc.cdzLazyImage = () => { $('[data-lazysrc]').each(function() { var $img = $(this).attr('src', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8Xw8AAoMBgDTD2qgAAAAASUVORK5CYII='); if ($img.attr('width') && $img.attr('height') && (!$img.parent().hasClass('abs-img'))) { $img.wrap($('').css({paddingBottom: (100*$img.attr('height'))/$img.attr('width') + '%'})); } $img.addClass('cdz-lazy owl-lazy').attr('data-src', $img.data('lazysrc')).removeAttr('data-lazysrc').cdzLazy(100, function() { $img.removeClass('cdz-lazy owl-lazy').css('display', ''); }); }); } thc.init = function() { this.triggerAdaptScreen(); this.triggerAdaptScreen(1200); this.winWidthChangedEvent(); var sht, lt = false, setupScr = () => {this.isMbScreen() ? this.setupMobile() : this.setupDesktop();}; $win.on(deskEvent, this.setupDesktop) .on(mobiEvent, this.setupMobile) .on(winWidthChangedEvent, () => { if (sht) clearTimeout(sht); sht = setTimeout(this.makeSameHeight, 300); }); this.cdzLazyImage(); $body.on('contentUpdated cdzResize', () => { if (sht) clearTimeout(sht); sht = setTimeout(this.makeSameHeight, 100); }).on('cdzTabsOpened', (e, $tab) => { if (sht) clearTimeout(sht); sht = setTimeout(() => { this.makeSameHeight($tab); }, 100); }).on('swatch.initialized', (e) => { this.makeSameHeight($(e.target).parents('[data-sameheight]').first().parent()); }); $(document).ajaxComplete(() => { if (lt) clearTimeout(lt); lt = setTimeout(this.cdzLazyImage, 500); }); setupScr(); this.toggleMobileMenu(); this.autoTrigger(); this.qtyControl(); this.remoteSliderNav(); this.scrollTo(); this.mobiProductViewTabs(); this.addNumControl(); require(['domReady!'], () => { this.mbtoolbar(); this.toggleContent(); this.moveFromSourceElement(); this.attachCustomerInfo(); this.verticalMenu(); this.backToTop(); setupScr(); }); $body.on('contentUpdated', () => { this.toggleContent(); this.cdzLazyImage(); this.addNumControl(); }); this.makeSameHeight(); var onLoaded = () => { this.ajaxHandler(); this.stickyMenu(); this.makeSameHeight(); this.updateFormKey(); this.qtyControl(); this.addNumControl(); this.sectionMenu(); setupScr(); } window.windowLoaded ? onLoaded() : $win.on('load', onLoaded); }; thc.ajaxHandler = () => { $(document).ajaxStart(() => { $body.addClass('cdz-ajax-loading'); }); $(document).ajaxStop(() => { $body.removeClass('cdz-ajax-loading'); }); }; thc.remoteSliderNav = () => { $body.on('click', '[data-targetslider]', function() { var $btn = $(this), sliderId = $btn.data('targetslider'), $slider = $('#' + sliderId).find('.owl-carousel'); if ($slider.length) $btn.hasClass('owl-prev') ? $slider.trigger('prev.owl.carousel') : $slider.trigger('next.owl.carousel'); }); }; thc.attachCustomerInfo = function() { function loadCustomerInfo() { if ($('[data-customerinfo]').length) { $.ajax({ url: codazon.customerDataUrl, type: "get", cache: false, success: (data) => { var customer = data.customer if (customer) { $('[data-customerinfo]').each(function() { var $info = $(this), info = $info.data('customerinfo'); $info.removeAttr('data-customerinfo'); if (customer[info]) { $info.replaceWith(customer[info].replace(/(<([^>]+)>)/ig,'')); } }); } } }); } } loadCustomerInfo(); $body.on('contentUpdated', loadCustomerInfo); }; thc.mbtoolbar = function() { var $toolbar = $('#mb-bottom-toolbar'), $btnSlider = $('[data-role=group-slider]', $toolbar), $switcher = $('[data-role=switch-group]'), clicked = false; $btnSlider.owlCarousel({ items: 1, dots: false, nav: false, animateIn: 'changing', animateOut: false, touchDrag: false, mouseDrag: false, rtl: $body.hasClass('rtl-layout'), onChanged: function(property) { if (clicked) { var dotsCount = $switcher.find('.dot').length; $switcher.toggleClass('return'); $switcher.find('.dot').each((i, el) => { var $dot = $(el); setTimeout(() => { $dot.removeClass('wave-line').addClass('wave-line'); setTimeout(() => { $dot.removeClass('wave-line'); }, 1000); }, i*100); }); setTimeout(() => { $btnSlider.find('.owl-item').removeClass('changing animated'); },300); clicked = false; } } }); var owl = $btnSlider.data('owl.carousel'), slideTo = 0; $switcher.on('click', (e) => { clicked = true; e.preventDefault(); slideTo = !slideTo; owl.to(slideTo, 1, true); }); var $currentDisplay = false, $currentPlaceholder = $('