/** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ /* Theme JS */ require([ 'jquery', 'mage/cookies', 'domReady!' ], function ($) { 'use strict'; /* dynamic input size for overlay search */ $.fn.textWidth = function (text, font) { if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('').hide().appendTo(document.body); $.fn.textWidth.fakeEl.text(text || this.val() || this.text() || this.attr('placeholder')).css({ 'font': font || this.css('font'), 'text-transform': 'uppercase', 'letter-spacing': this.css('letter-spacing') }); return $.fn.textWidth.fakeEl.width(); }; $('.width-dynamic').on('input', function () { var inputWidth = $(this).textWidth() + 40; //40 is padding $(this).css({ width: inputWidth }) }).trigger('input'); $('.width-dynamic').blur(function () { if (!$(this).val().length) { $(this).css({ width: '' }) } }); /* input plus minus */ $("body").on('click', ".qty-controls-wrap .qty-plus", function (event) { event.preventDefault(); var _input = $(this).parent().find('input'); _input.val(parseInt(_input.val()) + 1); _input.change(); $(this).parent().find('button.update-cart-item').show(); }); $("body").on('click', ".qty-controls-wrap .qty-minus", function (event) { event.preventDefault(); var _input = $(this).parent().find('input'); var count = parseInt(_input.val()) - 1; count = count < 0 ? 0 : count; _input.val(count).change(); $(this).parent().find('button.update-cart-item').show(); }); $("body").on('change', ".qty-controls-wrap input", function () { var $this = $(this); var min = 0; var val = parseInt($this.val(), 10); var max = 10000000; val = Math.min(val, max); val = Math.max(val, min); if (isNaN(val)) { val = 0; } $this.val(val); $this.trigger('keypress'); }); /* Filter toggle */ var item = $('.block.filter, .filters-slideout-content').find('.filter-options, .filter-current'), itemContent = item.find('.filter-options-content, .ox-toggle-content'); if (item.length) { item.each(function () { if ($(this).hasClass('collapsible')) { if ($(this).hasClass('open')) { $(this).find(itemContent).slideDown(function () { $('body').trigger('oxToggleUpdated'); }); } else { $(this).find(itemContent).slideUp(function () { $('body').trigger('oxToggleUpdated'); }); } } }); $(document).on('click', '.filter-options-title, .filter-current-subtitle', function (e) { e.preventDefault(); var speed = 300; var thisParent = $(this).parent(), nextLevel = $(this).next('.filter-options-content, .ox-toggle-content'); if (thisParent.hasClass('collapsible')) { if (thisParent.hasClass('open')) { thisParent.removeClass('open'); nextLevel.slideUp(speed, function () { $('body').trigger('oxToggleUpdated'); }); } else { thisParent.addClass('open'); nextLevel.slideDown(speed, function () { $('body').trigger('oxToggleUpdated'); }); } } }) } $.fn.ox_toggles = function () { var $this = $(this); $this.each(function () { if ($(this).hasClass('collapsible')) { if ($(this).hasClass('open')) { $(this).find(itemContent).slideDown(); } else { $(this).find(itemContent).slideUp(); } } }); $this.on('click', '.ox-toggle-title', function (e) { e.preventDefault(); var speed = 300; var thisParent = $(this).parent(), nextLevel = $(this).next('.ox-toggle-content'); if (thisParent.hasClass('collapsible')) { if (thisParent.hasClass('open')) { thisParent.removeClass('open'); nextLevel.slideUp(speed, function () { $('body').trigger('oxToggleUpdated'); }); } else { thisParent.addClass('open'); nextLevel.slideDown(speed, function () { $('body').trigger('oxToggleUpdated'); }); } } }) }; $('.ox-toggle').ox_toggles(); /* Collapsible text */ $('body').on('click.OXExpand', '.ox-expand .ox-expand__link', function (e) { e.preventDefault(); var $this = $(this).closest('.ox-expand').eq(0), max_height = $this.data('max-height') || 90, isMin = $this.hasClass('minimized'); $this.toggleClass('minimized', !isMin) .children('.ox-expand__inner') .attr("aria-expanded", isMin ? "true" : "false") .css('max-height', isMin ? '100%' : max_height); }); // Forced full-width stretching $.fn.ox_force_fullwidth = function () { var $this = $(this); function stretching($this, $window) { var $window = $window || $(window), $window_w = $window.width(); return $this.each(function () { var _this = $(this), _this_outer = _this.outerWidth(), _this_marg_l = _this.css('margin-left').replace(/[^0-9\.\,\-]/ig, '') || '0'; if (0 !== $window_w - _this_outer) { _this.width(_this.width() + ($window_w - _this_outer)); } try { _this_marg_l = parseFloat(_this_marg_l); } catch (e) { _this_marg_l = 0; } _this.css('margin-left', _this_marg_l - _this.offset().left); }); } $(window).on('resize', function () { stretching($this, $(this)); }); return stretching($this); }; // Forced full-width stretching $('.ox_force_fullwidth').ox_force_fullwidth(); }); /* require([ 'jquery', 'jquery-plugin', 'countdown' ], function($) { if ($(".js-countdown").length) { var showZero = showZero || true; $(".js-countdown").each(function() { var $this = $(this), date = $this.data('date'), set_year = $this.data('year') || 'Yrs', set_month = $this.data('month') || 'Mths', set_week = $this.data('week') || 'Wk', set_day = $this.data('day') || 'days', set_hour = $this.data('hour') || 'hours', set_minute = $this.data('minute') || 'min', set_second = $this.data('second') || 'sec'; if (date = date.split('-')) { date = date.join('/'); } else return; $this.countdown(date , function(e) { var format = ''; function addFormat(func, timeNum, showZero) { if(timeNum === 0 && !showZero) return; func(format); }; addFormat(function() { format += '' + '' + e.offset.totalDays + '' + '' + set_day + '' + ''; }, e.offset.totalDays, showZero); addFormat(function() { format += '' + '' + e.offset.hours + '' + '' + set_hour + '' + ''; }, e.offset.hours, showZero); addFormat(function() { format += '' + '' + e.offset.minutes + '' + '' + set_minute + '' + ''; }, e.offset.minutes, showZero); addFormat(function() { format += '' + '' + e.offset.seconds + '' + '' + set_second + '' + ''; }, e.offset.seconds, showZero); format += ''; $(this).html(format); }); }); } });*/ require([ 'jquery', 'domReady!' ], function ($) { 'use strict'; if ($('body.catalog-product-view')) { $(document).on('mousemove', '.product.media .gallery-placeholder', function (e) { var parentOffset = $(this).offset(); var relX = e.pageX - parentOffset.left; var relY = e.pageY - parentOffset.top; $('#ox-zoom-cursor').css({ left: relX, top: relY }); }); } }); require([ 'jquery', 'domReady!' ], function ($) { 'use strict'; var socialShare = $('.social-share__action'); if (socialShare.length) { socialShare.on('click', function (e) { $('.social-share__content').addClass('opened'); e.stopPropagation(); }); $('body').on('click', function () { $('.social-share__content').removeClass('opened'); }); } }); require(['jquery', 'domReady!', 'js/waypoints'], function ($) { $('.ox-animate:not(.animated)').waypoint({ handler: function () { var $this = $(this.element), delay = $this.data('animdelay') || 1; if ($this.hasClass('animated')) { return; } if (this.hasOwnProperty('element')) { $this = $(this.element); } else { $this = $(this); } setTimeout(function () { $this.addClass('animated'); }, delay); }, offset: '80%' }); }); require(['jquery', 'domReady!'], function ($) { (function () { if ($('body').hasClass('page-layout-1column') || $('body').hasClass('page-layout-1column-fullwidth')) { var $this = $('.ox-move-item-filtersslideout, .ox-block-filter, .sidebar-additional'), $parent = $('[data-move-mobile="filtersslideout"]').eq(0); if (!$this.length || !$parent.length || $this.parent().is($parent)) { return; } var element = $this.detach(); $parent.append(element); $('body').addClass('ox-show-filter'); } })(); }); require([ 'jquery', 'jquery-ui-modules/effect', 'domReady!' ], function ($) { /* cms banner animation */ var debounce = function (func, wait, immediate) { var timeout, args, context, timestamp, result; return function () { context = this; args = arguments; timestamp = new Date(); var later = function () { var last = (new Date()) - timestamp; if (last < wait) { timeout = setTimeout(later, wait - last); } else { timeout = null; if (!immediate) result = func.apply(context, args); } }; var callNow = immediate && !timeout; if (!timeout) { timeout = setTimeout(later, wait); } if (callNow) result = func.apply(context, args); return result; }; }; $.fn.OxBanner = function () { var cmsBanner = $(this); var cmsBannerText = cmsBanner.find('.ox-banner-animated-container'); if (!cmsBannerText.length) return; $('.text', cmsBanner).wrap('
'); $('.link', cmsBanner).wrap('