Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- document.addEventListener("DOMContentLoaded", function() {
- const imageObserver = new IntersectionObserver((entries, imgObserver) => {
- entries.forEach((entry) => {
- if (entry.isIntersecting) {
- const lazyImage = entry.target;
- if (lazyImage.tagName == 'IMG') {
- lazyImage.src = lazyImage.dataset.src;
- } else {
- lazyImage.style.backgroundImage = 'url('+ lazyImage.dataset.src +')';
- }
- lazyImage.classList.remove("gr_images_lazy_load");
- imgObserver.unobserve(lazyImage);
- }
- })
- });
- const arr = document.querySelectorAll(".gr_images_lazy_load");
- arr.forEach((v) => {
- imageObserver.observe(v);
- })
- });
- shop2.facets.search.wrapper = "";
- shop2.options.msgTime = 2000;
- shop2.msg = function(text, obj) {
- var selector = '#shop2-msg',
- msg = $(selector),
- offset = obj.offset(),
- width = obj.outerWidth(true),
- height = obj.outerHeight(true);
- if (!msg.get(0)) {
- msg = $('<div id="shop2-msg">');
- $(document.body).append(msg);
- msg = $(selector);
- }
- msg.html(text).fadeIn(150);
- var msgWidth = msg.outerWidth();
- var msgHeight = msg.outerHeight();
- var left = offset.left + width;
- var top = offset.top + height;
- if (left + msgWidth > $(window).width()) {
- left = offset.left - msgWidth;
- }
- msg.css({
- left: 50 + '%',
- top: 50 + '%',
- 'position': 'fixed',
- 'margin-left': msgWidth / 2 * -1,
- 'margin-top': msgHeight / 2 * -1
- });
- $.s3throttle('msg', function() {
- msg.hide();
- }, shop2.options.msgTime);
- $(document).on('click', '#shop2-msg', function() {
- $(this).fadeOut(150);
- });
- };
- shop2.queue.compare = function() {
- var $document = $(document);
- if ($('html').attr('lang') == 'ru') {
- var compareBtn = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn" target="_blank">к сравнению</a>';
- var compareBtn2 = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn" target="_blank">Перейти к сравнению</a>';
- } else {
- var compareBtn = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn" target="_blank">сompare</a>';
- var compareBtn2 = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn" target="_blank">Compare</a>';
- };
- function update(el, res) {
- $('input[type=checkbox][value=' + el.val() + ']').closest('.product-compare').replaceWith(res.data);
- $('.product-compare-added a span').html(res.count);
- $('.gr-compare-btn .gr-compare-btn-amount').html(res.count);
- if (+$('.gr-compare-btn .gr-compare-btn-amount').text() == '0') {
- $('.gr-compare-btn').removeClass('active');
- } else {
- $('.gr-compare-btn').addClass('active');
- };
- if (!$('.compare-remodal').hasClass('remodal-is-opened')) {
- if ($('html').attr('lang') == 'ru') {
- shop2.msg('Товар добавлен ' + compareBtn + ' ' + res.count, $('body'));
- } else {
- shop2.msg('Added to ' + compareBtn + ' ' + res.count, $('body'));
- };
- };
- if (res.panel) {
- $('#shop2-panel').replaceWith(res.panel);
- };
- }
- $document.on('click', '.product-compare input:checkbox', function() {
- var $this = $(this),
- action = $this.attr('checked') ? 'del' : 'add';
- shop2.compare.action(action, $this.val(), function(res, status) {
- if (status == 'success') {
- if (res.errstr) {
- if (!$('.compare-remodal').hasClass('remodal-is-opened')) {
- shop2.msg(res.errstr + ' <br>' + compareBtn2, $('body'));
- }
- $this.prop('checked', false);
- } else {
- update($this, res);
- if (action == 'del' && !$('.compare-remodal').hasClass('remodal-is-opened')) {
- if ($('html').attr('lang') == 'ru') {
- shop2.msg('Товар удален из сравнения', $('body'));
- } else {
- shop2.msg('Product removed from comparison', $('body'));
- };
- }
- }
- }
- });
- });
- };
- shop2.product.getProductListItem = function(product_id, kind_id, func) {
- var gr_images_size = $('.product-list').data('images-size');
- var gr_images_view = $(".product-list").data("images-view");
- var gr_mode_catalog = $(".product-list").data("mode-catalog");
- var url = "/my/s3/api/shop2/?cmd=getProductListItem&hash=" + shop2.apiHash.getProductListItem + "&ver_id=" + shop2.verId + "&gr_images_view=" + gr_images_view + "&gr_images_size=" + gr_images_size + "&gr_mode_catalog=" + gr_mode_catalog;
- shop2.trigger('beforeGetProductListItem');
- $.post(
- url, {
- product_id: product_id,
- kind_id: kind_id
- },
- function(d, status) {
- shop2.fire('afterGetProductListItem', func, d, status);
- shop2.trigger('afterGetProductListItem', d, status);
- }
- );
- };
- shop2.queue.lazyLoad = function() {
- var $document = $(document),
- $window = $(window),
- blocked = false,
- products = $('.product-list');
- function path(url, param, value) {
- return url + (~url.indexOf("?") ? "&" : "?") + param + "=" + value;
- }
- if (shop2.my.lazy_load_subpages && products.get(0)) {
- $document.on('click', '.lazy-pagelist-btn', function(e){
- e.preventDefault();
- var pagelist = $('.shop-pagelist');
- var next = pagelist.find('.active-num').next().find('a');
- if (!next.length) {
- return;
- }
- if (!blocked && next.get(0)) {
- blocked = true;
- $.get(path(next.attr('href'), 'products_only', 1), function(data) {
- var productsHtml = $(data).filter('.product-list').html();
- var $lazyLoad = $(data).filter('.lazy-pagelist');
- $('.lazy-pagelist').remove();
- $('.product-list').append(productsHtml);
- $('.product-list').after($lazyLoad);
- $('.product-list .gr_images_lazy_load').each(function(){
- $(this).attr('src', $(this).attr('data-src'));
- });
- $('.quick-view-trigger').elemToolTip({
- text: 'Быстрый просмотр',
- margin: 12
- });
- $('.product-additional__top-right').matchHeight();
- $('.product-list.thumbs .product-item .product-price').matchHeight();
- shop2_gr.methods.viewLots();
- shop2_gr.methods.amountInit();
- pagelist = $('.shop-pagelist');
- pagelist.find('a').each(function() {
- var $this = $(this),
- href = $this.attr('href');
- $this.attr('href', href.replace(/[&|\?]*products_only=[^&]/, ""));
- });
- blocked = false;
- });
- }
- });
- }
- };
- shop2.queue.addToCart = function() {
- $(document).on('click', '.shop-product-btn', function(e) {
- var $this = $(this),
- $form = $this.closest('form'),
- form = $form.get(0),
- adds = $form.find('.additional-cart-params'),
- len = adds.length,
- i, el,
- a4 = form.amount.value,
- kind_id = form.kind_id.value;
- e.preventDefault();
- if (len) {
- a4 = {
- amount: a4
- };
- for (i = 0; i < len; i += 1) {
- el = adds[i];
- if (el.value) {
- a4[el.name] = el.value;
- }
- }
- }
- shop2.cart.add(kind_id, a4, function(d) {
- $('#shop2-cart-preview').replaceWith(d.data);
- var totalCartAmount = +$(d.data).find('.gr-cart-total-amount').text();
- var totalCartSum = $(d.data).find('.gr-cart-total-sum').data('total-price');
- if (totalCartAmount>0) {
- $('.gr-cart-popup-btn').removeClass('pointer_events_none');
- $('.gr-cart-total-amount').text(totalCartAmount);
- $('.gr-cart-total-sum ins').text(totalCartSum);
- } else{
- $('.gr-cart-popup-btn').addClass('pointer_events_none');
- $('.gr-cart-total-amount').text('0');
- $('.gr-cart-total-sum ins').text('0');
- };
- if (d.errstr) {
- shop2.msg(d.errstr, $this);
- } else {
- var $text = window._s3Lang.JS_SHOP2_ADD_CART_WITH_LINK;
- shop2.msg($text.replace("%s", shop2.uri + "/cart"), $this);
- }
- if (d.panel) {
- $('#shop2-panel').replaceWith(d.panel);
- };
- });
- });
- };
- shop2.filter.sort = function(name, elem) {
- var re = new RegExp(this.escape('s[sort_by]') + '=([^&]*)'),
- params = this.str.match(re),
- desc = name + ' desc',
- asc = name + ' asc',
- isDesc = (elem.is('.sort-param-desc'));
- params = (params && params.length > 1) ? params[1] : "";
- params = (isDesc) ? desc : asc;
- this.remove('s[sort_by]');
- this.add('s[sort_by]', params);
- return this;
- };
- shop2.queue.sort = function() {
- var wrap = $('.sorting');
- wrap.find('.sort-param').on('click', function(e) {
- var $this = $(this),
- name = $this.data('name');
- e.preventDefault();
- shop2.filter.sort(name, $this);
- shop2.filter.go();
- });
- wrap.find('.sort-reset').on('click', function(e) {
- e.preventDefault();
- shop2.filter.remove('s[sort_by]');
- shop2.filter.go();
- });
- };
- shop2.queue.colorPopup = function() {
- var handle;
- $(document).on('click', '.shop2-color-ext-list li', function() {
- var caption = $(this);
- var wrap = caption.closest('.shop2-color-ext-popup');
- var ul = wrap.find('.shop2-color-ext-list');
- var offset = caption.offset();
- var $this = $(this);
- var data = $this.data();
- var input = $this.parent().find('input.additional-cart-params');
- var isSelected = $this.is('.shop2-color-ext-selected');
- colors = ul.children('li');
- if (typeof data.kinds !== 'undefined' || input.length) {
- $this.addClass('shop2-color-ext-selected').siblings().removeClass('shop2-color-ext-selected');
- if (input.length) {
- input.val(data.value);
- } else {
- if (!isSelected) {
- shop2.product._reload(this);
- }
- }
- } else {
- var index = $this.index();
- colors.eq(index).toggleClass('shop2-color-ext-selected');
- shop2.filter.toggle(data.name, data.value);
- shop2.filter.count();
- var offsetTop = $(this).position().top;
- $('.result-popup').css({
- 'top': offsetTop,
- 'visibility': 'visible',
- 'opacity': '1',
- 'display': 'block'
- });
- }
- return false;
- });
- };
- (function($, myObject) {
- var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
- isApple = /iPod|iPad|iPhone/i.test(navigator.userAgent),
- $doc = $(document),
- $win = $(window),
- $html = $(document.documentElement);
- var shop2_gr = {
- queue: {},
- methods : {},
- init: function() {
- $(function() {
- let queue = shop2_gr.queue;
- if (isMobile) $html.addClass('mobile');
- for (key in queue) {
- let f = queue[key];
- if (typeof f === 'function') {
- f();
- };
- }
- });
- }
- };
- shop2_gr.queue = {
- ajaxRequestsComplete: function() {
- /*$.ajaxSetup({
- complete: function() {
- }
- });*/
- shop2.on('afterProductReloaded', function(){
- setTimeout(function(){
- shop2_gr.methods.viewLots();
- shop2_gr.methods.amountInit();
- $('.shop2-product-item .buy-one-click').attr('data-api-url', $('.product-list').data('popup-form'));
- $('.product-list .gr_images_lazy_load').each(function(){
- $(this).attr('src', $(this).attr('data-src'));
- });
- $('.quick-view-trigger').elemToolTip({
- text: 'Быстрый просмотр',
- margin: 12
- });
- $('#shop2-tooltip').hide();
- $('.main-blocks .product-list.thumbs .product-item__bottom').matchHeight();
- });
- $.fn.matchHeight._update();
- });
- }, /*Обновление скриптов при аякс-запросах*/
- ajaxCompare: function(){
- /*if (shop2.mode=="") {
- var url = document.location.origin;
- $.ajax({
- url: url,
- success: function(data){
- var html = $(data).find('.gr-compare-btn');
- $('.gr-compare-btn').replaceWith(html);
- }
- });
- }*/
- }, /*Сравнение на страницах "не магазина"*/
- checkboxes: function() {
- $('#orderForm input[name="personal_data"]').parents('label').next('a').appendTo($('#orderForm input[name="personal_data"]').parents('label'));
- $('.shop2-order-form input[type="checkbox"], .shop2-order-form input[type="radio"], .comments-block .tpl-field.checkbox input, .tpl-field-reg input, .gr-authorization-checkbox, .shop2-order-options.shop2-payment-options .payment_methods-column input[type="radio"], #orderForm input[name="personal_data"]').mgStyler();
- $('#orderForm .mg-styler-label--checkbox a').on('click', function(e){
- var $label = $(this).parent();
- var $input = $(this).parents('label').find('input');
- var href = $(this).attr('href');
- window.open(href, '_blank');
- if ($('.mg-styler-label--checkbox input').is(':checked')) {
- setTimeout(function(){
- $input.prop('checked', true);
- $label.addClass('checked');
- }, 10);
- } else {
- setTimeout(function(){
- $input.prop('checked', false);
- $label.removeClass('checked');
- }, 10);
- }
- });
- $(document).on('click', '.shop2-edost-variant > label', function(){
- if ($('.shop2-edost-variant > label > .shop2-edost-control input[type="radio"]:checked')) {
- $('.shop2-edost-variant > label > .shop2-edost-control').removeClass("active");
- $('.shop2-edost-variant > label > .shop2-edost-control input[type="radio"]:checked').parent().addClass('active');
- }
- if ($('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked')) {
- $('.shop2-edost-office > label > .shop2-edost-control').removeClass("active");
- $('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked').parent().addClass('active');
- }
- });
- $(document).on("click", ".shop2-edost-office > label", function(){
- if ($('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked')) {
- $('.shop2-edost-office > label > .shop2-edost-control').removeClass("active");
- $('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked').parent().addClass('active');
- }
- });
- }, /*Чекбоксы*/
- colorSelect: function() {
- $(document).on('click', '.shop-search-color-select li', function(){
- var $input = $(this).find('input');
- var value = $(this).data('value');
- if ($(this).hasClass('shop2-color-ext-selected')) {
- $input.val("");
- $(this).removeClass('shop2-color-ext-selected');
- } else {
- $(this).addClass('shop2-color-ext-selected');
- $input.val(value);
- }
- var url = '/my/s3/api/shop2/?cmd=getSearchMatches&hash=' +
- shop2.apiHash.getSearchMatches +
- '&ver_id=' + shop2.verId + '&',
- fullUrl = url + $(shop2.facets.search.wrapper).serialize();
- shop2.facets.getDataSearch(fullUrl);
- });
- }, /*Допполе "Цвет" в фасетном поиске*/
- topSlider: function() {
- var sliders = document.querySelectorAll('.site-top-slider__items');
- shop2_gr.methods.forEach(sliders, function(index, value) {
- var sliderAutoplay = +sliders[index].getAttribute('data-autoplay');
- var multislider = tns({
- loop: false,
- rewind: true,
- container: value,
- slideBy: 1,
- items: 1,
- autoplayHoverPause: true,
- mode: 'carousel',
- axis: 'horizontal',
- autoplay: sliderAutoplay,
- autoplayButtonOutput: false,
- mouseDrag: true,
- center: false,
- autoWidth: false,
- nav: true,
- swipeAngle: 50,
- lazyload: true,
- controlsText: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_next_small"></use></svg>'],
- navPosition: 'bottom',
- preventActionWhenRunning: false,
- responsive: {
- 320: {
- autoHeight: true,
- controls: false
- },
- 768: {
- autoHeight: true,
- controls: false
- },
- 1024: {
- autoHeight: false,
- controls: false
- },
- 1261: {
- autoHeight: false,
- controls: true
- }
- }
- });
- shop2_gr.methods.arrowsPosition('.site-top-slider__items', '.site-top-slider__pic');
- });
- }, /*Слайдер в шапке*/
- mainBlocks: function() {
- if (shop2.mode == 'main' && $('.main-products').length) {
- $('.product-list').removeClass('simple').removeClass('list').addClass('thumbs');
- }
- var $mainBlocksClass = $('.main_blocks_list');
- if ($mainBlocksClass.length>0) {
- var sliderAutoplay = $('.main_blocks_list').data('autoplay');
- var main_items = $('.main_blocks_list').data('main-items');
- if (main_items == 5) {
- $mainBlocksClass.addClass('main_columns_5');
- var main_items_1920 = 7,
- main_items_1600 = 6,
- main_items_1440 = 5,
- main_items_1366 = 5,
- main_items_1280 = 4,
- main_items_1024 = 4,
- main_items_768 = 3,
- main_items_320 = 2;
- } else if (main_items == 4) {
- $mainBlocksClass.addClass('main_columns_4');
- var main_items_1920 = 5,
- main_items_1600 = 4,
- main_items_1440 = 4,
- main_items_1366 = 4,
- main_items_1280 = 4,
- main_items_1024 = 4,
- main_items_768 = 3,
- main_items_320 = 2;
- } else if (main_items == 3) {
- $mainBlocksClass.addClass('main_columns_3');
- var main_items_1920 = 4,
- main_items_1600 = 4,
- main_items_1440 = 3,
- main_items_1366 = 3,
- main_items_1280 = 3,
- main_items_1024 = 3,
- main_items_768 = 3,
- main_items_320 = 2;
- } else if (main_items == 2) {
- $mainBlocksClass.addClass('main_columns_2');
- var main_items_1920 = 3,
- main_items_1600 = 3,
- main_items_1440 = 3,
- main_items_1366 = 2,
- main_items_1280 = 2,
- main_items_1024 = 2,
- main_items_768 = 2,
- main_items_320 = 2;
- }
- // tiny-slider initialisation
- var sliders = document.querySelectorAll('.main_blocks_list');
- shop2_gr.methods.forEach(sliders, function(index, value) {
- var multislider = tns({
- loop: false,
- rewind: true,
- container: value,
- slideBy: 1,
- autoplayHoverPause: true,
- mode: 'carousel',
- axis: 'horizontal',
- autoplay: sliderAutoplay,
- autoplayButtonOutput: false,
- mouseDrag: true,
- center: false,
- autoWidth: false,
- nav: true,
- swipeAngle: 50,
- controlsText: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_next_small"></use></svg>'],
- navPosition: 'bottom',
- preventActionWhenRunning: false,
- responsive: {
- 320: {
- controls: false,
- items: main_items_320,
- gutter: 12
- },
- 768: {
- controls: false,
- items: main_items_768,
- gutter: 20
- },
- 1024: {
- controls: false,
- items: main_items_1024,
- gutter: 20
- },
- 1261: {
- controls: true,
- items: main_items_1280,
- gutter: 20
- },
- 1341: {
- controls: true,
- items: main_items_1366,
- gutter: 20
- },
- 1367: {
- controls: true,
- items: main_items_1440,
- gutter: 20
- },
- 1441: {
- controls: true,
- items: main_items_1600,
- gutter: 20
- },
- 1601: {
- controls: true,
- items: main_items_1920,
- gutter: 20
- }
- }
- });
- });
- }
- }, /*Блоки на главной*/
- sortingPanel : function() {
- $('.shop-view').on('click', '.shop-view__btn', function(){
- $(this).parents('.shop-view__inner').toggleClass('active');
- });
- $(document).on('click', function(e){
- if (!$(e.target).closest('.shop-view .shop-view__btn').length) {
- $('.shop-view .shop-view__inner').removeClass('active');
- };
- });
- $(document).on('click', '.sorting-button', function(){
- $('.sorting-block').addClass('active');
- });
- $(document).on('click', '.sorting-block__title', function(){
- $('.sorting-block').removeClass('active');
- });
- shop2_gr.methods.viewLots();
- }, /*Сортировка и виды*/
- searchBlock: function() {
- $(document).on('click', '.search-form .row-title', function(){
- $(this).toggleClass('active');
- $(this).next().slideToggle(250);
- });
- function searchMoreFields() {
- $('.search-rows__row').each(function() {
- var $this = $(this);
- var $btn = $this.find('.gr-filter-more__btn');
- var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
- $btn.off('click').on('click', function(){
- var $hiddenCkeckbox = $this.find('ul li:hidden');
- var currentText = $btn.data('text');
- $hiddenCkeckbox.addClass('hidden_item');
- if ($this.find('.hidden_item').hasClass('active')) {
- $btn.find('.gr-filter-more__text').text(currentText);
- $this.find('.hidden_item').removeClass('active');
- } else {
- $btn.find('.gr-filter-more__text').text(hideText);
- $this.find('.hidden_item').addClass('active');
- };
- });
- });
- };
- searchMoreFields();
- shop2.on('afterGetFolderCustomFields', function(){
- searchMoreFields();
- var url = '/my/s3/api/shop2/?cmd=getSearchMatches&hash=' +
- shop2.apiHash.getSearchMatches +
- '&ver_id=' + shop2.verId + '&',
- fullUrl = url + $(shop2.facets.search.wrapper).serialize();
- shop2.facets.getDataSearch(fullUrl);
- });
- }, /*Поиск*/
- filterBlock: function() {
- $('.shop2-filter__title').on('click', function(){
- $(this).toggleClass('active');
- $(this).next().slideToggle(250);
- });
- $('.shop2-filter__item').each(function() {
- var $this = $(this);
- var $btn = $this.find('.gr-filter-more__btn');
- var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
- $btn.on('click', function(){
- var $hiddenCkeckbox = $this.find('.shop2-filter__checkbox:hidden');
- var $hiddenColor = $this.find('.shop2-color-ext-list__item:hidden');
- var currentText = $btn.data('text');
- $hiddenCkeckbox.addClass('hidden_item');
- $hiddenColor.addClass('hidden_item');
- if ($this.find('.hidden_item').hasClass('active')) {
- $btn.find('.gr-filter-more__text').text(currentText);
- $this.find('.hidden_item').removeClass('active');
- } else {
- $btn.find('.gr-filter-more__text').text(hideText);
- $this.find('.hidden_item').addClass('active');
- };
- });
- });
- }, /*Фильтр*/
- productsBlock: function() {
- $(document).on('click', '.gr-options-more__btn', function(){
- var $parent = $(this).parents('.gr-product-options');
- var $params = $parent.find('.gr-options-container');
- var currentText = $(this).data('text');
- var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
- if ($(this).hasClass('active')) {
- $(this).removeClass('active');
- $(this).find('ins').text(currentText);
- } else {
- $(this).addClass('active');
- $(this).find('ins').text(hideText);
- };
- $params.stop().slideToggle(250);
- });
- $('.shop2-color-ext-select .shop2-color-ext-options').on('click', function() {
- if ($(this).closest('.shop2-color-ext-select').hasClass('active')) {
- $(this).closest('.shop2-color-ext-select').removeClass('active');
- } else {
- $(this).closest('.shop2-color-ext-select').addClass('active');
- }
- });
- $('#shop2-color-ext-select').on('click', function() {
- $('.shop2-color-ext-select').removeClass('active');
- });
- $(document).on('click', '.shop2-color-ext-select', function() {
- if ($(this).parents('.product-item').length>0) {
- $('#shop2-color-ext-select').addClass('product_item_color');
- }
- if ($(this).parents('.shop2-product').length>0) {
- $('#shop2-color-ext-select').addClass('shop_product_color');
- }
- });
- $(document).on('click', '#shop2-color-ext-select', function() {
- $(this).removeClass('product_item_color');
- $(this).removeClass('shop_product_color');
- });
- $(document).on('click', function(e){
- if (!$(e.target).closest('#shop2-color-ext-select').length) {
- $('#shop2-color-ext-select').removeClass('product_item_color');
- $('#shop2-color-ext-select').removeClass('shop_product_color');
- }
- });
- }, /*Товар*/
- cardPage: function(){
- var $cardHiddenOptions = $('.card-page .shop2-product .gr-product-options .option-item:hidden');
- if ($cardHiddenOptions.length>0) {
- $('.shop2-product .gr-product-options-more').addClass('show_more_btn');
- };
- $(document).on('click', '.card-page .shop2-product .gr-product-options-more__btn', function(){
- var currentText = $(this).data('text');
- var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
- if ($(this).hasClass('active')) {
- $(this).removeClass('active');
- $(this).find('ins').text(currentText);
- } else {
- $(this).addClass('active');
- $(this).find('ins').text(hideText);
- };
- $cardHiddenOptions.stop().slideToggle(250);
- });
- if ($('.card-slider__thumbs-slider').length>0) {
- var vslider = tns({
- container: '.card-slider__items-slider',
- slideBy: 1,
- mode: 'gallery',
- axis: 'horizontal',
- autoplay: false,
- mouseDrag: true,
- center: true,
- autoWidth: false,
- loop: false,
- rewind: true,
- swipeAngle: false,
- preventActionWhenRunning: false,
- nav: true,
- swipeAngle: 50,
- navPosition: 'bottom',
- controlsText: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_card_sl_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_card_sl_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_card_sl_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_card_sl_next_small"></use></svg>'],
- responsive: {
- 320: {
- controls: false,
- nav: true
- },
- 768: {
- controls: true,
- nav: true
- }
- }
- });
- var small_slider = tns({
- container: '.card-slider__thumbs-slider',
- loop: false,
- gutter: 20,
- center:false,
- mouseDrag: true,
- nav: false,
- controls: false,
- navPosition: 'bottom',
- preventActionWhenRunning: false,
- axis: 'horizontal',
- responsive: {
- 320: {
- items: 3
- },
- 640: {
- items: 6
- },
- 768: {
- items: 3
- },
- 1024: {
- items: 5
- },
- 1261: {
- items: 4
- },
- 1340: {
- items: 5
- }
- }
- });
- var navIndex = $('.card-slider__items .tns-nav-active').index();
- $('.card-slider__thumbs-slider .card-slider__thumb').removeClass('tns-nav-active');
- $('.card-slider__thumbs-slider .card-slider__thumb').eq(navIndex).addClass('tns-nav-active');
- vslider.events.on('indexChanged', function(){
- var navIndex = $('.card-slider__items .tns-nav-active').index();
- $('.card-slider__thumbs-slider .card-slider__thumb').removeClass('tns-nav-active');
- $('.card-slider__thumbs-slider .card-slider__thumb').eq(navIndex).addClass('tns-nav-active');
- /*if (vslider.getInfo().index>vslider.getInfo().indexCached) {
- //console.log('right')
- } else {
- //console.log('left')
- }*/
- });
- $(document).on('click', '.card-slider__thumbs-slider .card-slider__thumb', function(){
- var thisIndex = $(this).index();
- $('.card-slider__items .tns-nav button').eq(thisIndex).click();
- });
- vslider.events.on('indexChanged', function(){
- small_slider.goTo(vslider.getInfo().index);
- });
- };
- if (!isMobile && jQuery().zoom) {
- $('.gr-image-zoom').zoom({
- magnify: 1,
- duration: 10,
- onZoomIn: function(){
- $(this).parent().addClass('hide_small_pic');
- },
- onZoomOut: function(){
- $(this).parent().removeClass('hide_small_pic');
- },
- callback: function(){
- var $zoomImg = $(this);
- var containerHeight = $zoomImg.parent().outerHeight();
- var containerWidth = $zoomImg.parent().outerWidth();
- var zoomImgHeight = Math.floor($zoomImg.height());
- var zoomImgWidth = Math.floor($zoomImg.width());
- var floatHeight = Math.floor(20 * zoomImgHeight / 100);
- var floatWidth = Math.floor(20 * zoomImgWidth / 100);
- var prevWidth = Math.floor($(this).prev().outerWidth());
- var prevHeight = Math.floor($(this).prev().outerHeight());
- var zoomFloatHeight = zoomImgHeight + floatHeight;
- var zoomFloatWidth = zoomImgWidth + floatWidth;
- var finalHeight = prevHeight+floatHeight;
- var finalWidth = prevWidth+floatWidth;
- if (zoomFloatHeight<=prevHeight-floatHeight || zoomFloatWidth<=prevWidth-floatWidth) {
- $(this).parent().addClass('hide_big_pic');
- };
- if (zoomImgHeight<=prevHeight || zoomImgWidth <=prevWidth) {
- $zoomImg.css({
- 'width': finalWidth,
- 'height': finalHeight
- });
- }
- if (finalHeight<=containerHeight && finalWidth<=containerWidth) {
- $(this).parent().addClass('hide_zoom_pic');
- }
- }
- });
- };
- }, /*Слайдер в карточке товара*/
- responsiveTabs: function() {
- var $tabs = $('#product-tabs');
- $tabs.responsiveTabs({
- rotate: false,
- startCollapsed: 'accordion',
- collapsible: 'accordion',
- animation: 'slide',
- duration: 500,
- animationqueue: false,
- setHash: true,
- scrollToAccordion: true,
- scrollToAccordionOffset: 60,
- click: function(event, tab) {
- setTimeout(function(){
- $.fn.matchHeight._update();
- }, 501);
- }
- });
- }, /*Табы*/
- kindsBlock: function() {
- var $kindClass = $('.kinds-block__items.kinds_slider');
- if ($kindClass.length>0) {
- var sliderAutoplay = $('.kinds-block__items.kinds_slider').data('autoplay');
- var kind_items = $('.kinds-block__items.kinds_slider').data('kind-items');
- if (kind_items == 5) {
- $('.kinds-block.collections_block').addClass('kind_columns_5');
- var kind_items_1920 = 7,
- kind_items_1600 = 6,
- kind_items_1440 = 5,
- kind_items_1366 = 5,
- kind_items_1280 = 4,
- kind_items_1024 = 4,
- kind_items_768 = 3,
- kind_items_320 = 2;
- } else if (kind_items == 4) {
- $('.kinds-block.collections_block').addClass('kind_columns_4');
- var kind_items_1920 = 5,
- kind_items_1600 = 4,
- kind_items_1440 = 4,
- kind_items_1366 = 4,
- kind_items_1280 = 4,
- kind_items_1024 = 4,
- kind_items_768 = 3,
- kind_items_320 = 2;
- } else if (kind_items == 3) {
- $('.kinds-block.collections_block').addClass('kind_columns_3');
- var kind_items_1920 = 4,
- kind_items_1600 = 4,
- kind_items_1440 = 3,
- kind_items_1366 = 3,
- kind_items_1280 = 3,
- kind_items_1024 = 3,
- kind_items_768 = 3,
- kind_items_320 = 2;
- } else if (kind_items == 2) {
- $('.kinds-block.collections_block').addClass('kind_columns_2');
- var kind_items_1920 = 3,
- kind_items_1600 = 3,
- kind_items_1440 = 3,
- kind_items_1366 = 2,
- kind_items_1280 = 2,
- kind_items_1024 = 2,
- kind_items_768 = 2,
- kind_items_320 = 2;
- }
- var respSettings = {};
- if ($('.dynamic_width').length) {
- respSettings = {
- 320: {
- controls: false,
- items: kind_items_320,
- gutter: 12
- },
- 768: {
- controls: false,
- items: kind_items_768,
- gutter: 20
- },
- 1024: {
- controls: false,
- items: kind_items_1024,
- gutter: 20
- },
- 1261: {
- controls: true,
- items: kind_items_1280,
- gutter: 20
- },
- 1341: {
- controls: true,
- items: kind_items_1366,
- gutter: 20
- },
- 1367: {
- controls: true,
- items: kind_items_1440,
- gutter: 20
- },
- 1441: {
- controls: true,
- items: kind_items_1600,
- gutter: 20
- },
- 1601: {
- controls: true,
- items: kind_items_1920,
- gutter: 20
- }
- }
- } else {
- respSettings = {
- 320: {
- controls: false,
- items: kind_items_320,
- gutter: 12
- },
- 768: {
- controls: false,
- items: kind_items_768,
- gutter: 20
- },
- 1024: {
- controls: false,
- items: kind_items_1024,
- gutter: 20
- },
- 1261: {
- controls: true,
- items: kind_items_1280,
- gutter: 20
- }
- }
- }
- // tiny-slider initialisation
- var sliders = document.querySelectorAll('.kinds-block__items.kinds_slider');
- shop2_gr.methods.forEach(sliders, function(index, value) {
- var multislider = tns({
- loop: false,
- rewind: true,
- container: value,
- slideBy: 1,
- autoplayHoverPause: true,
- mode: 'carousel',
- axis: 'horizontal',
- autoplay: sliderAutoplay,
- autoplayButtonOutput: false,
- mouseDrag: true,
- center: false,
- autoWidth: false,
- nav: true,
- swipeAngle: 50,
- controlsText: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_next_small"></use></svg>'],
- navPosition: 'bottom',
- preventActionWhenRunning: false,
- responsive: respSettings
- });
- });
- }
- }, /*Коллекции*/
- commentsBlock: function() {
- $('.comments-form__btn').on('click', function(){
- $(this).next().slideToggle(200);
- });
- }, /*Комментарии*/
- rangeSlider: function() {
- if ($('.input_range_slider').length>0) {
- shop2_gr.methods.rangeSliderInit('.filter-block .input_range_slider');
- shop2_gr.methods.rangeSliderInit('.search-form .input_range_slider', false);
- };
- }, /*Бегунки*/
- amountBlock: function() {
- shop2_gr.methods.amountInit();
- }, /*Количество*/
- buyOneClick: function() {
- $(document).on('click', '.buy-one-click', function(e) {
- var productName = $(this).data('product-name');
- var productLink = $(this).data('product-link');
- if (shop2.mode == 'product' && $(this).parents('.kind-item').length<1) {
- var productAmount = $(this).parents('.shop2-product').find('.shop2-product-amount input').val();
- } else if ($('.product-quick-view').length>0 && $(this).parents('.kind-item').length<1) {
- var productAmount = $(this).parents('.shop2-product').find('.shop2-product-amount input').val();
- } else if ($(this).parents('.kind-item').length>0) {
- var productAmount = $(this).parents('.kind-item').find('.shop2-product-amount input').val();
- } else {
- var productAmount = $(this).parents('.shop2-product-item').find('.shop2-product-amount input').val();
- }
- $.ajax({
- url: $(this).data('api-url'),
- dataType: 'json',
- success: function(response) {
- if (!response.result.error) {
- $('.remodal[data-remodal-id="buy-one-click"] .tpl-anketa').remove();
- $(response.result.html).appendTo('.remodal[data-remodal-id="buy-one-click"]');
- var nameValue = productName + ', количество - ' + productAmount;
- $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-link input').val(productLink);
- $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-name input').val(nameValue);
- s3From.initForms($('.remodal[data-remodal-id="buy-one-click"]'), function(){
- $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-link input').val(productLink);
- $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-name input').val(nameValue);
- });
- grFormDatePicker.init();
- }
- }
- });
- });
- }, /*Купить в 1 клик*/
- actionsBlock: function() {
- var actionEventName = 'mouseenter';
- if (isMobile) {
- actionEventName = 'click';
- };
- $(document).on(actionEventName, '.shop2-product-actions dt', function(){
- $('.shop2-product-actions dt').removeClass('dt_hover');
- $('.shop2-product-actions dd').css('left', 'auto');
- if (!isMobile) {
- $(this).addClass('dt_hover');
- };
- $(this).next().css('left', $(this).position().left);
- $(this).next().css('top', $(this).position().top - $(this).next().outerHeight());
- var nextLeft = $(this).next().offset().left;
- var nextWidth = $(this).next().outerWidth();
- var offsetSum = nextLeft + nextWidth;
- var winWidth = $(window).width();
- if ((offsetSum) > winWidth) {
- $(this).next().css('left', $(this).position().left - (offsetSum - winWidth))
- }
- });
- $(document).on('mouseleave', '.shop2-product-actions dl', function(){
- $('.shop2-product-actions dt').removeClass('dt_hover');
- $('.shop2-product-actions dd').css('left', 'auto');
- });
- }, /*Подарок/Акция*/
- cartPreview: function(){
- $(document).on('click', '.gr_order_one_page', function(e){
- eraseCookie('gr_delivery_scroll');
- createCookie('gr_delivery_scroll', 1, 30);
- });
- if (readCookie('gr_delivery_scroll') == '1') {
- eraseCookie('gr_delivery_scroll');
- setTimeout(function(){
- $('html, body').animate({
- scrollTop: $('.shop2-delivery').offset().top - 30
- }, 800);
- }, 1000);
- };
- }, /*Скролл на странице корзины до доставки*/
- cartPage: function() {
- $(document).on('click', '.cart-params__more-btn', function(){
- var $parent = $(this).parents('.cart-params');
- var $params = $parent.find('.cart-params__body');
- var currentText = $(this).data('text');
- var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
- if ($(this).hasClass('active')) {
- $(this).removeClass('active');
- $(this).find('ins').text(currentText);
- } else {
- $(this).addClass('active');
- $(this).find('ins').text(hideText);
- };
- $params.stop().slideToggle(250);
- });
- if (shop2.mode=='cart') {
- $('.shop2-warning').prependTo('.cart-page__left');
- };
- /*Автопересчет в корзине*/
- if (shop2.mode=='cart') {
- var cartURL = shop2.uri + "/cart",
- ajax, hash, $idd,
- shopCartDiv = $('.cart-page'),
- cartPreloader = '<div class="gr-preloader-holder"><div class="gr-preloader"><svg xmlns="http://www.w3.org/2000/svg" width="34" height="26" viewBox="0 0 120 30" fill="#fff"><script xmlns=""></script> <circle cx="15" cy="15" r="15"> <animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate> <animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate> </circle> <circle cx="60" cy="15" r="9" fill-opacity="0.3"> <animate attributeName="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcMode="linear" repeatCount="indefinite"></animate> <animate attributeName="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcMode="linear" repeatCount="indefinite"></animate> </circle> <circle cx="105" cy="15" r="15"> <animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate> <animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate> </circle></svg></div></div>';
- $('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').append(cartPreloader);
- $.get(cartURL + "?gethash=1", function(d) {
- d = $.trim(d).replace(/<script[\s\S]*/, '');
- d = $.trim(d).replace(/.*(\{[^}]*\})/g, "$1");
- d = $.trim(d).replace(/<!--(.*?)-->/gm, "");
- d = $.trim(d);
- hash = JSON.parse(d);
- shop2.on("afterCartAddItem", function(d, status) {
- if (!d.errstr.length) {
- getCart();
- };
- });
- });
- $(document).on('click', '#shop2-color-ext-select li.param-value:not(.shop2-color-ext-selected)', function() {
- clearTimeout($idd);
- $idd = setTimeout(updateForm, 500);
- $('.shop2-cart-update').hide();
- });
- function getCart() {
- if (ajax) ajax.abort();
- ajax = $.ajax({
- url: cartURL + "?cart_only=1",
- async: false,
- success: function(data) {
- var $shopWarning = $(data).filter('.shop2-warning').clone();
- $('.cart-page__top').html($(data).find('.cart-page__top').html());
- $('.cart-page__bottom').html($(data).find('.cart-page__bottom').html());
- $shopWarning.prependTo('.cart-page__left');
- initCart(shopCartDiv);
- $('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').removeClass('gr-preloader-active');
- }
- });
- };
- function initDelivery() {
- if ($('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').find('.gr-preloader-holder').length<1) {
- $('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').append(cartPreloader);
- };
- /*Код из shop2.queue.cart*/
- $('#shop2-deligate-calc').on('click', function(e) {
- var data = {},
- delivery = $('#shop2-order-delivery'),
- tabs = delivery.find('.shop2-delivery--item__tab');
- $('#shop2-perfect-form').find('input, textearea, select').each(function() {
- var $this = $(this);
- if (this.tagName === 'INPUT' && this.type === 'checkbox') {
- if (this.checked) {
- data[this.name] = 'on';
- }
- } else {
- data[this.name] = $(this).val();
- }
- });
- e.preventDefault();
- tabs.removeClass('active-tab');
- tabs.removeClass('point');
- delivery.addClass('preloader');
- $('#shop2-delivery-wait').show();
- $('input#address').blur();
- $('#shop2-deligate-calc').hide();
- $.ajax({
- url: '/my/s3/xapi/public/?method=deligate/calc¶m[get_vars][]',
- type: 'post',
- dataType: 'json',
- data: data,
- success: function(result) {
- delivery.removeClass('preloader');
- $('#shop2-delivery-wait').hide();
- $('#shop2-order-delivery').html(result.result.html);
- $('#shop2-order-delivery').append('<div class="preloader"><div class="spinner"></div></div>');
- $('#shop2-order-delivery').find('.delivery-items').each(function() {
- var $this = $(this);
- if ($.trim($this.text()) == "") {
- $this.parents('.shop2-delivery--item__tab:first').addClass('disabled');
- }
- });
- if (result.result.error) {
- shop2.alert(result.result.error);
- } else {
- var dadataJson = $.parseJSON($('#dadata').val()),
- coordsCenter = [dadataJson.geo_lat, dadataJson.geo_lon];
- shop2.queue.edost2();
- $('#shop2-ems-calc, #shop2-edost-calc').on('click', function(e) {
- var $this = $(this);
- var attach_id = $this.data('attach-id');
- var to = $('select[name=' + attach_id + '\\[to\\]]');
- var zip = $('input[name=' + attach_id + '\\[zip\\]]');
- var order_value = $('input[name=' + attach_id + '\\[order_value\\]]');
- if (to.length == 0) {
- to = $('#shop2-edost2-to');
- }
- e.preventDefault();
- to = to.get(0) ? to.val() : '';
- zip = zip.get(0) ? zip.val() : '';
- order_value = order_value.prop("checked") ? 'on' : '';
- shop2.delivery.calc(attach_id, 'to=' + to + '&zip=' + zip + '&order_value=' + order_value, function(d) {
- if (!d.data && d.errstr) {
- shop2.alert(d.errstr);
- $('#delivery-' + attach_id + '-cost').html(0);
- } else {
- $('#delivery-' + attach_id + '-cost').html(d.data.cost);
- if (d.data.html) {
- $('#delivery-' + attach_id + '-html').html(d.data.html);
- shop2.queue.edost();
- }
- }
- });
- });
- $('#shop2-deligate-calc').hide();
- }
- }
- });
- });
- /*Код из shop2.queue.cart*/
- /*Код из shop2.queue.delivery*/
- $('#shop2-order-delivery').find('.delivery-items').each(function() {
- var $this = $(this);
- if ($.trim($this.text()) == "") {
- $this.parents('.shop2-delivery--item__tab:first').addClass('disabled');
- }
- });
- $('#shop2-ems-calc, #shop2-edost-calc').on('click', function(e) {
- var $this = $(this);
- var attach_id = $this.data('attach-id');
- var to = $('select[name=' + attach_id + '\\[to\\]]');
- var zip = $('input[name=' + attach_id + '\\[zip\\]]');
- var order_value = $('input[name=' + attach_id + '\\[order_value\\]]');
- if (to.length == 0) {
- to = $('#shop2-edost2-to');
- }
- e.preventDefault();
- to = to.get(0) ? to.val() : '';
- zip = zip.get(0) ? zip.val() : '';
- order_value = order_value.prop("checked") ? 'on' : '';
- shop2.delivery.calc(attach_id, 'to=' + to + '&zip=' + zip + '&order_value=' + order_value, function(d) {
- if (!d.data && d.errstr) {
- shop2.alert(d.errstr);
- $('#delivery-' + attach_id + '-cost').html(0);
- } else {
- $('#delivery-' + attach_id + '-cost').html(d.data.cost);
- if (d.data.html) {
- $('#delivery-' + attach_id + '-html').html(d.data.html);
- shop2.queue.edost();
- }
- }
- });
- });
- /*Код из shop2.queue.delivery*/
- };
- function initCart($div) {
- var $form = $div.find("#shop2-cart"),
- $inp = $form.find("input:text"),
- $item = $form.find(".cart-products__item"),
- $recalc = $("a.shop2-cart-update"),
- $minus = $form.find(".amount-minus"),
- $plus = $form.find(".amount-plus");
- if (!$form.length) return;
- shop2_gr.methods.amountInit();
- if (shop2.mode=='cart') {
- $('.shop2-warning').prependTo('.cart-page__left');
- };
- $('.cart-total-checkout, .cart-total-order-checkout, .cart-registration-btn').append(cartPreloader);
- $('[data-remodal-id="cart-auth-remodal"]').remodal({
- hashTracking: false
- });
- $('[data-remodal-id="coupon-remodal"]').remodal({
- hashTracking: false
- });
- $('#shop2-cart .cart-delete a').off('click');
- $item.each(function(){
- var $del = $(this).find(".cart-delete a");
- var $input = $(this).find(".shop2-product-amount input");
- var $button = $(this).find(".shop2-product-amount button");
- var $select = $(this).find("select.param-value");
- $select.on('change', function() {
- clearTimeout($idd);
- $idd = setTimeout(updateForm, 500);
- $('.shop2-cart-update').hide();
- });
- $input.on('change', function() {
- clearTimeout($idd);
- $idd = setTimeout(updateForm, 1000);
- $('.shop2-cart-update').hide();
- $('.cart-total-checkout, .cart-total-order-checkout, .cart-registration-btn, .shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').addClass('gr-preloader-active');
- });
- $button.on('click', function() {
- clearTimeout($idd);
- $idd = setTimeout(updateForm, 1000);
- $('.shop2-cart-update').hide();
- $('.cart-total-checkout, .cart-total-order-checkout, .cart-registration-btn, .shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').addClass('gr-preloader-active');
- });
- $del.on("click", function(e) {
- var $this = $(this),
- kind_id = $this.data('id');
- e.preventDefault();
- $('.cart-total-checkout, .cart-total-order-checkout, .cart-registration-btn, .shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').addClass('gr-preloader-active');
- kind_id = kind_id.toString().replace(/\"/g, '\\"').replace(/\'/g, '"');
- kind_id = $.parseJSON(kind_id);
- shop2.trigger('beforeCartRemoveItem');
- $.ajax({
- url: '/my/s3/api/shop2/?cmd=cartRemoveItem',
- async: false,
- dataType: "json",
- data: {
- hash: hash.del,
- ver_id: shop2.verId,
- kind_id: kind_id
- },
- success: function (d, status) {
- sessionStorage.setItem('cart-reload', 1);
- getCart();
- $('.gr-cart-total-amount').text($('#shop2-cart').data('cart-amount') || '0');
- if (d.data.cart.length == 0) {
- document.location = shop2.uri + "?mode=cart&action=cleanup";
- };
- }
- });
- return false;
- });
- });
- $recalc.on("click", function(e) {
- e.preventDefault();
- updateForm();
- return false;
- });
- shop2.on('afterCartAddCoupon, afterCartRemoveCoupon', function() {
- document.location.reload();
- });
- $('.coupon-btn').on('click', function(e) {
- var coupon = $('#coupon'),
- code = coupon.val();
- e.preventDefault();
- if (code) {
- shop2.cart.addCoupon(code);
- }
- });
- $('.coupon-delete').on('click', function(e) {
- var $this = $(this),
- code = $this.data('code');
- e.preventDefault();
- if (code) {
- shop2.cart.removeCoupon(code);
- }
- });
- };
- function updateForm() {
- var data = $("#shop2-cart").serialize();
- shop2.trigger('beforeCartUpdate');
- $.ajax({
- type: "POST",
- url:
- '/my/s3/api/shop2/?cmd=cartUpdate' +
- '&ver_id=' + shop2.verId +
- '&hash=' + hash.up +
- '&' + data,
- async: false,
- success: function (d, status) {
- sessionStorage.setItem('cart-reload', 1);
- getCart();
- shop2.trigger('afterCartUpdated');
- $('.gr-cart-total-amount').text($('#shop2-cart').data('cart-amount') || '0');
- $('.gr-cart-total-sum ins').text($('.last_item .cart-total__body').data('total-price'));
- initDelivery();
- }
- });
- return false;
- };
- initCart(shopCartDiv);
- };
- /*Автопересчет в корзине*/
- }, /*Корзина*/
- specialPopup: function(){
- var specialRemodal = $('[data-remodal-id=special-popup]').remodal();
- var showSpecOnReturn = true;
- function init() {
- if (document.layers) document.captureEvents(Event.MOUSEMOVE);
- document.onmousemove = mousemove;
- }
- function mousemove(event) {
- var mouse_y = 0;
- if (document.attachEvent != null) {
- mouse_y = window.event.clientY;
- } else if (!document.attachEvent && document.addEventListener) {
- mouse_y = event.clientY;
- }
- var showSpecOn = function () {
- setTimeout(function(){
- //specialRemodal.open();
- showSpecOnReturn = false ;
- }, 300);
- }
- if (mouse_y <= 10 && showSpecOnReturn != false ) {
- showSpecOn()
- }
- }
- init();
- }, /*Форма "Спецпредложение"*/
- lightGallery: function() {
- $('.card-slider__items').lightGallery({
- thumbnail: false,
- download: true,
- loop: false,
- counter: false,
- share: false,
- getCaptionFromTitleOrAlt: true,
- selector: '.card-slider__image a'
- });
- $('.gr_cart_param_img').lightGallery({
- thumbnail: false,
- download: true,
- loop: false,
- counter: false,
- share: false,
- getCaptionFromTitleOrAlt: true,
- selector: 'a'
- });
- }, /*Галерея*/
- toolTips: function(){
- $('.shop-view .shop-view__item.thumbs').elemToolTip({
- position: 'top',
- text: 'Витрина',
- margin: 12
- });
- $('.shop-view .shop-view__item.simple').elemToolTip({
- position: 'top',
- text: 'Простой',
- margin: 12
- });
- $('.shop-view .shop-view__item.pricelist').elemToolTip({
- position: 'top',
- text: 'Прайс-лист',
- margin: 12
- });
- $('.quick-view-trigger').elemToolTip({
- position: 'top',
- text: 'Быстрый просмотр',
- margin: 12
- });
- }, /*Тултипы*/
- alignElements : function() {
- function blocksMatchHeight(arr) {
- for (var i = 0; i< arr.length; i++) {
- $(arr[i]).matchHeight();
- }
- }
- var alignBlocks = function(){
- blocksMatchHeight([
- '.kinds-block__items.kinds_slider .kind-item__top',
- '.kinds-block__items.kinds_slider .kind-price',
- '.kinds-block__items.kinds_slider .kind-additional__top',
- '.mods_block .kinds-block__items .kind-item__top',
- '.mods_block .kinds-block__items .kind-price',
- '.kinds-block .kind-additional__btns',
- '.kinds-block .kind-item__bottom',
- '.product-list.thumbs .product-item .product-price',
- '.product-list.thumbs .product-item .product-additional__top-right',
- '.main-blocks .product-list.thumbs .product-item__bottom'
- ]);
- }
- setTimeout(function(){
- alignBlocks();
- }, 100);
- window.addEventListener('orientationchange', function() {
- setTimeout(function(){
- $.fn.matchHeight._update();
- }, 300);
- }, false);
- }, /*Выравнивание блоков по высоте*/
- foldersInBlock: function(){
- if ($('.folders_slider').length<1) {
- $('.site-folders-in-block').each(function() {
- var $hiddenItems = $(this).find('.site-folders-in-block__item:hidden');
- if ($hiddenItems.length>0) {
- $(this).find('.site-folders-in-block__more').show();
- };
- $(this).find('.site-folders-in-block__more-btn').on('click', function(){
- var $this = $(this);
- var $ins = $(this).find('ins');
- var currentText = $this.data('text');
- var hideText = $('html').attr('lang') == 'ru' ? 'Скрыть' : 'Hide';
- if ($hiddenItems.hasClass('active')) {
- $ins.text(currentText);
- $this.removeClass('active');
- $hiddenItems.removeClass('active');
- $hiddenItems.slideToggle(200);
- } else {
- $ins.text(hideText);
- $this.addClass('active');
- $hiddenItems.addClass('active');
- $hiddenItems.slideToggle(200);
- };
- });
- });
- };
- var respSettings = {};
- if ($('.site-folders-in-block__items').hasClass('small_folders')) {
- respSettings = {
- 1024: {
- controls: false,
- items: 7,
- gutter: 30
- },
- 1261: {
- controls: true,
- items: 7,
- gutter: 30
- }
- }
- } else if ($('.site-folders-in-block__items').hasClass('medium_folders')) {
- respSettings = {
- 1024: {
- controls: false,
- items: 6,
- gutter: 30
- },
- 1261: {
- controls: true,
- items: 6,
- gutter: 30
- }
- }
- } else if ($('.site-folders-in-block__items').hasClass('large_folders')) {
- respSettings = {
- 1024: {
- controls: false,
- items: 4,
- gutter: 30
- },
- 1261: {
- controls: true,
- items: 4,
- gutter: 30
- }
- }
- };
- var $slider = $('.folders_slider .site-folders-in-block__items');
- var sliderAutoplay = $slider.data('autoplay');
- if ($slider.length>0) {
- var slider = tns({
- loop: false,
- rewind: true,
- container: '.folders_slider .site-folders-in-block__items',
- slideBy: 1,
- autoplayHoverPause: true,
- mode: 'carousel',
- axis: 'horizontal',
- autoplay: sliderAutoplay,
- autoplayButtonOutput: false,
- mouseDrag: true,
- center: false,
- autoWidth: false,
- nav: true,
- swipeAngle: 50,
- controlsText: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_next_small"></use></svg>'],
- navPosition: 'bottom',
- preventActionWhenRunning: false,
- responsive: respSettings
- });
- shop2_gr.methods.arrowsPosition('.folders_slider .site-folders-in-block__items', '.site-folders-in-block__pic');
- var folders_slider_timeout;
- var winWidth = window.innerWidth;
- if (winWidth <= 1260) {
- if ($slider.hasClass('tns-slider')) {
- slider.destroy();
- };
- } else {
- if (!$slider.hasClass('tns-slider')) {
- slider = slider.rebuild();
- };
- };
- $(window).on('resize', function(){
- var $slider = $('.folders_slider .site-folders-in-block__items');
- var winWidth = window.innerWidth;
- if (folders_slider_timeout) {
- clearTimeout(folders_slider_timeout);
- };
- folders_slider_timeout = setTimeout(function(){
- if (winWidth <= 1260) {
- if ($slider.hasClass('tns-slider')) {
- slider.destroy();
- };
- } else {
- if (!$slider.hasClass('tns-slider')) {
- slider = slider.rebuild();
- };
- };
- shop2_gr.methods.arrowsPosition('.folders_slider .site-folders-in-block__items', '.site-folders-in-block__pic');
- return slider;
- }, 50);
- return slider;
- });
- };
- }, /*Категории в блоке*/
- siteActions: function() {
- shop2_gr.methods.initMoreBtn('.site-actions__items', function(){
- $('.site-actions__items:not(.abosolute_text) .site-actions__bottom').matchHeight();
- }, function(){
- setTimeout(function(){
- $('.site-actions__items:not(.abosolute_text) .site-actions__text').matchHeight();
- }, 300);
- });
- }, /*Акции*/
- siteActions2: function() {
- shop2_gr.methods.initMoreBtn('.site-actions-2__items:not(.actions2_slider)');
- // tiny-slider initialisation
- var sliders = document.querySelectorAll('.site-actions-2__items.actions2_slider');
- var slidersCounter = 0;
- var respSettings = {};
- if ($('.dynamic_width').length) {
- respSettings = {
- 320: {
- controls: false,
- items: 1,
- gutter: 0
- },
- 640: {
- controls: false,
- items: 2,
- gutter: 16
- },
- 768: {
- controls: false,
- items: 3,
- gutter: 20
- },
- 1024: {
- controls: false,
- items: 4,
- gutter: 20
- },
- 1261: {
- controls: true,
- items: 4,
- gutter: 20
- },
- 1341: {
- controls: true,
- items: 4,
- gutter: 20
- },
- 1367: {
- controls: true,
- items: 4,
- gutter: 30
- }
- }
- } else {
- respSettings = {
- 320: {
- controls: false,
- items: 1,
- gutter: 0
- },
- 640: {
- controls: false,
- items: 2,
- gutter: 16
- },
- 768: {
- controls: true,
- items: 3,
- gutter: 20
- },
- 1024: {
- controls: false,
- items: 4,
- gutter: 20
- },
- 1261: {
- controls: true,
- items: 4,
- gutter: 30
- }
- }
- };
- shop2_gr.methods.forEach(sliders, function(index, value) {
- var sliderAutoplay = +sliders[index].getAttribute('data-autoplay');
- var multislider = tns({
- loop: false,
- rewind: true,
- container: value,
- slideBy: 1,
- autoplayHoverPause: true,
- mode: 'carousel',
- axis: 'horizontal',
- autoplay: sliderAutoplay,
- autoplayButtonOutput: false,
- mouseDrag: true,
- center: false,
- autoWidth: false,
- nav: true,
- swipeAngle: 50,
- controlsText: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_next_small"></use></svg>'],
- navPosition: 'bottom',
- preventActionWhenRunning: false,
- responsive: respSettings
- });
- slidersCounter += 1;
- return slidersCounter;
- });
- if (slidersCounter == sliders.length) {
- setTimeout(function(){
- shop2_gr.methods.insertTinyDots('.site-actions-2', '.site-actions-2__nav');
- shop2_gr.methods.arrowsPosition('.site-actions-2__items.actions2_slider', '.site-actions-2__image');
- }, 300);
- };
- }, /*Акции 2*/
- dayProduct: function() {
- var grTimerTemplate = function(wrap) {
- var timerBlocksFirst = $(wrap + '.gr-timer'),
- $htmlLang = window._s3Lang.code;
- if ($htmlLang == 'de' || $htmlLang == 'en') {
- timerDays = 'days';
- timerHours = 'hours';
- timerMinutes = 'minutes';
- timerSeconds = 'seconds'
- } else {
- timerDays = 'Дней';
- timerHours = 'Часов';
- timerMinutes = 'Минут';
- timerSeconds = 'Секунд'
- };
- var outputFormat = '<span class="gr-timer-elem gr-timer-days"> <span class="gr-timer-number">%d </span> <em>' + timerDays + '</em> </span> <span class="gr-timer-delim"><svg class="gr-svg-icon"><use xlink:href="#icon_shop_timer_dots"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_timer_dots_small"></use></svg></span> <span class="gr-timer-elem"> <span class="gr-timer-number">%h </span> <em>' + timerHours + '</em> </span> <span class="gr-timer-delim"><svg class="gr-svg-icon"><use xlink:href="#icon_shop_timer_dots"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_timer_dots_small"></use></svg></span> <span class="gr-timer-elem"> <span class="gr-timer-number">%m </span> <em>' + timerMinutes + '</em> </span> <span class="gr-timer-delim"><svg class="gr-svg-icon"><use xlink:href="#icon_shop_timer_dots"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_timer_dots_small"></use></svg></span> <span class="gr-timer-elem"> <span class="gr-timer-number">%s </span> <em>' + timerSeconds + '</em> </span>';
- if (timerBlocksFirst.length) {
- timerBlocksFirst.timer({
- format_in: "%d.%M.%y %h:%m:%s",
- format_out: outputFormat,
- wrapChar: 'ins class="timerWrapChar"',
- language: $htmlLang,
- update_time: 1000,
- onEnd: function() {
- $(this).hide();
- },
- onTimeChange: function() {
- $('.site-sale__date .gr-timer-days').each(function() {
- var $first = $(this).find('.timerWrapChar:first-child');
- var $last = $(this).find('.timerWrapChar:last-child');
- if (+$first.text() == 0 && +$last.text() == 0) {
- $(this).hide();
- $(this).next().hide();
- }
- });
- }
- });
- }
- };
- grTimerTemplate('.site-sale__date');
- $('.site-sale__date .gr-timer-days').each(function() {
- var $first = $(this).find('.timerWrapChar:first-child');
- var $last = $(this).find('.timerWrapChar:last-child');
- if (+$first.text() == 0 && +$last.text() == 0) {
- $(this).hide();
- $(this).next().hide();
- }
- });
- }, /*Товар дня*/
- reviewsSlider: function(){
- $('.site-reviews__items:not(.reviews_slider)').each(function() {
- var $parent = $(this).parents('.site-reviews');
- var $hiddenItems = $(this).find('.site-reviews__item:hidden');
- if ($hiddenItems.length > 0) {
- $parent.find('.site-reviews__more').show();
- };
- $parent.find('.site-reviews__more-btn').on('click', function() {
- var $this = $(this);
- var $ins = $(this).find('ins');
- var currentText = $this.data('text');
- var hideText = $('html').attr('lang') == 'ru' ? 'Скрыть' : 'Hide';
- if ($hiddenItems.hasClass('active')) {
- $ins.text(currentText);
- $this.removeClass('active');
- $hiddenItems.removeClass('active');
- $hiddenItems.slideToggle(200);
- } else {
- $ins.text(hideText);
- $this.addClass('active');
- $hiddenItems.addClass('active');
- $hiddenItems.slideToggle(200);
- };
- });
- });
- // tiny-slider initialisation
- var sliders = document.querySelectorAll('.site-reviews__items.reviews_slider');
- var slidersCounter = 0;
- shop2_gr.methods.forEach(sliders, function(index, value) {
- var sliderAutoplay = +sliders[index].getAttribute('data-autoplay');
- var multislider = tns({
- loop: false,
- rewind: true,
- container: value,
- slideBy: 1,
- autoplayHoverPause: true,
- mode: 'carousel',
- axis: 'horizontal',
- autoplay: sliderAutoplay,
- autoplayButtonOutput: false,
- mouseDrag: true,
- center: false,
- autoWidth: false,
- nav: true,
- swipeAngle: 50,
- controlsText: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_next_small"></use></svg>'],
- navPosition: 'bottom',
- preventActionWhenRunning: false,
- responsive: {
- 320: {
- controls: false,
- items: 1,
- gutter: 0
- },
- 768: {
- controls: false,
- items: 1,
- gutter: 0
- },
- 1024: {
- controls: false,
- items: 2,
- gutter: 20
- },
- 1261: {
- controls: false,
- items: 3,
- gutter: 20
- },
- 1341: {
- controls: true,
- items: 3,
- gutter: 20
- },
- 1367: {
- controls: true,
- items: 3,
- gutter: 30
- }
- }
- });
- slidersCounter += 1;
- return slidersCounter;
- });
- if (slidersCounter == sliders.length) {
- setTimeout(function(){
- shop2_gr.methods.insertTinyDots('.site-reviews', '.site-reviews__nav');
- }, 300);
- };
- }, /*Отзывы*/
- reviews2Slider: function(){
- $('.site-reviews-2__items:not(.reviews2_slider)').each(function() {
- var $parent = $(this).parents('.site-reviews-2');
- var $hiddenItems = $(this).find('.site-reviews-2__item:hidden');
- if ($hiddenItems.length > 0) {
- $parent.find('.site-reviews-2__more').show();
- };
- $parent.find('.site-reviews-2__more-btn').on('click', function() {
- var $this = $(this);
- var $ins = $(this).find('ins');
- var currentText = $this.data('text');
- var hideText = $('html').attr('lang') == 'ru' ? 'Скрыть' : 'Hide';
- if ($hiddenItems.hasClass('active')) {
- $ins.text(currentText);
- $this.removeClass('active');
- $hiddenItems.removeClass('active');
- $hiddenItems.slideToggle(200);
- } else {
- $ins.text(hideText);
- $this.addClass('active');
- $hiddenItems.addClass('active');
- $hiddenItems.slideToggle(200);
- };
- });
- });
- // tiny-slider initialisation
- var sliders = document.querySelectorAll('.site-reviews-2__items.reviews2_slider');
- var slidersCounter = 0;
- shop2_gr.methods.forEach(sliders, function(index, value) {
- var sliderAutoplay = +sliders[index].getAttribute('data-autoplay');
- var multislider = tns({
- loop: false,
- rewind: true,
- container: value,
- slideBy: 1,
- autoplayHoverPause: true,
- mode: 'carousel',
- axis: 'horizontal',
- autoplay: sliderAutoplay,
- autoplayButtonOutput: false,
- mouseDrag: true,
- center: false,
- autoWidth: false,
- nav: true,
- swipeAngle: 50,
- controlsText: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_next_small"></use></svg>'],
- navPosition: 'bottom',
- preventActionWhenRunning: false,
- responsive: {
- 320: {
- controls: false,
- items: 1,
- gutter: 0
- },
- 768: {
- controls: false,
- items: 1,
- gutter: 0
- },
- 1024: {
- controls: false,
- items: 2,
- gutter: 20
- },
- 1261: {
- controls: true,
- items: 2,
- gutter: 20
- },
- 1341: {
- controls: true,
- items: 2,
- gutter: 20
- },
- 1367: {
- controls: true,
- items: 2,
- gutter: 30
- }
- }
- });
- slidersCounter += 1;
- return slidersCounter;
- });
- if (slidersCounter == sliders.length) {
- setTimeout(function(){
- shop2_gr.methods.insertTinyDots('.site-reviews-2', '.site-reviews-2__nav');
- }, 300);
- };
- }, /*Отзывы 2*/
- articlesSlider: function(){
- shop2_gr.methods.initMoreBtn('.site-articles__items:not(.articles_slider)');
- // tiny-slider initialisation
- var sliders = document.querySelectorAll('.site-articles__items.articles_slider');
- var slidersCounter = 0;
- shop2_gr.methods.forEach(sliders, function(index, value) {
- var sliderAutoplay = +sliders[index].getAttribute('data-autoplay');
- var multislider = tns({
- loop: false,
- rewind: true,
- container: value,
- slideBy: 1,
- autoplayHoverPause: true,
- mode: 'carousel',
- axis: 'horizontal',
- autoplay: sliderAutoplay,
- autoplayButtonOutput: false,
- mouseDrag: true,
- center: false,
- autoWidth: false,
- nav: true,
- swipeAngle: 50,
- controlsText: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_next_small"></use></svg>'],
- navPosition: 'bottom',
- preventActionWhenRunning: false,
- responsive: {
- 320: {
- controls: false,
- items: 1,
- gutter: 0
- },
- 640: {
- controls: false,
- items: 2,
- gutter: 16
- },
- 768: {
- controls: false,
- items: 3,
- gutter: 20
- },
- 1024: {
- controls: false,
- items: 4,
- gutter: 20
- },
- 1261: {
- controls: true,
- items: 4,
- gutter: 20
- },
- 1341: {
- controls: true,
- items: 4,
- gutter: 20
- },
- 1367: {
- controls: true,
- items: 4,
- gutter: 30
- }
- }
- });
- slidersCounter += 1;
- return slidersCounter;
- });
- if (slidersCounter == sliders.length) {
- setTimeout(function(){
- shop2_gr.methods.insertTinyDots('.site-articles', '.site-articles__nav');
- shop2_gr.methods.arrowsPosition('.site-articles__items.articles_slider', '.site-articles__image');
- }, 300);
- };
- }, /*Статьи*/
- otherScripts : function() {
- $('table').wrap('<div class="table-wrapper"></div>');
- // Нажатие на клавишу Esc
- $(document).on('keyup.esc_keyup', function(keyUp){
- if (keyUp.keyCode
- == 27) {
- $('.sorting-block').removeClass('active');
- $('.shop2-color-ext-select').removeClass('active');
- return false;
- };
- });
- // Нажатие на клавишу Esc
- // Клик по документу
- $(document).on('click', function(e){
- if (!$(e.target).closest('.sorting-block').length && !$(e.target).closest('.sorting-button').length) {
- $('.sorting-block').removeClass('active');
- };
- if (!$(e.target).closest('.shop2-color-ext-select .shop2-color-ext-options, #shop2-color-ext-select').length) {
- $('.shop2-color-ext-select').removeClass('active');
- };
- setTimeout(function(){
- $('#shop2-alert-ok').html('<span><svg class="gr-svg-icon gr_big_icon"><use xlink:href="#icon_site_close"></use></svg><svg class="gr-svg-icon"><use xlink:href="#icon_site_close_small"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_site_close_mini"></use></svg></span>');
- }, 250)
- });
- // Клик по документу
- // Меню в подвале
- function divideList() {
- var $list = $('.site-footer-top .footer-menu > li');
- var devider = Math.ceil($list.length/2);
- for (var i = 0; i < $list.length; i += devider) {
- $list.slice(i, i + devider).wrapAll("<div class='footer-menu__column'></div>");
- };
- };
- divideList();
- // Меню в подвале
- }
- };
- shop2_gr.methods = {
- forEach: function(array, callback, scope) {
- for (var i = 0; i < array.length; i++) {
- callback.call(scope, i, array[i]);
- };
- },
- viewLots: function() {
- var $productList = $('.product-list');
- var $productItems = $('.shop2-product-item');
- var loadedValue = $('.shop-view__item.active-view').data('value');
- if ( loadedValue == 'thumbs' ) {
- $('.product-list-titles').addClass('hide');
- $('.product-item').each(function() {
- var $flags = $(this).find('.product-flags');
- var $flagsContainer = $(this).find('.product-item__top');
- $flags.appendTo($flagsContainer);
- });
- } else if ( loadedValue == 'simple' ) {
- $('.product-list-titles').addClass('hide');
- $('.product-item').each(function() {
- var $flags = $(this).find('.product-flags');
- var $flagsContainer = $(this).find('.product-item__top');
- $flags.appendTo($flagsContainer);
- });
- } else if ( loadedValue == 'list' ) {
- $('.product-list-titles').removeClass('hide');
- $('.product-item').each(function() {
- var $flags = $(this).find('.product-flags');
- var $flagsContainer = $(this).find('.product-item__bottom-left');
- $flags.prependTo($flagsContainer);
- });
- };
- $('.shop-view .shop-view__item').on('click', function(e) {
- var $this = $(this),
- value = $this.data('value');
- if ( value == 'thumbs' ) {
- $('.product-list-titles').addClass('hide');
- $('.product-item').each(function() {
- var $flags = $(this).find('.product-flags');
- var $flagsContainer = $(this).find('.product-item__top');
- $flags.appendTo($flagsContainer);
- });
- } else if ( value == 'simple' ) {
- $('.product-list-titles').addClass('hide');
- $('.product-item').each(function() {
- var $flags = $(this).find('.product-flags');
- var $flagsContainer = $(this).find('.product-item__top');
- $flags.appendTo($flagsContainer);
- });
- } else if ( value == 'list' ) {
- $('.product-list-titles').removeClass('hide');
- $('.product-item').each(function() {
- var $flags = $(this).find('.product-flags');
- var $flagsContainer = $(this).find('.product-item__bottom-left');
- $flags.prependTo($flagsContainer);
- });
- };
- $this
- .addClass('active-view')
- .siblings()
- .removeClass('active-view');
- if ($productList.length>0) {
- $productList
- .removeClass($productList.attr('class').replace( /[a-zA-Z0-9_-]+(?=\s)/, "" ))
- .addClass(value);
- };
- $(this).parents('.shop-view__inner').removeClass('active');
- createCookie('views', value, 30);
- setTimeout(function() {
- $.fn.matchHeight._update();
- }, 300);
- e.preventDefault();
- return false;
- });
- },
- amountInit: function() {
- $('.cart-products__item, .shop2-product-item, .shop2-product, .kind-item, .popup-product').each(function() {
- var $this = $(this);
- var $amountWrap = $this.find('.shop2-product-amount');
- var $input = $amountWrap.find('input[type="text"]');
- var $buttons = $amountWrap.find('button');
- var $minus = $amountWrap.find('button.amount-minus');
- var $plus = $amountWrap.find('button.amount-plus');
- var min = $amountWrap.find('input').data('min');
- var inputVal = +$input.val();
- if (inputVal<=min) {
- $minus.attr('disabled', 'disabled');
- }
- $buttons.on('click', function(){
- var parent = $(this).parent();
- var input = parent.find('input');
- setTimeout(function(){
- var inputVal = +input.val();
- if (inputVal<=min) {
- $minus.attr('disabled', 'disabled');
- } else {
- $minus.removeAttr('disabled');
- }
- }, 100);
- });
- $input.on('change', function(e) {
- var curVal = +$(this).val();
- if (curVal < min) {
- $(this).val(min);
- } else if (curVal == min) {
- $minus.attr('disabled', 'disabled');
- } else if (curVal > min) {
- $minus.removeAttr('disabled');
- }
- });
- });
- },
- rangeSliderInit: function(element, isFilter) {
- if (isFilter === undefined) {
- isFilter = true
- };
- $(element).each(function() {
- var curMin = $(this).siblings('.input-from').find('input').val() != "" ? parseInt($(this).siblings('.input-from').find('input').val()) : 0;
- var curMax = $(this).siblings('.input-to').find('input').val() != "" ? parseInt($(this).siblings('.input-to').find('input').val()) : 200000;
- var rangeMin = $(this).siblings('.input-to').find('input').data('range_min');
- var rangeMax = $(this).siblings('.input-to').find('input').data('range_max');
- var $this = $(this),
- $lower = $this.siblings('.input-from').find('input'),
- $upper = $this.siblings('.input-to').find('input'),
- arr = [curMin, curMax];
- var randomNum = parseInt(Math.random() * 100 * 33);
- var throttleName = 'randomThrottleName-' + randomNum;
- $this.slider({
- range: true,
- min: rangeMin,
- max: rangeMax,
- values: arr,
- classes: {
- 'ui-slider-range': 'ui-corner-all ui-widget-header2'
- },
- slide: function( event, ui ) {
- $lower.val( ui.values[ 0 ] );
- $upper.val( ui.values[ 1 ] );
- if (isFilter) {
- $.s3throttle(throttleName, function() {
- $('.range-input').each(function() {
- var name = $(this).attr('name');
- var value = $(this).val();
- shop2.filter.add(name, value);
- shop2.filter.count();
- });
- }, 500);
- }
- },
- create: function( event, ui ) {
- $lower.val( arr[ 0 ] );
- $upper.val( arr[ 1 ] );
- }
- });
- $lower.on('keyup', function() {
- $this.slider( 'values', [ $lower.val(), $upper.val() ] );
- });
- $upper.on('keyup', function() {
- $this.slider( 'values', [ $lower.val(), $upper.val() ] );
- });
- });
- },
- resizeController: function() {
- var $win = $(window),
- winWidth = window.innerWidth,
- range = [],
- func = [],
- toggleState = [undefined, undefined];
- if (!!arguments.length) {
- for (var i = 0; i <= arguments.length-1; i++) {
- if ($.isArray(arguments[i])) {
- range = arguments[i];
- } else if ($.isNumeric(arguments[i])) {
- range.push(arguments[i]);
- } else if ($.isFunction(arguments[i])) {
- func.push(arguments[i]);
- }
- };
- }
- $win.resize(function(event) {
- winWidth = window.innerWidth;
- if (range.length > 1) {
- if (winWidth >= range[0] && winWidth <= range[range.length-1] && typeof toggleState[0] === 'undefined') {
- func[0]();
- toggleState[0] = true;
- toggleState[1] = undefined;
- } else if ((winWidth < range[0] || winWidth > range[range.length-1]) && typeof toggleState[1] === 'undefined') {
- toggleState[0] = undefined;
- toggleState[1] = true;
- if ($.isFunction(func[1])) {
- func[1]();
- }
- }
- } else if (range.length == 1) {
- if (winWidth <= range[0] && typeof toggleState[0] === 'undefined') {
- func[0]();
- toggleState[0] = true;
- toggleState[1] = undefined;
- } else if (winWidth > range[0] && typeof toggleState[1] === 'undefined') {
- toggleState[0] = undefined;
- toggleState[1] = true;
- if ($.isFunction(func[1])) {
- func[1]();
- }
- }
- }
- }).trigger('resize');
- },
- insertTinyDots: function(itemContainer, itemNav) {
- var item = document.querySelectorAll(itemContainer);
- for (var i = item.length - 1; i >= 0; i--) {
- var nav = item[i].querySelector('.tns-nav');
- var navContainer = item[i].querySelector(itemNav);
- if (nav != null) {
- navContainer.insertAdjacentElement('afterbegin', nav);
- };
- };
- },
- arrowsPosition: function(slider, item) {
- var arrows_timeout;
- $(slider).each(function() {
- var $this = $(this);
- var $image = $this.find(item);
- var $controls = $this.parents('.tns-outer').find('.tns-controls');
- var imgHeight = $image.outerHeight();
- $controls.css({
- "top": imgHeight / 2
- });
- });
- $(window).on('resize', function() {
- if (arrows_timeout) {
- clearTimeout(arrows_timeout);
- };
- arrows_timeout = setTimeout(function() {
- $(slider).each(function() {
- var $this = $(this);
- var $image = $this.find(item);
- var $controls = $this.parents('.tns-outer').find('.tns-controls');
- var imgHeight = $image.outerHeight();
- $controls.css({
- "top": imgHeight / 2
- });
- });
- }, 50);
- });
- },
- initMoreBtn: function(item, afterInit, afterOpened) {
- $(item).each(function() {
- var $parent = $(this).parents('.js_block_parent');
- var $btn = $parent.find('.js_block_more_btn');
- var $hiddenItems = $(this).find('.js_block_item:hidden');
- if ($hiddenItems.length > 0) {
- $parent.find('.js_block_more').show();
- } else {
- $parent.find('.js_block_more').hide();
- };
- if (afterInit) {
- afterInit();
- };
- $btn.on('click', function() {
- var $this = $(this);
- var $ins = $(this).find('ins');
- var currentText = $this.data('text');
- var hideText = $('html').attr('lang') == 'ru' ? 'Скрыть' : 'Hide';
- if ($hiddenItems.hasClass('active')) {
- $ins.text(currentText);
- $this.removeClass('active');
- $hiddenItems.removeClass('active');
- $hiddenItems.slideToggle(200);
- } else {
- $ins.text(hideText);
- $this.addClass('active');
- $hiddenItems.addClass('active');
- $hiddenItems.slideToggle(200);
- if (afterOpened) {
- afterOpened();
- };
- };
- });
- });
- }
- }
- shop2_gr.init();
- myObject.shop2_gr = shop2_gr;
- })(jQuery, window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement