PageSourceSearch

https://sarkispastry.com/cdn/shop/t/9/assets/functions.min.js?v=64275148802526567761527195131

js sarkispastry.com collected 2026-10-07 01:12:16 UTC 198,978 bytes, 4,469 lines download raw bytes

1var baselThemeModule;
2
3(function($) {
4    "use strict";
5
6    baselThemeModule = (function() {
7        var baselTheme = {
8            popupEffect: 'mfp-move-horizontal',
9             shopLoadMoreBtn : '.basel-products-load-more.load-on-scroll',
10            supports_html5_storage: false,
11            ajaxLinks: '.basel-product-categories a, .basel-products-shop-view a, .widget_product_categories a, .widget_layered_nav_filters a, .filters-area a, .shopify-pagination a, .basel-shopify-layered-nav a, .widget_product_tag_cloud a'
12        };
13
14        /* Storage Handling */
15        try {
16            baselTheme.supports_html5_storage = ( 'sessionStorage' in window && window.sessionStorage !== null );
17
18            window.sessionStorage.setItem( 'basel', 'test' );
19            window.sessionStorage.removeItem( 'basel' );
20        } catch( err ) {
21            baselTheme.supports_html5_storage = false;
22        }
23
24        return {
25
26            init: function() {
27                this.headerBanner();
28                this.fixedHeaders();
29
30                this.verticalHeader();
31
32                this.splitNavHeader();
33
34                this.visibleElements();
35
36                this.bannersHover();
37                this.shopcarousel();
38                this.inscarousel();
39                this.instagram();
40                this.parallax();
41
42                this.googleMap();
43
44                this.scrollTop();
45
46                this.quickViewInit();
47
48                this.quickShop();
49
50                this.sidebarMenu();
51
52                //this.addToCart();
53
54                this.AJAXAddToCart();
55
56                this.AJAXFormAddToCart();
57
58                this.productImages();
59
60                this.productImagesGallery();
61
62                this.stickyDetails();
63
64                this.mfpPopup();
65
66                //this.swatchesVariations();
67
68                this.swatchesOnGrid();
69                // section off
70                this.blogMasonry();
71
72                this.blogLoadMore();
73
74                this.productsLoadMore();
75
76                this.productsTabs();
77                this.productsGalaxyTabs();
78
79                //this.portfolioLoadMore();
80
81                this.equalizeColumns();
82
83                this.menuSetUp();
84
85                this.menuOffsets();
86
87                this.onePageMenu();
88
89                this.mobileNavigation();
90
91                this.simpleDropdown();
92
93                //this.shopifyWrappTable();
94
95                this.autoloadCompare();
96                
97                this.wishList();
98                this.loginWishlist();
99                this.removeWishlist();
100
101                this.compare();
102
103                this.gl_save_note();
104
105                this.promoPopup();
106
107                this.cookiesPopup();
108
109                this.productVideo();
110
111                this.product360Button();
112
113                // this.btnsToolTips();
114
115                this.stickyFooter();
116
117                //this.updateWishListNumberInit();
118
119                this.cartWidget();
120
121                this.ajaxFilters();
122
123                this.shopPageInit();
124
125                this.filtersArea();
126
127                this.categoriesMenu();
128
129                this.searchFullScreen();
130
131                this.loginTabs();
132
133                this.productAccordion();
134
135                this.productCompact();
136
137                this.countDownTimer();
138
139                this.mobileFastclick();
140
141                this.nanoScroller();
142              this.videoPoster();
143
144                this.RTL();
145
146               // this.ShopifychangeItem();
147
148                this.AJAXRemoveFromCart();
149
150                this.shopifyQuantity();
151               this.loginSidebar();
152
153                // this.shopify_3_0();
154
155                $(window).resize();
156
157                $('body').addClass('document-ready');
158
159                // $(document.body).on('updated_cart_totals', function() {
160                //     baselThemeModule.shopifyWrappTable();
161                // });
162
163            },
164            // shopify_3_0: function() {
165            //     if ( theme.wc_version == 'old' ) {
166            //         var that = this;
167            //         $( 'body' ).on( 'shopify_init_gallery', function() {
168            //             if ( $.isFunction( $.fn.zoom ) ) {
169            //                 that.init_zoom();
170            //             }
171            //         });
172            //     }
173            // },
174
175            init_zoom: function() {
176                var zoom_target = $( '.shopify-product-gallery__image' ),
177                    enable_zoom = false;
178
179                if ( ! wc_single_product_params.flexslider_enabled ) {
180                    zoom_target = zoom_target.first();
181                }
182
183                $( zoom_target ).each( function( index, target ) {
184                    var image = $( target ).find( 'img' );
185                      
186                    if ( image.attr( 'width' ) > $( '.shopify-product-gallery' ).width() ) {
187                        enable_zoom = true;
188                        return false;
189                    }
190                } );
191
192                // But only zoom if the img is larger than its container.
193                if ( enable_zoom ) {
194                    zoom_target.trigger( 'zoom.destroy' );
195                    zoom_target.zoom({
196                        touch: false
197                    });
198                }
199            },
200            productHover : function(){
201
202                $('.shopify-hover-base').each(function(){
203
204                    var $product = $(this);
205
206                    $product.imagesLoaded(function() {
207
208                        // Read more details button
209
210                        var btnHTML = '<a href="#" class="more-details-btn"><span>' + 'more' + '</a></span>',
211                            content = $product.find('.hover-content'),
212                            inner = content.find('.hover-content-inner'),
213                            contentHeight = content.outerHeight(),
214                            innerHeight = inner.outerHeight(),
215                            delta = innerHeight - contentHeight;
216
217                        if( content.hasClass( 'more-description' ) ) return;
218
219                        if( delta > 30 ) {
220                            content.addClass('more-description');
221                            content.append(btnHTML);
222                        } else if( delta > 0 ) {
223                            content.css( 'height', contentHeight + delta );
224                        }
225
226                        // Bottom block height
227
228                        reculc( $product );
229                    });
230
231                });
232
233                $('body').on('click', '.more-details-btn', function(e) {
234                    e.preventDefault();
235                    $(this).parent().addClass('show-full-description');
236                        reculc( $(this).parents('.shopify-hover-base') );
237                });
238
239                if( $(window).width() < 992 ) {
240                    $('.shopify-hover-base').on('click', function( e ) {
241                        var hoverClass = 'state-hover';
242                        if( ! $(this).hasClass(hoverClass) ) {
243                            e.preventDefault();
244                            $('.' + hoverClass ).removeClass(hoverClass);
245                            $(this).addClass(hoverClass);
246                        }
247                    });
248                }
249
250                var reculc = function( $el ) {
251
252                    if( $el.hasClass('product-in-carousel') ) {
253                        return;
254                    }
255
256                    var heightHideInfo = $el.find('.fade-in-block').outerHeight();
257
258                    $el.find('.content-product-imagin').css({
259                        marginBottom : -heightHideInfo
260                    });
261
262                    $el.addClass('hover-ready'); 
263                };
264
265                $('.product-grid-item').each(function() {
266                    var $el = $(this),
267                        widthHiddenInfo = $el.outerWidth();
268
269                    if( widthHiddenInfo < 255 || $(window).width() <= 1024 ) {
270                        $el.removeClass('hover-width-big').addClass('hover-width-small'); 
271                    } else {
272                        $el.removeClass('hover-width-small').addClass('hover-width-big'); 
273                    }
274                })
275
276            },
277          
278            /**
279             *-------------------------------------------------------------------------------------------------------------------------------------------
280             * Login sidebar
281             *-------------------------------------------------------------------------------------------------------------------------------------------
282             */
283             
284            loginSidebar: function() {
285                var body = $( 'body' );
286                
287                $( '.login-side-opener' ).on( 'click', function ( e ) {
288                    e.preventDefault();
289                    if( isOpened() ) {
290                        closeWidget();
291                    } else {
292                        setTimeout( function() {
293                            openWidget();
294                        }, 10);
295                    }
296                });
297                
298                body.on( 'click touchstart', '.basel-close-side', function() {
299                    if( isOpened() ) closeWidget();
300                });
301
302                body.on( 'click', '.widget-close', function( e ) {
303                    e.preventDefault();
304                    if( isOpened() ) closeWidget();
305                });
306                
307                var closeWidget = function() {
308                    body.removeClass( 'basel-login-side-opened' );
309                };
310
311                var openWidget = function() {
312                    body.addClass( 'basel-login-side-opened' );
313                };
314                
315                var isOpened = function() {
316                    return body.hasClass( 'basel-login-side-opened' );
317                };
318
319            },
320          
321            
322            /**
323             *-------------------------------------------------------------------------------------------------------------------------------------------
324             * Header banner
325             *-------------------------------------------------------------------------------------------------------------------------------------------
326             */
327             
328            headerBanner: function() {
329                var banner_version = theme.basel_settings.header_banner_version,
330                    banner_btn = theme.basel_settings.close_banner_btn,
331                    banner_enabled = theme.basel_settings.header_banner_enabled;
332                if( $.cookie( 'basel_tb_banner_' + banner_version ) == 'closed' || banner_enabled == false ) return;
333                var banner = $( '.header-banner' );
334                
335                $( 'body' ).addClass( 'header-banner-display' );
336            
337                banner.on( 'click', '.close-header-banner', function( e ) {
338                    e.preventDefault();
339                    closeBanner();
340                })
341
342                var closeBanner = function() {
343                    $( 'body' ).removeClass( 'header-banner-display' ).addClass( 'header-banner-hide' );
344                    $.cookie( 'basel_tb_banner_' + banner_version, 'closed', { expires: 60, path: '/' } );
345                };
346
347            },
348          
349           videoPoster: function() {
350                $( '.basel-video-poster-wrapper' ).on( 'click', function() {
351                    var videoWrapper = $( this ),
352                        video = videoWrapper.siblings( 'iframe' ),
353                        videoScr =  video.attr( 'src' ),
354                        videoNewSrc = videoScr + '&autoplay=1';
355
356                    if  ( videoScr.indexOf( 'vimeo.com' ) + 1 ) {
357                        videoNewSrc = videoScr + '?autoplay=1';
358                    }
359                    video.attr( 'src',videoNewSrc );
360                    videoWrapper.addClass( 'hidden-poster' );
361                })
362            },
363          
364            fixedHeaders: function(){
365
366                var getHeaderHeight = function() {
367                    var headerHeight = header.outerHeight();
368
369                    if( body.hasClass( 'sticky-navigation-only' ) ) {
370                        headerHeight = header.find( '.navigation-wrap' ).outerHeight();
371                    }
372
373                    return headerHeight;
374                };
375
376                var headerSpacer = function() {
377                    if(stickyHeader.hasClass(headerStickedClass)) return;
378                    $('.header-spacing').height(getHeaderHeight()).css('marginBottom', 40);
379                };
380
381                var body = $("body"),
382                    header = $(".main-header"),
383                    stickyHeader = header,
384                    headerHeight = getHeaderHeight(),
385                    headerStickedClass = "act-scroll",
386                    stickyClasses = '',
387                    stickyStart = 0,
388                    links = header.find('.main-nav .menu>li>a');
389
390                if( ! body.hasClass('enable-sticky-header') || body.hasClass('global-header-vertical') || header.length == 0 ) return;
391
392                var logo = header.find(".site-logo").clone().html(),
393                    navigation = header.find(".main-nav").clone().html(),
394                    rightColumn = header.find(".right-column").clone().html();
395
396                var headerClone = [
397                    '<div class="sticky-header header-clone">',
398                        '<div class="container">',
399                            '<div class="site-logo">' + logo + '</div>',
400                            '<div class="main-nav site-navigation basel-navigation">' + navigation + '</div>',
401                            '<div class="right-column">' + rightColumn + '</div>',
402                        '</div>',
403                    '</div>',
404                ].join('');
405
406
407                if( $('.topbar-wrapp').length > 0 ) {
408                    stickyStart = $('.topbar-wrapp').outerHeight();
409                }
410                  if( $( '.header-banner' ).length > 0 && body.hasClass( 'header-banner-display' ) ) {
411                    stickyStart += $( '.header-banner' ).outerHeight();
412                }
413
414                if( body.hasClass( 'sticky-header-real' ) ) {
415                    var headerSpace = $('<div/>').addClass('header-spacing');
416                    header.before(headerSpace);
417
418                    $(window).on('resize', headerSpacer);
419
420                    var timeout;
421
422                    $(window).on("scroll", function(e){
423                        if($(this).scrollTop() > stickyStart){
424                            stickyHeader.addClass(headerStickedClass);
425                        }else {
426                            stickyHeader.removeClass(headerStickedClass);
427                            clearTimeout( timeout );
428                            timeout = setTimeout(function() {
429                                headerSpacer();
430                            }, 200);
431                        }
432                    });
433
434                } else if( body.hasClass( 'sticky-header-clone' ) ) {
435                    header.before( headerClone );
436                    stickyHeader = $('.sticky-header');
437                }
438
439                // Change header height smooth on scroll
440                if( body.hasClass( 'basel-header-smooth' ) ) {
441
442                    $(window).on("scroll", function(e){
443                        var space = ( 120 - $(this).scrollTop() ) / 2;
444
445                        if(space >= 60 ){
446                            space = 60;
447                        } else if( space <= 30 ) {
448                            space = 30;
449                        }
450                        links.css({
451                            paddingTop: space,
452                            paddingBottom: space
453                        });
454                    });
455
456                }
457
458                if(body.hasClass("basel-header-overlap") || body.hasClass( 'sticky-navigation-only' )){
459                }
460
461
462                if(!body.hasClass("basel-header-overlap") && body.hasClass("sticky-header-clone")){
463                    header.attr('class').split(' ').forEach(function(el) {
464                        if( el.indexOf('main-header') == -1 && el.indexOf('header-') == -1) {
465                            stickyClasses += ' ' + el;
466                        }
467                    });
468
469                    stickyHeader.addClass(stickyClasses);
470
471                     $(window).on("scroll", function(e){
472                        if($(this).scrollTop() > headerHeight + 30){
473                            stickyHeader.addClass(headerStickedClass);
474                        }else {
475                            stickyHeader.removeClass(headerStickedClass);
476                        }
477                    });
478                }
479
480                body.addClass('sticky-header-prepared');
481            },
482
483            /**
484             *-------------------------------------------------------------------------------------------------------------------------------------------
485             * Vertical header
486             *-------------------------------------------------------------------------------------------------------------------------------------------
487             */
488
489             verticalHeader: function() {
490
491                var $header = $('.header-vertical').first();
492
493                if( $header.length < 1 ) return;
494
495                var $body, $window, $sidebar, top = false,
496                    bottom = false, windowWidth, adminOffset, windowHeight, lastWindowPos = 0,
497                    topOffset = 0, bodyHeight, headerHeight, resizeTimer, Y = 0, delta,
498                    headerBottom, viewportBottom, scrollStep;
499
500                $body          = $( document.body );
501                $window        = $( window );
502                adminOffset    = $body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
503
504                $window
505                    .on( 'scroll', scroll )
506                    .on( 'resize', function() {
507                        clearTimeout( resizeTimer );
508                        resizeTimer = setTimeout( resizeAndScroll, 500 );
509                    } );
510
511                resizeAndScroll();
512
513                for ( var i = 1; i < 6; i++ ) {
514                    setTimeout( resizeAndScroll, 100 * i );
515                }
516
517
518                // Sidebar scrolling.
519                function resize() {
520                    windowWidth = $window.width();
521
522                    if ( 1024 > windowWidth ) {
523                        top = bottom = false;
524                        $header.removeAttr( 'style' );
525                    }
526                }
527
528                function scroll() {
529                    var windowPos = $window.scrollTop();
530
531                    if ( 1024 > windowWidth ) {
532                        return;
533                    }
534
535                    headerHeight   = $header.height();
536                    headerBottom   = headerHeight + $header.offset().top;
537                    windowHeight   = $window.height();
538                    bodyHeight     = $body.height();
539                    viewportBottom = windowHeight + $window.scrollTop();
540                    delta          = headerHeight - windowHeight;
541                    scrollStep     = lastWindowPos - windowPos;
542
543                    // console.log('header bottom ', headerBottom);
544                    // console.log('viewport bottom ', viewportBottom);
545                    // console.log('Y ', Y);
546                    // console.log('delta  ', delta);
547                    // console.log('scrollStep  ', scrollStep);
548
549                    // If header height larger than window viewport
550                    if ( delta > 0 ) {
551                        // Scroll down
552                        if ( windowPos > lastWindowPos ) {
553
554                            // If bottom overflow
555
556                            if( headerBottom > viewportBottom ) {
557                                Y += scrollStep;
558                            }
559
560                            if( Y < -delta ) {
561                                bottom = true;
562                                Y = -delta;
563                            }
564
565                            top = false;
566
567                        } else if ( windowPos < lastWindowPos )  { // Scroll up
568
569                            // If top overflow
570
571                            if( $header.offset().top < $window.scrollTop() ) {
572                                Y += scrollStep;
573                            }
574
575                            if( Y >= 0 ) {
576                                top = true;
577                                Y = 0;
578                            }
579
580                            bottom = false;
581
582                        } else {
583
584                            if( headerBottom < viewportBottom ) {
585                                Y = windowHeight - headerHeight;
586                            }
587
588                            if( Y >= 0 ) {
589                                top = true;
590                                Y = 0;
591                            }
592                        }
593                    } else {
594                        Y = 0;
595                    }
596
597                    // Change header Y coordinate
598                    $header.css({
599                        top: Y
600                    });
601
602                    lastWindowPos = windowPos;
603                }
604
605                function resizeAndScroll() {
606                    resize();
607                    scroll();
608                }
609
610             },
611
612
613            /**
614             *-------------------------------------------------------------------------------------------------------------------------------------------
615             * Split navigation header
616             *-------------------------------------------------------------------------------------------------------------------------------------------
617             */
618
619            splitNavHeader: function() {
620
621                var header = $('.header-split');
622
623                if( header.length <= 0 ) return;
624
625                var navigation = header.find('.main-nav'),
626                    navItems = navigation.find('.menu > li'),
627                    itemsNumber = navItems.length,
628                    rtl = $('body').hasClass('rtl'),
629                    midIndex = parseInt( itemsNumber/2 + 0.5 * rtl - .5 ),
630                    midItem = navItems.eq( midIndex ),
631                    logo = header.find('.site-logo .basel-logo-wrap > a'),
632                    logoWidth,
633                    leftWidth = 0,
634                    rule = ( ! rtl ) ? 'marginRight' : 'marginLeft',
635                    rightWidth = 0;
636
637                var recalc = function() {
638                    logoWidth = logo.outerWidth(),
639                    leftWidth = 5,
640                    rightWidth = 0;
641
642                    for (var i = itemsNumber - 1; i >= 0; i--) {
643                        var itemWidth = navItems.eq(i).outerWidth();
644                        if( i > midIndex ) {
645                            rightWidth += itemWidth;
646                        } else {
647                            leftWidth += itemWidth;
648                        }
649                    };
650
651                    var diff = leftWidth - rightWidth;
652
653                    if( rtl ) {
654                        if( leftWidth > rightWidth ) {
655                            navigation.find('.menu > li:first-child').css('marginRight', -diff);
656                        } else {
657                            navigation.find('.menu > li:last-child').css('marginLeft', diff + 5);
658                        }
659                    } else {
660                        if( leftWidth > rightWidth ) {
661                            navigation.find('.menu > li:last-child').css('marginRight', diff + 5);
662                        } else {
663                            navigation.find('.menu > li:first-child').css('marginLeft', -diff);
664                        }
665                    }
666
667                    midItem.css(rule, logoWidth);
668                };
669
670                logo.imagesLoaded(function() {
671                    recalc();
672                    header.addClass('menu-calculated');
673                });
674
675                $(window).on('resize', recalc);
676
677            },
678
679            /**
680             *-------------------------------------------------------------------------------------------------------------------------------------------
681             * Counter shortcode method
682             *-------------------------------------------------------------------------------------------------------------------------------------------
683             */
684            counterShortcode: function(counter) {
685                if( counter.attr('data-state') == 'done' || counter.text() != counter.data('final') ) {
686                    return;
687                }
688                counter.prop('Counter',0).animate({
689                    Counter: counter.text()
690                }, {
691                    duration: 3000,
692                    easing: 'swing',
693                    step: function (now) {
694                        if( now >= counter.data('final')) {
695                            counter.attr('data-state', 'done');
696                        }
697                        counter.text(Math.ceil(now));
698                    }
699                });
700            },
701
702            /**
703             *-------------------------------------------------------------------------------------------------------------------------------------------
704             * Activate methods in viewport
705             *-------------------------------------------------------------------------------------------------------------------------------------------
706             */
707            visibleElements: function() {
708                $('.basel-counter .counter-value').each(function(){
709                    $(this).waypoint(function(){
710                        baselThemeModule.counterShortcode($(this));
711                    }, { offset: '100%' });
712                });
713
714            },
715
716            /**
717             *-------------------------------------------------------------------------------------------------------------------------------------------
718             * Compare button
719             *-------------------------------------------------------------------------------------------------------------------------------------------
720             */
721
722            compare: function() {
723                var body = $("body"),
724                    button = $("a.compare");
725
726                body.on("click", "a.compare", function() {
727                    $(this).addClass("loading");
728                    var $this = $(this), handle = $this.data('pid'),
729                        holder = $("#compare-content"), 
730                        ls = gl_Currency.cookie.tearead('tea-compare');
731                     if(ls != null){ 
732                        ls = ls.split(',');
733                     }else{
734                        ls = new Array();
735                     }
736                     if(ls.indexOf(handle)< 0 && $(this).hasClass('added') === false ){
737                        ls.push(handle);
738                        //gl_Currency.cookie.teawrite('tea-compare',ls.join(','));
739                        var ls_ = ls.join(',');
740                        if (ls_.substring(0, 1) == ',') { 
741                          ls_ = ls_.substring(1);
742                        }
743                        // console.log(ls_)
744                        gl_Currency.cookie.teawrite('tea-compare',ls_);
745                     }
746                     if( $(this).hasClass('added') === false || $.trim($("#compare-content").html()).length === 0 ) {
747                        holder.html(' ');
748                        $.ajax({
749                           url: '/pages/compare/'+ls,
750                           dataType: 'html',
751                           type: 'GET',
752                           success: function(responsive) {
753                              holder.html(responsive);
754                           },
755                           error: function(data) {
756                             console.log('ajax error');
757                           },
758                           complete: function() {
759                              $this.removeClass("loading");
760                              body.addClass("compare-opened");
761                              $('[data-pid="'+handle + '"]' ).addClass('added').html('<span class="basel-tooltip-label">'+theme.strings.added_label+'</span>'+theme.strings.added_label);
762                             //currency
763                              baselThemeModule.gl_currency();
764                           }
765                        });
766                     } else {
767                        $this.removeClass("loading");
768                        body.addClass("compare-opened");
769                       //currency
770                        baselThemeModule.gl_currency();
771                     }
772                     $('.compare').colorbox({
773                        inline:true, 
774                        title: false,
775                        width:'90%',
776                        height: '90%'
777                     });
778                     $(window).resize(function() {
779                        $('.compare').colorbox.resize({
780                              title: false,
781                             width: '90%',
782                             height: '90%'
783                         });
784                     });
785                });
786
787                body.on('click', '#cboxClose, #cboxOverlay', function() {
788                    body.removeClass("compare-opened");
789                });
790                body.bind("keydown.cbox_close", function (e) {
791                  if (e.keyCode === 27) {
792                     e.preventDefault();
793                     body.removeClass("compare-opened");
794                  }
795               });
796                body.on('click', '#compare-content .product-remove', function(ev) {
797                  ev.preventDefault();
798                  var $this = $(this),handle = $this.attr('data-rev'),holder = $("#compare-content");
799                  $('[data-pid="'+handle + '"]' ).removeClass('added').html('<span class="basel-tooltip-label">'+theme.strings.compare+'</span>'+theme.strings.compare);                
800                  var ls = decodeURI(gl_Currency.cookie.tearead('tea-compare'));
801                  //ls = ls.replace(handle+',','').replace(handle,'');
802                  //ls = ls.replace(handle,'');
803                  if(ls != null){ 
804                     ls = ls.split(',');
805                  }
806                  //console.log(ls);
807                  ls = jQuery.grep(ls, function(value) {
808                      return value != handle;
809                  });
810                  //ls.splice($.inArray(handle ,ls),1);
811                  ls  = $.trim(ls);
812                  gl_Currency.cookie.teawrite('tea-compare',ls);
813                  $('.gl_'+handle).remove();
814                  //console.log(ls);
815                  //console.log(ls.length);
816                  if(ls.length === 0 ){ 
817                     holder.find('tbody').html('<tr class="no-products odd"><td>'+theme.strings.no_compare+'</td></tr>');
818                  }
819                  // if (ls.indexOf('_sp_') > -1 === false){ 
820                  //    holder.find('tbody').html('<tr class="no-products odd"><td>'+theme.strings.no_compare+'</td></tr>');
821                  // }
822               });
823            },
824
825            /**
826             *-------------------------------------------------------------------------------------------------------------------------------------------
827             * Promo popup
828             *-------------------------------------------------------------------------------------------------------------------------------------------
829             */
830
831            promoPopup: function() {
832                var promo_version = theme.basel_settings.promo_version;
833                if( theme.basel_settings.enable_popup != 'yes' || ( theme.basel_settings.promo_popup_hide_mobile == 'yes' && $(window).width() < 768 ) ) return;
834                console.log('init popup');
835                var popup = $( '.nathan-promo-popup' ),
836                    shown = false,
837                    pages = $.cookie('basel_shown_pages');
838
839                if( ! pages ) pages = 0;
840
841                if( pages < theme.basel_settings.popup_pages) {
842                    pages++;
843                    $.cookie('basel_shown_pages', pages, { expires: 7, path: '/' } );
844                    return false;
845                }
846
847                var showPopup = function() {
848                    if ($('.nathan-promo-popup').length > 0) {
849                        $.magnificPopup.open({
850                            items: {
851                                src: '.nathan-promo-popup'
852                            },
853                            type: 'inline',
854                            removalDelay: 400, //delay removal by X to allow out-animation
855                            callbacks: {
856                                beforeOpen: function() {
857                                    this.st.mainClass = 'basel-popup-effect';
858                                },
859                                open: function() {
860                                // Will fire when this exact popup is opened
861                                // this - is Magnific Popup object
862                                },
863                                close: function() {
864                                    $.cookie('basel_popup_' + promo_version, 'shown', { expires: 7, path: '/' } );
865                                }
866                                // e.t.c.
867                            }
868                        });
869                    }
870                };
871
872                if ( $.cookie('basel_popup_' + promo_version) != 'shown' ) {
873                    if( theme.basel_settings.popup_event == 'scroll' ) {
874                        $(window).scroll(function() {
875                            if( shown ) return false;
876                            if( $(document).scrollTop() >= theme.basel_settings.popup_scroll ) {
877                                showPopup();
878                                shown = true;
879                            }
880                        });
881                    } else {
882                        setTimeout(function() {
883                            showPopup();
884                        }, theme.basel_settings.popup_delay );
885                    }
886                }
887
888                $('.basel-open-popup').on('click',function(){
889                    showPopup();
890                })
891            },
892
893
894            /**
895             *-------------------------------------------------------------------------------------------------------------------------------------------
896             * Product video button
897             *-------------------------------------------------------------------------------------------------------------------------------------------
898             */
899
900            productVideo: function() {
901                $('.product-video-button a').magnificPopup({
902                    type: 'iframe',
903                    mainClass: 'mfp-fade',
904                    removalDelay: 160,
905                    preloader: false,
906                    disableOn: false,
907                    fixedContentPos: false
908                });
909            },
910
911
912            /**
913             *-------------------------------------------------------------------------------------------------------------------------------------------
914             * Product 360 button
915             *-------------------------------------------------------------------------------------------------------------------------------------------
916             */
917
918            product360Button: function() {
919                $('.product-360-button a').magnificPopup({
920                    type: 'inline',
921                    mainClass: 'mfp-fade',
922                    removalDelay: 160,
923                    disableOn: false,
924                    preloader: false,
925                    fixedContentPos: false,
926                    callbacks: {
927                        open: function() {
928                            $(window).resize()
929                        },
930                    },
931
932                });
933            },
934
935            /**
936             *-------------------------------------------------------------------------------------------------------------------------------------------
937             * Cookies law
938             *-------------------------------------------------------------------------------------------------------------------------------------------
939             */
940
941            cookiesPopup: function() {
942                  var cookies_version = theme.basel_settings.cookies_version;
943                if( $.cookie( 'basel_cookies_' + cookies_version ) == 'accepted' || $('.basel-cookies-popup').length < 1 ) return;
944                var popup = $( '.basel-cookies-popup' );
945
946                setTimeout(function() {
947                    popup.addClass('popup-display');
948                    popup.on('click', '.cookies-accept-btn', function(e) {
949                        e.preventDefault();
950                        acceptCookies();
951                    })
952                }, 2500 );
953
954                var acceptCookies = function() {
955                    popup.removeClass('popup-display').addClass('popup-hide');
956                    $.cookie('basel_cookies', 'accepted', { expires: 60, path: '/' } );
957                };
958            },
959
960            /**
961             *-------------------------------------------------------------------------------------------------------------------------------------------
962             * Google map
963             *-------------------------------------------------------------------------------------------------------------------------------------------
964             */
965
966            googleMap: function() {
967                var gmap = $(".google-map-container-with-content");
968
969                $(window).resize(function() {
970                    gmap.css({
971                        'height': gmap.find('.basel-google-map.with-content').outerHeight()
972                    })
973                });
974
975            },
976
977            /**
978             *-------------------------------------------------------------------------------------------------------------------------------------------
979             * mobile responsive navigation
980             *-------------------------------------------------------------------------------------------------------------------------------------------
981             */
982
983            // shopifyWrappTable: function() {
984
985            //     var wooTable = $(".shopify .shop_table");
986
987            //     var cartTotals = $(".shopify .cart_totals table");
988
989            //     var wishList = $("#yith-wcwl-form .shop_table");
990
991            //     wooTable.wrap("<div class='responsive-table'></div>");
992
993            //     cartTotals.wrap("<div class='responsive-table'></div>");
994
995            //     wishList.wrap("<div class='responsive-table'></div>");
996
997            // },
998
999
1000            /**
1001             *-------------------------------------------------------------------------------------------------------------------------------------------
1002             * Menu preparation
1003             *-------------------------------------------------------------------------------------------------------------------------------------------
1004             */
1005
1006            menuSetUp: function() {
1007                var hasChildClass = 'menu-item-has-children',
1008                    mainMenu = $('.basel-navigation').find('ul.menu'),
1009                    lis = mainMenu.find(' > li'),
1010                    openedClass = 'item-menu-opened';
1011
1012                lis.has('.sub-menu-dropdown').addClass(hasChildClass);
1013
1014                mainMenu.on('click', ' > .item-event-click.menu-item-has-children > a', function(e) {
1015                    e.preventDefault();
1016                    if(  ! $(this).parent().hasClass(openedClass) ) {
1017                        $('.' + openedClass).removeClass(openedClass);
1018                    }
1019                    $(this).parent().toggleClass(openedClass);
1020                });
1021
1022                $(document).click(function(e) {
1023                    var target = e.target;
1024                    if ( $('.' + openedClass).length > 0 && ! $(target).is('.item-event-hover') && ! $(target).parents().is('.item-event-hover') && !$(target).parents().is('.' + openedClass + '')) {
1025                        mainMenu.find('.' + openedClass + '').removeClass(openedClass);
1026                        return false;
1027                    }
1028                });
1029
1030                var menuForIPad = function() {
1031                    if( $(window).width() <= 1024 ) {
1032                        mainMenu.find(' > .item-event-hover').each(function() {
1033                            $(this).data('original-event', 'hover').removeClass('item-event-hover').addClass('item-event-click');
1034                        });
1035                    } else {
1036                        mainMenu.find(' > .item-event-click').each(function() {
1037                            if( $(this).data('original-event') == 'hover' ) {
1038                                $(this).removeClass('item-event-click').addClass('item-event-hover');
1039                            }
1040                        });
1041                    }
1042                };
1043
1044                $(window).on('resize', menuForIPad);
1045            },
1046            /**
1047             *-------------------------------------------------------------------------------------------------------------------------------------------
1048             * Keep navigation dropdowns in the screen
1049             *-------------------------------------------------------------------------------------------------------------------------------------------
1050             */
1051
1052            menuOffsets: function() {
1053
1054                var $window = $(window),
1055                    $header = $('.main-header'),
1056                    mainMenu = $('.main-nav').find('ul.menu'),
1057                    lis = mainMenu.find(' > li.menu-item-design-sized');
1058
1059
1060                mainMenu.on('hover', ' > li', function(e) {
1061                    setOffset( $(this) );
1062                });
1063
1064                var setOffset = function( li ) {
1065
1066                    var dropdown = li.find(' > .sub-menu-dropdown'),
1067                        siteWrapper = $('.website-wrapper');
1068
1069
1070                    dropdown.attr('style', '');
1071
1072                    var dropdownWidth = dropdown.outerWidth(),
1073                        dropdownOffset = dropdown.offset(),
1074                        screenWidth = $window.width(),
1075                        bodyRight = siteWrapper.outerWidth() + siteWrapper.offset().left,
1076                        viewportWidth = ( $('body').hasClass('wrapper-boxed') || $('body').hasClass('wrapper-boxed-small') ) ? bodyRight : screenWidth;
1077
1078                        if( ! dropdownWidth || ! dropdownOffset ) return;
1079
1080                        if( $('body').hasClass('rtl') && dropdownOffset.left <= 0 && li.hasClass( 'menu-item-design-sized' ) && ! $header.hasClass('header-vertical') ) {
1081                            // If right point is not in the viewport
1082                            var toLeft = - dropdownOffset.left;
1083
1084                            dropdown.css({
1085                                right: - toLeft - 10
1086                            });
1087
1088                            var beforeSelector = '.' + li.attr('class').split(' ').join('.') + '> .sub-menu-dropdown:before',
1089                                arrowOffset = toLeft + li.width()/2;
1090
1091                        } else if( dropdownOffset.left + dropdownWidth >= viewportWidth && li.hasClass( 'menu-item-design-sized' ) && ! $header.hasClass('header-vertical') ) {
1092                            // If right point is not in the viewport
1093                            var toRight = dropdownOffset.left + dropdownWidth - viewportWidth;
1094
1095                            dropdown.css({
1096                                left: - toRight - 10
1097                            });
1098
1099                            var beforeSelector = '.' + li.attr('class').split(' ').join('.') + '>
1099 .sub-menu-dropdown:before',
1100                                arrowOffset = toRight + li.width()/2;
1101
1102                        }
1103
1104                        // Vertical header fit
1105                        if( $header.hasClass('header-vertical') ) {
1106
1107                            var bottom = dropdown.offset().top + dropdown.outerHeight(),
1108                                viewportBottom = $window.scrollTop() + $window.outerHeight();
1109
1110                            if( bottom > viewportBottom ) {
1111                                dropdown.css({
1112                                    top: viewportBottom - bottom - 10
1113                                });
1114                            }
1115                        }
1116                };
1117
1118                lis.each(function() {
1119                    setOffset( $(this) );
1120                    $(this).addClass('with-offsets');
1121                });
1122
1123            },
1124
1125
1126            /**
1127             *-------------------------------------------------------------------------------------------------------------------------------------------
1128             * One page menu
1129             *-------------------------------------------------------------------------------------------------------------------------------------------
1130             */
1131
1132            onePageMenu: function() {
1133
1134                var scrollToRow = function(hash) {
1135                    var row = $('.vc_row#' + hash);
1136
1137                    if( row.length < 1 ) return;
1138
1139                    var position = row.offset().top;
1140
1141                    $('html, body').stop().animate({
1142                        scrollTop: position - 150
1143                    }, 800, function() {
1144                        activeMenuItem(hash);
1145                    });
1146                };
1147
1148                var activeMenuItem = function(hash) {
1149                    var itemHash;
1150                    $('.onepage-link').each(function() {
1151                        itemHash = $(this).find('> a').attr('href').split('#')[1];
1152
1153                        if( itemHash == hash ) {
1154                            $('.onepage-link').removeClass('current-menu-item');
1155                            $(this).addClass('current-menu-item');
1156                        }
1157
1158                    });
1159                };
1160
1161                $('body').on('click', '.onepage-link > a', function(e) {
1162                    var $this = $(this),
1163                        hash = $this.attr('href').split('#')[1];
1164
1165                    if( $('.gl_row#' + hash).length < 1 ) return;
1166
1167                    e.preventDefault();
1168
1169                    scrollToRow(hash);
1170
1171                    // close mobile menu
1172                    $('.basel-close-side').trigger('click');
1173                });
1174
1175                if( $('.onepage-link').length > 0 ) {
1176                    $('.entry-content > .gl_row').waypoint(function() {
1177                        var hash = $(this).attr('id');
1178                        activeMenuItem(hash);
1179                    }, { offset: 0 });
1180
1181                    $('.onepage-link').removeClass('current-menu-item');
1182
1183
1184                    // URL contains hash
1185                    var locationHash = window.location.hash.split('#')[1];
1186
1187                    if(window.location.hash.length > 1) {
1188                        setTimeout(function(){
1189                            scrollToRow(locationHash);
1190                        }, 500);
1191                    }
1192
1193                }
1194            },
1195
1196
1197            /**
1198             *-------------------------------------------------------------------------------------------------------------------------------------------
1199             * mobile responsive navigation
1200             *-------------------------------------------------------------------------------------------------------------------------------------------
1201             */
1202
1203            mobileNavigation: function() {
1204
1205                var body = $("body"),
1206                    mobileNav = $(".mobile-nav"),
1207                    wrapperSite = $(".website-wrapper"),
1208                    dropDownCat = $(".mobile-nav .site-mobile-menu .menu-item-has-children"),
1209                    elementIcon = '<span class="icon-sub-menu"></span>',
1210                    butOpener = $(".icon-sub-menu");
1211
1212                dropDownCat.append(elementIcon);
1213
1214                mobileNav.on("click", ".icon-sub-menu", function(e) {
1215                    e.preventDefault();
1216                    var el = $(this).closest( 'li' );
1217                    if ($(this).parent().hasClass("opener-page")) {
1218                        $(this).parent().removeClass("opener-page").find("> ul").slideUp(200);
1219                        $(this).parent().removeClass("opener-page").find(">
1219 .sub-menu-dropdown >.container > ul").slideUp(200);
1220                        $(this).parent().find('> .icon-sub-menu').removeClass("up-icon");
1221                    } else {
1222                        $(this).parent().addClass("opener-page").find("> ul").slideDown(200);
1223                        $(this).parent().addClass("opener-page").find(">.sub-menu-dropdown >.container > ul").slideDown(200);
1224                        $(this).parent().find('> .icon-sub-menu').addClass("up-icon");
1225                    }
1226                });
1227                body.on("click", ".mobile-nav-icon", function() {
1228
1229                    if (body.hasClass("act-mobile-menu")) {
1230                        closeMenu();
1231                    } else {
1232                        openMenu();
1233                    }
1234
1235                });
1236
1237                body.on("click touchstart", ".basel-close-side", function() {
1238                    closeMenu();
1239                });
1240
1241                function openMenu() {
1242                    body.addClass("act-mobile-menu");
1243                    wrapperSite.addClass("left-wrapp");
1244                }
1245
1246                function closeMenu() {
1247                    body.removeClass("act-mobile-menu");
1248                    wrapperSite.removeClass("left-wrapp");
1249                }
1250            },
1251
1252            /**
1253             *-------------------------------------------------------------------------------------------------------------------------------------------
1254             * Simple dropdown for category select on search form
1255             *-------------------------------------------------------------------------------------------------------------------------------------------
1256             */
1257            simpleDropdown: function() {
1258                $('.input-dropdown-inner').each(function() {
1259                    var dd = $(this);
1260                    var btn = dd.find('> a');
1261                     var input = dd.find('> input');
1262                    var list = dd.find('> ul'); //.dd-list-wrapper
1263
1264                    $(document).click(function(e) {
1265                        var target = e.target;
1266                        if (dd.hasClass('dd-shown') && !$(target).is('.input-dropdown-inner') && !$(target).parents().is('.input-dropdown-inner')) {
1267                            hideList();
1268                            return false;
1269                        }
1270                    });
1271
1272                    btn.on('click', function(e) {
1273                        e.preventDefault();
1274                        if (dd.hasClass('dd-shown')) {
1275                          hideList();
1276                        } else {
1277                          $('.input-dropdown-inner.dd-shown > ul').slideUp(100);
1278                          $('.input-dropdown-inner.dd-shown').removeClass('dd-shown');
1279                          showList();
1280                        }
1281                        return false;
1282                    });
1283
1284                    list.on('click', 'a', function(e) {
1285                        e.preventDefault();
1286                        var value = $(this).data('val');
1287                        var label = $(this).text();
1288                        list.find('.current-item').removeClass('current-item');
1289                        $(this).parent().addClass('current-item');
1290                        if (value != 0) {
1291                            list.find('li:first-child').show();
1292                        } else if (value == 0) {
1293                            list.find('li:first-child').hide();
1294                        }
1295                       var form = $(this).closest('form.has-categories-dropdown');
1296                        form.attr('action','/search/collections/'+value);
1297                        btn.text(label);
1298                        input.val(value);
1299                        hideList();
1300                    });
1301
1302                    function showList() {
1303                        dd.addClass('dd-shown');
1304                        list.slideDown(100);
1305
1306                        // $(".dd-list-wrapper .basel-scroll").nanoScroller({
1307                        //     paneClass: 'basel-scroll-pane',
1308                        //     sliderClass: 'basel-scroll-slider',
1309                        //     contentClass: 'basel-scroll-content',
1310                        //     preventPageScrolling: false
1311                        // });
1312                    }
1313
1314                    function hideList() {
1315                        dd.removeClass('dd-shown');
1316                        list.slideUp(100);
1317                    }
1318                });
1319
1320            },
1321
1322            /**
1323             *-------------------------------------------------------------------------------------------------------------------------------------------
1324             * Function to make columns the same height
1325             *-------------------------------------------------------------------------------------------------------------------------------------------
1326             */
1327            equalizeColumns: function() {
1328
1329                $.fn.basel_equlize = function(options) {
1330
1331                    var settings = $.extend({
1332                        child: "",
1333                    }, options);
1334
1335                    var that = this;
1336
1337                    if (settings.child != '') {
1338                        that = this.find(settings.child);
1339                    }
1340
1341                    var resize = function() {
1342
1343                        var maxHeight = 0;
1344                        var height;
1345                        that.each(function() {
1346                            $(this).attr('style', '');
1347                            //if ($(window).width() > 767 && $(this).outerHeight() > maxHeight)
1348                              if ($(this).outerHeight() > maxHeight)
1349                                maxHeight = $(this).outerHeight();
1350                        });
1351
1352                        that.each(function() {
1353                          $(this).css({'height': maxHeight+"px" });
1354//                             $(this).css({
1355//                                 Height: maxHeight
1356//                             });
1357                        });
1358
1359                    }
1360
1361                    $(window).bind('resize', function() {
1362                        resize();
1363                    });
1364                    setTimeout(function() {
1365                        resize();
1366                    }, 200);
1367                    setTimeout(function() {
1368                        resize();
1369                    }, 500);
1370                    setTimeout(function() {
1371                        resize();
1372                    }, 800);
1373                }
1374
1375                $('.equal-columns').each(function() {
1376                    $(this).basel_equlize({
1377                        child: ' [class*=col-] .product-element-top'
1378                    });
1379                });
1380            },
1381
1382
1383            /**
1384             *-------------------------------------------------------------------------------------------------------------------------------------------
1385             * Enable masonry grid for blog
1386             *-------------------------------------------------------------------------------------------------------------------------------------------
1387             */
1388            blogMasonry: function() {
1389                if (typeof($.fn.isotope) == 'undefined' || typeof($.fn.imagesLoaded) == 'undefined') return;
1390                var $container = $('.masonry-container');
1391
1392                // initialize Masonry after all images have loaded
1393                $container.imagesLoaded(function() {
1394                    $container.isotope({
1395                        gutter: 0,
1396                        isOriginLeft: ! $('body').hasClass('rtl'),
1397                        itemSelector: '.blog-design-masonry, .blog-design-mask, .masonry-item'
1398                    });
1399                });
1400
1401                $('.masonry-filter').on('click', 'a', function(e) {
1402                    e.preventDefault();
1403                    $('.masonry-filter').find('.filter-active').removeClass('filter-active');
1404                    $(this).addClass('filter-active');
1405                    var filterValue = $(this).attr('data-filter');
1406                    $container.isotope({
1407                        filter: filterValue
1408                    });
1409                });
1410
1411            },
1412
1413
1414            /**
1415             *-------------------------------------------------------------------------------------------------------------------------------------------
1416             * Load more button for blog shortcode
1417             *-------------------------------------------------------------------------------------------------------------------------------------------
1418             */
1419            blogLoadMore: function() {
1420
1421                $('.basel-blog-load-more').on('click', function(e) {
1422                    e.preventDefault();
1423                    var $this = $(this),
1424                        holder = $this.parent().siblings('.basel-blog-holder'),
1425                        tea_ajaxurl = $(this).attr('href');
1426
1427                    $this.addClass('loading');
1428
1429                    $.ajax({
1430                        url: tea_ajaxurl,
1431                        dataType: 'html',
1432                        type: 'GET',
1433                        success: function(data) {
1434                           //console.log(data);
1435                            data = jQuery(data);
1436                            var html = data.find('#tea_data_blog').html(),
1437                                data_status = data.find('#tea_data_arrow').attr("data-status"),
1438                                data_load_more = data.find('#tea_section_next').attr("href"),
1439                                items = $(html);
1440                                if( holder.hasClass('masonry-container') ) {
1441                                    // initialize Masonry after all images have loaded
1442                                    holder.append(items).isotope( 'appended', items );
1443                                    holder.imagesLoaded().progress(function() {
1444                                      holder.isotope('layout');
1445                                    });
1446                                } else {
1447                                    holder.append(html);
1448                                }
1449                              if( data_status == 'have-posts' ) {
1450                                   $this.attr("href", data_load_more);
1451                               } else {
1452                                   $this.hide();
1453                               }
1454                        },
1455                        error: function(data) {
1456                            console.log('ajax error');
1457                        },
1458                        complete: function() {
1459                            $this.removeClass('loading');
1460                        },
1461                    });
1462
1463                });
1464
1465            },
1466
1467
1468            /**
1469             *-------------------------------------------------------------------------------------------------------------------------------------------
1470             * Load more button for products shortcode
1471             *-------------------------------------------------------------------------------------------------------------------------------------------
1472             */
1473            productsLoadMore: function() {
1474               var process = false, intervalID;
1475                $('.basel-products-element').each(function() {
1476                    var $this = $(this),
1477                        // cache = [],
1478                        inner = $this.find('.basel-products-holder');
1479
1480                    if( ! inner.hasClass('pagination-arrows') && ! inner.hasClass('pagination-more-btn') ) return;
1481
1482                    // cache[1] = {
1483                    //     items: inner.html(),
1484                    //     status: 'have-posts'
1485                    // };
1486
1487                    $this.on('recalc', function() {
1488                        calc();
1489                    });
1490
1491                    if( inner.hasClass('pagination-arrows') ) {
1492                        $(window).resize(function() {
1493                            calc();
1494                        });
1495                    }
1496
1497                    var calc = function() {
1498                        var height = inner.outerHeight();
1499                        $this.stop().css({height: height});
1500                    };
1501
1502                    // sticky buttons
1503
1504                    var body = $('body'),
1505                        btnWrap = $this.find('.products-footer'),
1506                        btnLeft = btnWrap.find('.basel-products-load-prev'),
1507                        btnRight = btnWrap.find('.basel-products-load-next'),
1508                        loadWrapp = $this.find('.basel-products-loader'),
1509                        scrollTop,
1510                        holderTop,
1511                        btnLeftOffset,
1512                        btnRightOffset,
1513                        holderBottom,
1514                        holderHeight,
1515                        holderWidth,
1516                        btnsHeight,
1517                        offsetArrow = 50,
1518                        offset,
1519                        windowWidth;
1520
1521                    if( body.hasClass('rtl') ) {
1522                        btnLeft = btnRight;
1523                        btnRight = btnWrap.find('.basel-products-load-prev');
1524                    }
1525
1526                    $(window).scroll(function() {
1527                        buttonsPos();
1528                    });
1529
1530                    function buttonsPos() {
1531
1532                        offset = $(window).height() / 2;
1533
1534                        windowWidth = $(window).outerWidth(true) + 17;
1535
1536                        holderWidth = $this.outerWidth(true) + 10;
1537
1538                        scrollTop = $(window).scrollTop();
1539
1540                        holderTop = $this.offset().top - offset;
1541
1542                        btnLeftOffset = $this.offset().left - offsetArrow;
1543
1544                        btnRightOffset = btnLeftOffset + holderWidth + offsetArrow;
1545
1546                        btnsHeight = btnLeft.outerHeight();
1547
1548                        holderHeight = $this.height() - 50 - btnsHeight;
1549
1550                        holderBottom = holderTop + holderHeight;
1551
1552                        if(windowWidth <= 1047 && windowWidth >= 992 || windowWidth <= 825 && windowWidth >= 768 ) {
1553                            btnLeftOffset += 18;
1554                            btnRightOffset -= 18;
1555                        }
1556
1557                        if(windowWidth < 768 || body.hasClass('wrapper-boxed') || body.hasClass('wrapper-boxed-small') || $('.main-header').hasClass('header-vertical') ) {
1558                            btnLeftOffset += 51;
1559                            btnRightOffset -= 51;
1560                        }
1561
1562                        btnLeft.css({
1563                            'left' : btnLeftOffset + 'px'
1564                        });
1565
1566                        // Right arrow position for vertical header
1567                        // if( $('.main-header').hasClass('header-vertical') && ! body.hasClass('rtl') ) {
1568                        //     btnRightOffset -= $('.main-header').outerWidth();
1569                        // } else if( $('.main-header').hasClass('header-vertical') && body.hasClass('rtl') ) {
1570                        //     btnRightOffset += $('.main-header').outerWidth();
1571                        // }
1572
1573                        btnRight.css({
1574                            'left' : btnRightOffset + 'px'
1575                        });
1576
1577
1578                        if (scrollTop < holderTop || scrollTop > holderBottom) {
1579                            btnWrap.removeClass('show-arrow');
1580                            loadWrapp.addClass('hidden-loader');
1581                        } else {
1582                            btnWrap.addClass('show-arrow');
1583                            loadWrapp.removeClass('hidden-loader');
1584                        }
1585
1586                    };
1587
1588                    // $this.find('.basel-products-load-more:not(.loading)').on('click', function(e) {
1589                    //     e.preventDefault();
1590                    //     //console.log('click');
1591                    //     var $this = $(this),
1592                    //         holder = $this.parent().siblings('.basel-products-holder'),
1593                    //         tea_ajaxurl = $(this).attr('href');
1594                    //     loadProducts(holder, tea_ajaxurl, $this, function(data) {
1595                    //         data = jQuery(data);
1596                    //         var html = data.find('#te
1596a_data_products').html(),
1597                    //             data_status = data.find('#tea_data_arrow').attr("data-status"),
1598                    //             data_load_more = data.find('#tea_section_next').attr("href");
1599                    //         //console.log(data_status);
1600                    //         if( holder.hasClass('grid-masonry') ) {
1601                    //             isotopeAppend(holder, html);
1602                    //         } else {
1603                    //              holder.append(html);
1604                    //         }
1605                    //         if( data_status == 'have-posts' ) {
1606                    //             $this.attr("href", data_load_more);
1607                    //         } else {
1608                    //             $this.hide();
1609                    //         }
1610                    //     });
1611                    // });
1612
1613                    $this.find('.basel-products-load-prev, .basel-products-load-next').on('click', function(e) {
1614                        e.preventDefault();
1615                        //console.log('click');
1616                        if (process) return;
1617                        process = true;
1618                        clearInterval(intervalID);
1619
1620                        var $this = $(this),
1621                            holder = $this.parent().siblings('.basel-products-holder'),
1622                            next = $this.parent().find('.basel-products-load-next'),
1623                            prev = $this.parent().find('.basel-products-load-prev'),
1624                            tea_ajaxurl = $(this).attr('href');
1625
1626                        loadProducts(holder, tea_ajaxurl, $this, function(data) {
1627                           data = jQuery(data);
1628                           var html = data.find('#tea_data_products').html(),
1629                                tea_url_prev = data.find('#tea_section_previous').attr('href'),
1630                                tea_class_prev = data.find('#tea_section_previous').attr('class'),
1631                                tea_url_nev = data.find('#tea_section_next').attr('href'),
1632                                tea_class_nev = data.find('#tea_section_next').attr('class');
1633                               // var pagination = data.find('#tea_data_arrow').html();
1634                               holder.addClass('basel-animated-products').html( html );
1635                               prev.attr({ href: tea_url_prev, class: tea_class_prev });
1636                               next.attr({ href: tea_url_nev, class: tea_class_nev });
1637                               // arrow.html( pagination );
1638
1639                            // if( data.items ) {
1640                                // holder.html(data.items).attr('data-paged', paged);
1641                                holder.imagesLoaded().progress(function() {
1642                                    holder.parent().trigger('recalc');
1643                                    // $(window).trigger('rebuttonpos');
1644                                    // calc();
1645                                    // buttonsPos();
1646                                    // console.log('thu');
1647                                });
1648
1649                                // buttonsPos();
1650                            // }
1651
1652                            if( $(window).width() < 768 ) {
1653                                $('html, body').stop().animate({
1654                                    scrollTop: holder.offset().top - 150
1655                                }, 400);
1656                            }
1657                            var iter = 0;
1658                            intervalID = setInterval(function() {
1659                                holder.find('.product-grid-item').eq(iter).addClass('basel-animated');
1660                                iter++;
1661                            }, 100);
1662                        });
1663
1664                    });
1665                });
1666               baselThemeModule.clickOnScrollButton(baselTheme.shopLoadMoreBtn, false);
1667                  $(document).off('click', '.basel-products-load-more').on('click', '.basel-products-load-more', function(e) {
1668                  e.preventDefault();
1669                     if (process) return;
1670                     process = true;
1671                  var $this = $(this),
1672                      holder = $this.parent().siblings('.basel-products-holder'),
1673                      tea_ajaxurl = $(this).attr('href');
1674                  loadProducts(holder, tea_ajaxurl, $this, function(data) {
1675                      data = jQuery(data);
1676                      var html = data.find('#tea_data_products').html(),
1677                          result = data.find('#shopify_result_count').html(),
1678                          data_status = data.find('#tea_data_arrow').attr("data-status"),
1679                          data_load_more = data.find('#tea_section_next').attr("href");
1680                      if( holder.hasClass('grid-masonry') ) {
1681                          isotopeAppend(holder, html);
1682                      } else {
1683                           holder.append(html);
1684                      }
1685                      if ($(".shopify-result-count").length > 0) {
1686                        $('.shopify-result-count').text(result);
1687                     }
1688                      holder.imagesLoaded().progress(function() {
1689                        baselThemeModule.clickOnScrollButton(baselTheme.shopLoadMoreBtn, true);
1690                     });
1691                      if( data_status == 'have-posts' ) {
1692                          $this.attr("href", data_load_more);
1693                      } else {
1694                         $this.hide().remove();
1695                      }
1696                  });
1697               });
1698
1699                var loadProducts = function(holder, ajaxurl, btn, callback) {
1700
1701                    holder.addClass('loading').parent().addClass('element-loading');
1702
1703                    btn.addClass('loading');
1704
1705                    $.ajax({
1706                        dataType: "html",
1707                        type: 'GET',
1708                        url: ajaxurl,
1709                        success: function(data) {
1710                            callback( data );
1711                        },
1712                        error: function(data) {
1713                            console.log('ajax error');
1714                        },
1715                        complete: function() {
1716                            //countDown
1717                            baselThemeModule.countDownTimer();
1718                           //product review
1719                           baselThemeModule.gl_productreviews();
1720                           baselThemeModule.autoloadCompare();
1721                            holder.removeClass('loading').parent().removeClass('element-loading');
1722                            btn.removeClass('loading');
1723                          if (holder.hasClass('equal-columns')) {
1724                          holder.basel_equlize({
1725                              child: '> [class*=col-] .product-element-top'
1726                          });
1727                          }
1728                            //currency
1729                           baselThemeModule.gl_currency();
1730                            process = false;
1731                            // process = false;
1732                            // baselThemeModule.compare();
1733                        },
1734                    });
1735                };
1736
1737                var isotopeAppend = function(el, items) {
1738                    // initialize Masonry after all images have loaded
1739                    var items = $(items);
1740                    //console.log(items);
1741                    el.append(items).isotope( 'appended', items );
1742                    el.isotope('layout');
1743                    setTimeout(function() {
1744                        el.isotope('layout');
1745                    }, 100);
1746                    el.imagesLoaded().progress(function() {
1747                        el.isotope('layout');
1748                    });
1749                };
1750
1751            },
1752
1753             /**
1754             *-------------------------------------------------------------------------------------------------------------------------------------------
1755             * Helper function that make btn click when you scroll page to it
1756             *-------------------------------------------------------------------------------------------------------------------------------------------
1757             */
1758            clickOnScrollButton: function( btnClass, destroy ) {
1759                if( typeof $.waypoints != 'function' ) return;
1760                
1761                var $btn = $(btnClass);
1762                if( destroy ) {
1763                    $btn.waypoint('destroy');
1764                }
1765
1766                $btn.waypoint(function(){
1767                    $btn.trigger('click');
1768                }, { offset: '100%' });
1769            },
1770
1771            /**
1772             *-------------------------------------------------------------------------------------------------------------------------------------------
1773             * Products tabs element AJAX loading
1774             *-------------------------------------------------------------------------------------------------------------------------------------------
1775             */
1776            productsGalaxyTabs: function() {
1777              $("body").on("click", "ul.gl_tta-tabs-list li a, ul.tabs li a", function(b) {
1778                  b.preventDefault();
1779                  var c = $(this)
1780                    , d = c.closest(".tab-collection, .shopify-tabs")
1781                    , e = d.find("ul.gl_tta-tabs-list, ul.tabs");
1782                  e.find("li").removeClass("gl_active"),
1783                  d.find(".gl_tta-panel, .panel:not(.panel .panel)").removeClass("gl_active"),
1784                  c.closest("li").addClass("gl_active"),
1785                  d.find(c.attr("href")).addClass("gl_active")
1786              });
1787            },
1788            
1789            productsTabs: function() {
1790                //var process = false;
1791
1792                $('.basel-products-tabs').each(function() {
1793                    var $this = $(this),
1794                        $inner = $this.find('.basel-tab-content'),
1795                        $nt_ajax = $this.find('.products_nt_ajax'),
1796                        cache = [];
1797                  console.log($nt_ajax)
1798                        console.log($($nt_ajax).length)
1799                    // if( $inner.find('.owl-carousel').length < 1 ) {
1800                    //     cache[0] = {
1801                    //         html: $inner.html()
1802                    //     };
1803                    // }
1804
1805                    $this.find('.products-tabs-title li').on('click', function(e) {
1806                        e.preventDefault();
1807
1808                        var $this = $(this),
1809                            ajaxurl = $this.data('atts'),
1810                            index = $this.index();
1811
1812                        //if( process || $this.hasClass('active-tab-title') ) return; process = true;
1813
1814                        loadTab(ajaxurl, index, $inner, $this, cache,  function(data) {
1815                            // if( data.html ) {
1816                            //     $inner.html(data.html);
1817                            //     // baselThemeModule.btnsToolTips();
1818                            //     baselThemeModule.shopMasonry();
1819                            //     baselThemeModule.productsLoadMore();
1820                            // }
1821                            //data = jQuery(data);
1822                            $inner.html(data);
1823                            baselThemeModule.shopMasonry();
1824                            baselThemeModule.productsLoadMore();
1825                        });
1826
1827                    });
1828
1829                    var $nav = $this.find('.tabs-navigation-wrapper'),
1830                        $subList = $nav.find('ul'),
1831                        time = 300;
1832
1833                    $nav.on('click', '.open-title-menu', function() {
1834                        var $btn = $(this);
1835
1836                        if( $subList.hasClass('list-shown') ) {
1837                            $btn.removeClass('toggle-active');
1838                            $subList.removeClass('list-shown');
1839                        } else {
1840                            $btn.addClass('toggle-active');
1841                            $subList.addClass('list-shown');
1842                            setTimeout(function() {
1843                                $('body').one('click', function(e) {
1844                                    var target = e.target;
1845                                    if ( ! $(target).is('.tabs-navigation-wrapper') && ! $(target).parents().is('.tabs-navigation-wrapper')) {
1846                                        $btn.removeClass('toggle-active');
1847                                        $subList.removeClass('list-shown');
1848                                        return false;
1849                                    }
1850                                });
1851                            },10);
1852                        }
1853
1854                    })
1855                    .on('click', 'li', function() {
1856                        var $btn = $nav.find('.open-title-menu'),
1857                            text = $(this).text();
1858
1859                        if( $subList.hasClass('list-shown') ) {
1860                            $btn.removeClass('toggle-active').text(text);
1861                            $subList.removeClass('list-shown');
1862                        }
1863                    });
1864
1865                });
1866
1867                var loadTab = function(ajaxurl, index, holder, btn, cache, callback) {
1868
1869                    btn.parent().find('.active-tab-title').removeClass('active-tab-title');
1870                    btn.addClass('active-tab-title')
1871
1872                    // if( cache[index] ) {
1873                    //     holder.addClass('loading');
1874                    //     setTimeout(function() {
1875                    //         callback(cache[index]);
1876                    //         holder.removeClass('loading');
1877                    //         process = false;
1878                    //     }, 300);
1879                    //     return;
1880                    // }
1881
1882                    holder.addClass('loading').parent().addClass('element-loading');
1883
1884                    btn.addClass('loading');
1885
1886                    $.ajax({
1887                        dataType: "html",
1888                        type: 'GET',
1889                        url: ajaxurl,
1890                        success: function(data) {
1891                            //cache[index] = data;
1892                            callback( data );
1893                        },
1894                        error: function(data) {
1895                            console.log('ajax error');
1896                        },
1897                        complete: function() {
1898                            //process = false;
1899                          if ($('.products_nt_ajax').hasClass('equal-columns')) {
1900                          $('.products_nt_ajax.equal-columns').basel_equlize({
1901                              child: ' [class*=col-] .product-element-top'
1902                          });
1903                          }
1904                            //countDown
1905                            baselThemeModule.countDownTimer();
1906                           //product review
1907                           baselThemeModule.gl_productreviews();
1908                           baselThemeModule.autoloadCompare();
1909                          holder.removeClass('loading').parent().removeClass('element-loading');
1910                            btn.removeClass('loading');
1911                           baselThemeModule.gl_currency();
1912                        },
1913                    });
1914                };
1915            },
1916
1917
1918            /**
1919             *-------------------------------------------------------------------------------------------------------------------------------------------
1920             * Load more button for portfolio shortcode
1921             *-------------------------------------------------------------------------------------------------------------------------------------------
1922             */
1923            // portfolioLoadMore: function() {
1924
1925            //     if( typeof $.waypoints != 'function' ) return;
1926
1927            //     var waypoint = $('.basel-portfolio-load-more.load-on-scroll').waypoint(function(){
1928            //             $('.basel-portfolio-load-more.load-on-scroll').trigger('click');
1929            //         }, { offset: '100%' }),
1930            //         process = false;
1931
1932            //     $('.basel-portfolio-load-more').on('click', function(e) {
1933            //         e.preventDefault();
1934
1935            //         if( process ) return;
1936
1937            //         process = true;
1938
1939            //         var $this = $(this),
1940            //             holder = $this.parent().parent().find('.basel-portfolio-holder'),
1941            //             source = holder.data('source'),
1942            //             action = 'basel_get_portfolio_' + source,
1943            //             ajaxurl = theme.ajaxurl,
1944            //             dataType = 'json',
1945            //             method = 'POST',
1946            //             timeout,
1947            //             atts = holder.data('atts'),
1948            //             paged = holder.data('paged');
1949
1950            //         $this.addClass('loading');
1951
1952            //         var data = {
1953            //             atts: atts,
1954            //             paged: paged,
1955            //             action: action
1956            //         };
1957
1958            //         if( source == 'main_loop' ) {
1959            //             ajaxurl = $(this).attr('href');
1960            //             method = 'GET';
1961            //             data = {};
1962            //         }
1963
1964
1965            //         $.ajax({
1966            //             url: ajaxurl,
1967            //             data: data,
1968            //             dataType: dataType,
1969            //             method: method,
1970            //             success: function(data) {
1971
1972            //                 var items = $(data.items);
1973
1974            //                 if( items ) {
1975            //                     if( holder.hasClass('masonry-container') ) {
1976            //                         // initialize Masonry after all images have loaded
1977            //                         holder.append(items).isotope( 'appended', items );
1978            //                         holder.imagesLoaded().progress(function() {
1979            //                             holder.isotope('layout');
1980
1981            //                             clearTimeout(timeout);
1982
1983            //                             timeout = setTimeout(function() {
1984            //                                 $('.basel-portfolio-load-more.load-on-scroll').waypoint('destroy');
1985            //                                 waypoint = $('.basel-portfolio-load-more.load-on-scroll').waypoint(function(){
1986            //                                     $('.basel-portfolio-load-more.load-on-scroll').trigger('click');
1987            //                                 }, { offset: '100%' });
1988            //                             }, 1000);
1989            //                         });
1990            //                     } else {
1991            //                         holder.append(items);
1992            //                     }
1993
1994            //                     holder.data('paged', paged + 1);
1995
1996            //                     $this.attr('href', data.nextPage);
1997            //                 }
1998
1999            //                 baselThemeModule.mfpPopup();
2000
2001            //                 if( data.status == 'no-more-posts' ) {
2002            //                     $this.hide();
2003            //                 }
2004
2005            //             },
2006            //             error: function(data) {
2007            //                 console.log('ajax error');
2008            //             },
2009            //             complete: function() {
2010            //                 $this.removeClass('loading');
2011            //                 process = false;
2012            //             },
2013            //         });
2014
2015            //     });
2016
2017            // },
2018
2019            /**
2020             *-------------------------------------------------------------------------------------------------------------------------------------------
2021             * Enable masonry grid for shop isotope type
2022             *-------------------------------------------------------------------------------------------------------------------------------------------
2023             */
2024            shopMasonry: function() {
2025                if (typeof($.fn.isotope) == 'undefined' || typeof($.fn.imagesLoaded) == 'undefined') return;
2026                var $container = $('.elements-grid.grid-masonry');
2027                // initialize Masonry after all images have loaded
2028                $container.imagesLoaded(function() {
2029                    $container.isotope({
2030                        isOriginLeft: ! $('body').hasClass('rtl'),
2031                        itemSelector: '.category-grid-item, .product-grid-item',
2032                    });
2033                });
2034
2035                // Categories masonry
2036                $(window).resize(function() {
2037                    $(".categories-masonry").each(function (index) {
2038                        var $catsContainer = $(this);
2039                        var colWidth = ( $catsContainer.hasClass( 'categories-style-masonry' ) )  ? '.category-grid-item' : '.col-md-3.category-grid-item' ;
2040                        $catsContainer.imagesLoaded(function() {
2041                            $catsContainer.isotope({
2042                                resizable: false,
2043                                isOriginLeft: ! $('body').hasClass('rtl'),
2044                                layoutMode: 'packery',
2045                                packery: {
2046                                    gutter: 0,
2047                                    columnWidth: colWidth
2048                                },
2049                                itemSelector: '.category-grid-item',
2050                                // masonry: {
2051                                    // gutter: 0
2052                                // }
2053                            });
2054                        });
2055                    });
2056                });
2057
2058            },
2059
2060            collectionMasonry: function() {
2061                if (typeof($.fn.isotope) == 'undefined' || typeof($.fn.imagesLoaded) == 'undefined') return;
2062                var $container = $('.elements-grid.grid-masonry');
2063                // initialize Masonry after all images have loaded
2064                $container.imagesLoaded(function() {
2065                    $container.isotope({
2066                        isOriginLeft: ! $('body').hasClass('rtl'),
2067                        itemSelector: '.category-grid-item, .product-grid-item',
2068                        layoutMode: 'fitRows',
2069                    });
2070                });
2071            },
2072            // Categories carousel
2073            shopcarousel: function() {
2074               if (typeof($.fn.owlCarousel) == 'undefined' || typeof($.fn.imagesLoaded) == 'undefined') return;
2075               $(".gl_carousel_data").each(function (index) {
2076                  var items_no = $(this).data('items'),
2077                     nav = $(this).data('nav'),
2078                     dots = $(this).data('dots'),
2079                     medium = $(this).data('medium'),
2080                       small = $(this).data('small'),
2081                     time = $(this).data('time'),
2082                     loop = $(this).data('loop'),
2083                     autoplay = $(this).data('autoplay'),
2084                     autoheight = $(this).data('autoheight');
2085                  var options = {
2086                        rtl: $('body').hasClass('rtl'),
2087                        items: items_no, 
2088                        responsive: {
2089                           979: { items: items_no },
2090                           768: { items: 3 },
2091                           479: { items: 3 },
2092                           0: { items: typeof small == 'undefined' ? 1:small }
2093                        },
2094                        autoplay: autoplay,
2095                        autoplayTimeout: time,
2096                        dots: dots,
2097                        nav: nav,
2098                        autoHeight: typeof autoheight == 'undefined' ? false:autoheight,
2099                        slideBy:  'page',
2100                        navText:false,
2101                        loop: loop,
2102                        onRefreshed: function() {
2103                           $(window).resize();
2104                        }
2105                  };
2106                  $(this).owlCarousel(options);
2107               });
2108            },
2109
2110            instagram: function() {
2111              $(".gl_instagram").each(function (index) {
2112                var user_name = $(this).data('username'),
2113                     limit = $(this).data('limit'),
2114                     target = $(this).data('target'),
2115                     img_size = $(this).data('size'),
2116                     ul_ins = $(this).find(".instagram-pics");
2117                    $.ajax({
2118                      url: 'https://api.teathemes.net/instagram?username='+user_name,
2119                      dataType: 'json',
2120                      type: 'GET',
2121                      success: function(responsive) {
2122                        //console.log(responsive);
2123                        var html = '',
2124                            img_url = null,
2125                            data = responsive.entry_data.ProfilePage[0].user.media.nodes;
2126                        $.each(data,function(index,element){
2127                          if(index >= limit ) return 0;
2128                          var img_url_150 = element.thumbnail_resources[0].src,
2129                            img_url_240 = element.thumbnail_resources[1].src,
2130                            img_url_320 = element.thumbnail_resources[2].src,
2131                            img_url_480 = element.thumbnail_resources[3].src,
2132                            img_url_640 = element.thumbnail_resources[4].src;
2133                          html += '<li><a href="//instagram.com/p/'+element.code+'" target="'+target+'"></a><div class="wrapp-pics"><img src="'+img_url_150+'" data-src="'+img_url_150+'" data-sizes="auto" data-srcset="'+img_url_150+' 150w,'+img_url_240+' 240w,'+img_url_320+' 320w,'+img_url_480+' 480w,'+img_url_640+' 640w" class="w__100 lazyload" alt="'+user_name+'"><div class="jas-wrap-lazy"></div><div class="hover-mask"></div></div></li>';
2134                        
2135                        });
2136                        ul_ins.html(html);
2137                      },
2138                      error: function(data) {
2139                        console.log('ajax error');
2140                      },
2141                      complete: function() {
2142                        baselThemeModule.inscarousel();
2143                      }
2144                    }); 
2145              });
2146            },
2147
2148            inscarousel: function() {
2149               if (typeof($.fn.owlCarousel) == 'undefined' || typeof($.fn.imagesLoaded) == 'undefined') return;
2150               $(".ins-owl-carousel").each(function (index) {
2151                  var items_no = $(this).data('items'),
2152                     nav = $(this).data('nav'),
2153                     dots = $(this).data('dots'),
2154                     medium = $(this).data('medium'),
2155                     small = $(this).data('small'),
2156                     ex_small = $(this).data('exsmall'),
2157                     time = $(this).data('time'),
2158                     loop = $(this).data('loop'),
2159                     autoplay = $(this).data('autoplay');
2160                  var options = {
2161                        rtl: $('body').hasClass('rtl'),
2162                        items: items_no, 
2163                        responsive: {
2164                           979: { items: items_no },
2165                           768: { items: medium },
2166                           479: { items: small },
2167                           0: { items: ex_small  }
2168                        },
2169                        autoplay: autoplay,
2170                        autoplayTimeout: time,
2171                        dots: dots,
2172                        nav: nav,
2173                        autoHeight: true,
2174                        slideBy:  'page',
2175                        navText:false,
2176                        loop: loop,
2177                        onRefreshed: function() {
2178                           $(window).resize();
2179                        }
2180                  };
2181                  //$(this).addClass('owl-carousel');
2182                  $(this).owlCarousel(options);
2183               });
2184            },
2185
2186            /**
2187             *-------------------------------------------------------------------------------------------------------------------------------------------
2188             * MEGA MENU
2189             *-------------------------------------------------------------------------------------------------------------------------------------------
2190             */
2191            sidebarMenu: function() {
2192                var heightMegaMenu = $(".widget_nav_mega_menu").height();
2193                var heightMegaNavigation = $(".categories-menu-dropdown").height();
2194                var subMenuHeight = $(".widget_nav_mega_menu ul > li.menu-item-design-sized >
2194 .sub-menu-dropdown, .widget_nav_mega_menu ul > li.menu-item-design-full-width > .sub-menu-dropdown");
2195                var megaNavigationHeight = $(".categories-menu-dropdown ul > li.menu-item-design-sized > .sub-menu-dropdown, .categories-menu-dropdown ul > li.menu-item-design-full-width > .sub-menu-dropdown");
2196                subMenuHeight.css(
2197                    "min-height", heightMegaMenu + "px"
2198                );
2199
2200                megaNavigationHeight.css(
2201                    "min-height", heightMegaNavigation + "px"
2202                );
2203            },
2204
2205
2206            /**
2207             *-------------------------------------------------------------------------------------------------------------------------------------------
2208             * Product thumbnail images & photo swipe gallery
2209             *-------------------------------------------------------------------------------------------------------------------------------------------
2210             */
2211            productImages: function() {
2212
2213
2214                // Init photoswipe
2215
2216                var currentImage,
2217                    $productGallery = $('.shopify-product-gallery'),
2218                    $mainImages = $('.shopify-product-gallery__wrapper'),
2219                    $thumbs = $productGallery.find('.thumbnails'),
2220                    currentClass = 'current-image',
2221                    gallery = $('.photoswipe-images'),
2222                    PhotoSwipeTrigger = '.basel-show-product-gallery',
2223                    galleryType = 'photo-swipe'; // magnific photo-swipe
2224
2225                $thumbs.addClass('thumbnails-ready');
2226
2227                if( $productGallery.hasClass( 'image-action-popup') ) {
2228                    PhotoSwipeTrigger += ', .shopify-product-gallery__image a';
2229                }
2230
2231                $productGallery.on('click', '.shopify-product-gallery__image a', function(e) {
2232                    e.preventDefault();
2233                });
2234
2235                $productGallery.on('click', PhotoSwipeTrigger, function(e) {
2236                    e.preventDefault();
2237
2238                    currentImage = $(this).attr('href');
2239
2240                    if( galleryType == 'magnific' ) {
2241                        $.magnificPopup.open({
2242                            type: 'image',
2243                            image: {
2244                                verticalFit: false
2245                            },
2246                            items: getProductItems(),
2247                            gallery: {
2248                                enabled: true,
2249                                navigateByImgClick: false
2250                            },
2251                        }, 0);
2252                    }
2253
2254                    if( galleryType == 'photo-swipe' ) {
2255
2256                        // build items array
2257                        var items = getProductItems();
2258
2259                        callPhotoSwipe( getCurrentGalleryIndex(e), items );
2260
2261                    }
2262
2263                });
2264
2265                $thumbs.on('click', '.image-link', function(e) {
2266                    e.preventDefault();
2267
2268                    // if( $thumbs.hasClass('thumbnails-large') ) {
2269                    //     var index = $(e.currentTarget).index() + 1;
2270                    //     var items = getProductItems();
2271                    //     callPhotoSwipe(index, items);
2272                    //     return;
2273                    // }
2274
2275                    // var href = $(this).attr('href'),
2276                    //     src  = $(this).attr('data-single-image'),
2277                    //     width = $(this).attr('data-width'),
2278                    //     height = $(this).attr('data-height'),
2279                    //     title = $(this).attr('title');
2280
2281                    // $thumbs.find('.' + currentClass).removeClass(currentClass);
2282                    // $(this).addClass(currentClass);
2283
2284                    // if( $mainImages.find('img').attr('src') == src ) return;
2285
2286                    // $mainImages.addClass('loading-image').attr('href', href).find('img').attr('src', src).attr('srcset', src).one('load', function() {
2287                    //     $mainImages.removeClass('loading-image').data('width', width).data('height', height).attr('title', title);
2288                    // });
2289
2290                });
2291
2292                gallery.each(function() {
2293                    var $this = $(this);
2294                    $this.on('click', 'a', function(e) {
2295                        e.preventDefault();
2296                        var index = $(e.currentTarget).data('index') - 1;
2297                        var items = getGalleryItems($this, []);
2298                        callPhotoSwipe(index, items);
2299                    } );
2300                })
2301
2302                var callPhotoSwipe = function( index, items ) {
2303                    var pswpElement = document.querySelectorAll('.pswp')[0];
2304
2305                    if( $('body').hasClass('rtl') ) {
2306                        index = items.length - index - 1;
2307                        items = items.reverse();
2308                    }
2309
2310                    // define options (if needed)
2311                    var options = {
2312                        // optionName: 'option value'
2313                        // for example:
2314                        index: index, // start at first slide
2315                        getThumbBoundsFn: function(index) {
2316
2317                            // // get window scroll Y
2318                            // var pageYScroll = window.pageYOffset || document.documentElement.scrollTop;
2319                            // // optionally get horizontal scroll
2320
2321                            // // get position of element relative to viewport
2322                            // var rect = $target.offset();
2323
2324                            // // w = width
2325                            // return {x:rect.left, y:rect.top + pageYScroll, w:rect.width};
2326
2327                        }
2328                    };
2329
2330                    // Initializes and opens PhotoSwipe
2331                    var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
2332                    gallery.init();
2333                };
2334
2335                var getCurrentGalleryIndex = function( e ) {
2336                    if( $mainImages.hasClass('owl-carousel') )
2337                        return $mainImages.find('.owl-item.active').index();
2338                    else return $(e.currentTarget).parent().index();
2339                };
2340
2341                var getProductItems = function() {
2342                    var items = [];
2343
2344                    $mainImages.find('figure a img').each(function() {
2345                        var src = $(this).data('large_image'),
2346                            width = $(this).data('large_image_width'),
2347                            height = $(this).data('large_image_height'),
2348                            title = $(this).attr('title');
2349                            //console.log(src);
2350                            items.push({
2351                                src: src,
2352                                w: width,
2353                                h: height,
2354                                title: ( theme.product_images_captions == 'yes' ) ? title : false
2355                            });
2356
2357                    });
2358                    return items;
2359                };
2360
2361                var getGalleryItems = function( $gallery, items ) {
2362                    var src, width, height, title;
2363
2364                    $gallery.find('a').each(function() {
2365                        src = $(this).attr('href');
2366                        width = $(this).data('width');
2367                        height = $(this).data('height');
2368                        title = $(this).attr('title');
2369                        if( ! isItemInArray(items, src) ) {
2370                            items.push({
2371                                src: src,
2372                                w: width,
2373                                h: height,
2374                                title: title
2375                            });
2376                        }
2377                    });
2378                     console.log(items);
2379                    return items;
2380                };
2381
2382                var isItemInArray = function( items, src ) {
2383                    var i;
2384                    for (i = 0; i < items.length; i++) {
2385                        if (items[i].src == src) {
2386                            return true;
2387                        }
2388                    }
2389
2390                    return false;
2391                };
2392
2393                /* Fix zoom for first item firstly */
2394
2395                if( $productGallery.hasClass( 'image-action-zoom') ) {
2396                    var zoom_target   = $( '.shopify-product-gallery__image img' );
2397                    var image_to_zoom = zoom_target.find( 'img' );
2398
2399                    // But only zoom if the img is larger than its container.
2400                    zoom_target.each(function() {
2401                      var $this = $(this);
2402                      if ( $this.attr( 'data-large_image_width' ) > $( '.shopify-product-gallery__image' ).width() ) {
2403                        $this.trigger( 'zoom.destroy' );
2404                        var zoom_parent = $this.closest('.shopify-product-gallery__image')
2405                        zoom_parent.zoom({
2406                          url: $this.attr( 'data-large_image' ), 
2407                          touch: false
2408                        });
2409                      }
2410                    });
2411                }
2412
2413            },
2414
2415            productImagesGallery: function() {
2416
2417
2418                var $mainImages = $('.shopify-product-gallery__image:eq(0) img'),
2419                    $thumbs = $('.images .thumbnails'), // magnific photo-swipe
2420                    $mainOwl;
2421
2422                if( theme.product_gallery.images_slider ) {
2423                    initMainGallery();
2424                }
2425
2426                if( theme.product_gallery.thumbs_slider.enabled && theme.product_gallery.images_slider ) {
2427                    initThumbnailsMarkup();
2428                    if( theme.product_gallery.thumbs_slider.position == 'left' && jQuery(window).width() > 991 ) {
2429                        initThumbnailsVertical();
2430                    } else {
2431                        initThumbnailsHorizontal();
2432                    }
2433                }
2434                function initMainGallery() {
2435                    $('.shopify-product-gallery__wrapper').addClass('owl-carousel').owlCarousel({
2436                        rtl: $('body').hasClass('rtl'),
2437                        items: 1,
2438                        autoplay: false,
2439                        dots: false,
2440                        nav: false,
2441                        autoheight: true,
2442                        navText:false,
2443                        loop: false,
2444                        animateOut: 'fadeOut',
2445                        onRefreshed: function() {
2446                            $(window).resize();
2447                        }
2448                    });
2449
2450                    $mainOwl = $('.shopify-product-gallery__wrapper').owlCarousel();
2451                };
2452
2453                function initThumbnailsMarkup() {
2454                    var markup = '';
2455
2456                    $('.shopify-product-gallery__image').each(function() {
2457                        if( $(this).data('variant_id') != undefined && $(this).data('lenght') != undefined ) {
2458                           markup += '<img data-variant_id="' + $(this).data('variant_id') + '" data-lenght="' + $(this).data('lenght') + '" data-one="' + $(this).data('one') + '" data-two="' + $(this).data('two') + '" data-three="' + $(this).data('three') + '" src="' + $(this).data('thumb') + '" alt="' + $(this).data('alt') + '" data-image-id="' + $(this).data('id') + '"  />';
2459                        } else {
2460                           markup += '<img src="' + $(this).data('thumb') + '" alt="' + $(this).data('alt') + '" data-image-id="' + $(this).data('id') + '"  />';
2461                        }
2462                    });
2463
2464                    $thumbs.append(markup);
2465
2466                };
2467
2468                function initThumbnailsVertical() {
2469                    $thumbs.slick({
2470                        slidesToShow: theme.product_gallery.thumbs_slider.items.vertical_items,
2471                        slidesToScroll: theme.product_gallery.thumbs_slider.items.vertical_items,
2472                        vertical: true,
2473                        verticalSwiping: true,
2474                        infinite: false,
2475                    });
2476                    $thumbs.on('click', 'img', function(e) {
2477                        var i = $(this).index();
2478                        console.log(i);
2479                        $mainOwl.trigger('to.owl.carousel', i);
2480                    });
2481
2482                    $mainOwl.on('changed.owl.carousel', function(e) {
2483                        var i = e.item.index;
2484                        $thumbs.slick('slickGoTo', i);
2485                        $thumbs.find('.active-thumb').removeClass('active-thumb');
2486                        $thumbs.find('img').eq(i).addClass('active-thumb');
2487                    });
2488                    $thumbs.find("img").eq(0).addClass("active-thumb");
2489                };
2490
2491                function initThumbnailsHorizontal() {
2492                    $thumbs.addClass('owl-carousel').owlCarousel({
2493                        rtl: $('body').hasClass('rtl'),
2494                        items: theme.product_gallery.thumbs_slider.items.desktop,
2495                        responsive: {
2496                            979: {
2497                                items: theme.product_gallery.thumbs_slider.items.desktop
2498                            },
2499                            768: {
2500                                items: theme.product_gallery.thumbs_slider.items.desktop_small
2501                            },
2502                            479: {
2503                                items: theme.product_gallery.thumbs_slider.items.tablet
2504                            },
2505                            0: {
2506                                items: theme.product_gallery.thumbs_slider.items.mobile
2507                            }
2508                        },
2509                        dots:false,
2510                        nav: true,
2511                        // mouseDrag: false,
2512                        navText: false,
2513                    });
2514                    var $thumbsOwl = $thumbs.owlCarousel();
2515
2516                    $thumbs.on('click', '.owl-item', function(e) {
2517                        var i = $(this).index();
2518                        $thumbsOwl.trigger('to.owl.carousel', i);
2519                        $mainOwl.trigger('to.owl.carousel', i);
2520                    });
2521
2522                    $mainOwl.on('changed.owl.carousel', function(e) {
2523                        var i = e.item.index;
2524                        $thumbsOwl.trigger('to.owl.carousel', i);
2525                        $thumbs.find('.active-thumb').removeClass('active-thumb');
2526                        $thumbs.find('.owl-item').eq(i).addClass('active-thumb');
2527                    });
2528                    $thumbs.find(".owl-item").eq(0).addClass("active-thumb");
2529                };
2530
2531                // Update first thumbnail on variation change
2532
2533            },
2534
2535
2536            /**
2537             *-------------------------------------------------------------------------------------------------------------------------------------------
2538             * Sticky details block for special product type
2539             *-------------------------------------------------------------------------------------------------------------------------------------------
2540             */
2541            stickyDetails: function() {
2542                if( ! $('body').hasClass('basel-product-design-sticky') || ! $('body').hasClass('template-product')) return;
2543                 if ($( window ).width() <=768) {
2544                    var topOffset = 90;
2545                 } else {
2546                    var topOffset = 130;
2547                 }
2548                var details = $('.entry-summary'),
2549                    detailsInner = details.find('.summary-inner'),
2550                    detailsWidth = details.width(),
2551                    images = $('.product-images'),
2552                    thumbnails = images.find('.shopify-product-gallery__wrapper a'),
2553                    offsetThumbnils,
2554                    viewportHeight = $(window).height(),
2555                    imagesHeight = images.outerHeight(),
2556                    maxWidth = 600,
2557                    innerWidth,
2558                    detailsHeight = details.outerHeight(),
2559                    scrollTop = $(window).scrollTop(),
2560                    imagesTop =  images.offset().top,
2561                    detailsLeft =  details.offset().left + 15,
2562                    imagesBottom = imagesTop + imagesHeight;
2563                    if ($( window ).width() <=768) {
2564                       var detailsBottom = 350 + scrollTop + topOffset + detailsHeight;
2565                    } else {
2566                       var detailsBottom = scrollTop + topOffset + detailsHeight;
2567                    }
2568                details.css({
2569                    height: detailsHeight
2570                });
2571
2572                $(window).resize(function() {
2573                    recalculate();
2574                });
2575
2576                $(window).scroll(function() {
2577                    console.log('111');
2578                    onscroll();
2579                    animateThumbnails();
2580                });
2581
2582                images.imagesLoaded(function() {
2583                    recalculate();
2584                });
2585                function animateThumbnails() {
2586                    viewportHeight = $(window).height();
2587                    thumbnails.each(function(){
2588                        offsetThumbnils = $(this).offset().top;
2589                        if(scrollTop > (offsetThumbnils - viewportHeight + 20)) {
2590                            console.log(offsetThumbnils);
2591                           $(this).addClass('animate-images');
2592                        }
2593
2594                    });
2595                }
2596
2597                function onscroll() {
2598                    scrollTop = $(window).scrollTop();
2599                    detailsBottom = scrollTop + topOffset + detailsHeight;
2600                    detailsWidth = details.width();
2601                    detailsLeft =  details.offset().left + 15;
2602                    imagesTop =  images.offset().top;
2603                    imagesBottom = imagesTop + imagesHeight;
2604
2605                    if (detailsWidth > maxWidth) {
2606                        innerWidth = (detailsWidth - maxWidth) / 2;
2607                        detailsLeft = detailsLeft + innerWidth;
2608                    }
2609
2610                    // Fix after scroll the header
2611                    if( scrollTop + topOffset >= imagesTop ) {
2612                        details.addClass('block-sticked');
2613
2614                        detailsInner.css({
2615                            top: topOffset,
2616                            left: detailsLeft,
2617                            width: detailsWidth,
2618                            position: 'fixed',
2619                            transform:'translateY(-20px)'
2620                        });
2621                    } else {
2622                        details.removeClass('block-sticked');
2623                        detailsInner.css({
2624                            top: 'auto',
2625                            left: 'auto',
2626                            width: 'auto',
2627                            position: 'relative',
2628                            transform:'translateY(0px)'
2629                        });
2630                    }
2631
2632
2633
2634                    // When rich the bottom line
2635                    if( detailsBottom > imagesBottom ) {
2636                        details.addClass('hide-temporary');
2637                    } else {
2638                        details.removeClass('hide-temporary');
2639                    }
2640                };
2641
2642
2643                function recalculate() {
2644                    viewportHeight = $(window).height();
2645                    detailsHeight = details.outerHeight();
2646                    imagesHeight = images.outerHeight();
2647
2648                    // If enought space in the viewport
2649                    if( detailsHeight < ( viewportHeight - topOffset ) ) {
2650                        details.addClass('in-viewport').removeClass('not-in-viewport');
2651                    } else {
2652                        details.removeClass('in-viewport').addClass('not-in-viewport');
2653                    }
2654                    onscroll();
2655                        animateThumbnails();
2656                };
2657
2658            },
2659
2660
2661            /**
2662             *-------------------------------------------------------------------------------------------------------------------------------------------
2663             * Use magnific popup for images
2664             *-------------------------------------------------------------------------------------------------------------------------------------------
2665             */
2666            mfpPopup: function() {
2667                /*$('.image-link').magnificPopup({
2668                    type:'image'
2669                });*/
2670
2671                $('.gallery').magnificPopup({
2672                    delegate: ' > a',
2673                    type: 'image',
2674                    image: {
2675                        verticalFit: true
2676                    },
2677                    gallery: {
2678                        enabled: true,
2679                        navigateByImgClick: true
2680                    },
2681                });
2682
2683                $('[data-rel="mfp"]').magnificPopup({
2684                    type: 'image',
2685                    image: {
2686                        verticalFit: true
2687                    },
2688                    gallery: {
2689                        enabled: false,
2690                        navigateByImgClick: false
2691                    },
2692                });
2693
2694                $('[data-rel="mfp[projects-gallery]"]').magnificPopup({
2695                    type: 'image',
2696                    image: {
2697                        verticalFit: true
2698                    },
2699                    gallery: {
2700                        enabled: true,
2701                        navigateByImgClick: false
2702                    },
2703                });
2704
2705                if ($('.jas-magnific-image').length > 0) {
2706                  $('.jas-magnific-image').magnificPopup({
2707                     type: 'image',
2708                     tLoading: '<div class="loader"><div class="loader-inner"></div></div>',
2709                     removalDelay: 500,
2710                     callbacks: {
2711                        beforeOpen: function() {
2712                           this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
2713                           this.st.mainClass = this.st.el.attr('data-effect');
2714                        }
2715                     }
2716                  });
2717                }
2718
2719                $(document).on('click', '.mfp-img', function() {
2720                    var mfp = jQuery.magnificPopup.instance; // get instance
2721                    mfp.st.image.verticalFit = !mfp.st.image.verticalFit; // toggle verticalFit on and off
2722                    mfp.currItem.img.removeAttr('style'); // remove style attribute, to remove max-width if it was applied
2723                    mfp.updateSize(); // force update of size
2724                });
2725            },
2726
2727
2728            /**
2729             *-------------------------------------------------------------------------------------------------------------------------------------------
2730             * shopify adding to cart
2731             *-------------------------------------------------------------------------------------------------------------------------------------------
2732             */
2733            addToCart: function() {
2734              var timeoutNumber = 0;
2735              if( theme.add_to_cart_action == 'popup' ) {
2736                  var html = [
2737                      '<div class="added-to-cart">',
2738                          '<p>' + theme.strings.added_to_cart + '</p>',
2739                          '<a href="#" class="btn btn-style-link close-popup">' + theme.strings.continue_shopping + '</a>',
2740                          '<a href="/cart" class="btn btn-color-primary view-cart">' + theme.strings.view_cart + '</a>',
2741                      '</div>',
2742                  ].join("");
2743                  $.magnificPopup.open({
2744                      callbacks: {
2745                          beforeOpen: function() {
2746                              this.st.mainClass = baselTheme.popupEffect + '  cart-popup-wrapper';
2747                          },
2748                      },
2749                      items: {
2750                          src: '<div class="white-popup add-to-cart-popup popup-added_to_cart">' + html + '</div>',
2751                          type: 'inline'
2752                      }
2753                  });
2754
2755                  $('.white-popup').on('click', '.close-popup', function(e) {
2756                      e.preventDefault();
2757                      $.magnificPopup.close();
2758                  });
2759
2760              } else if( theme.add_to_cart_action == 'widget' ) {
2761                  
2762                  clearTimeout(timeoutNumber);
2763                  if( $('.cart-widget-opener a').length > 0 ) {
2764                        if( $('body').hasClass('open_gl_quick_view') ) {
2765                           $.magnificPopup.close();
2766                        }
2767                      $('.cart-widget-opener a').trigger('click');
2768                  } else if( $('.shopping-cart a').length > 0 ) {
2769                     $('.shopping-cart .dropdown-wrap-cat').addClass('display-widget');
2770                     console.log('aa');
2771                     if( $('body').hasClass('open_gl_quick_view') ) {
2772                        $.magnificPopup.close();
2773                     }
2774                     if ($(window).scrollTop() > 100 && $('body').hasClass('enable-sticky-header') == false ){
2775                        $('html, body').animate({
2776                           scrollTop: 0
2777                        }, 1000);
2778                     }
2779                     timeoutNumber = setTimeout(function() {
2780                        $('.display-widget').removeClass('display-widget');
2781                     }, 3500 );
2782
2783                  } else {
2784                     console.log('bb');
2785                     $('.main-header .dropdown-wrap-cat').addClass('display-widget');
2786                     if( $('body').hasClass('open_gl_quick_view') ) {
2787                        $.magnificPopup.close();
2788                     }
2789                     if ($(window).scrollTop() > 100 && $('body').hasClass('enable-sticky-header') == false ) {
2790                        $('html, body').animate({
2791                           scrollTop: 0
2792                        }, 1000);
2793                     }
2794                      timeoutNumber = setTimeout(function() {
2795                          $('.display-widget').removeClass('display-widget');
2796                      }, 3500 );
2797                  }
2798              }
2799               if( $('body').hasClass('open_gl_quick_view') ) {
2800                  $('body').removeClass('open_gl_quick_view');
2801               }
2802            },
2803
2804            // Login before using wishlist
2805            loginWishlist: function() {
2806               if( theme.basel_settings.wishlist == 'no' ) return;
2807               var body = $("body");
2808               body.on('click', '.nitro_wishlist_login', function(event) {
2809                  event.preventDefault();
2810                  var $this = $(this);
2811                  $this.parent().addClass("feid-in");
2812                  var html = [
2813                      '<div class="added-to-cart">',
2814                          '<p>' + theme.strings.info_wishlist + '</p>',
2815                          '<a href="#" class="btn btn-style-link close-popup">' + theme.strings.continue_shopping + '</a>',
2816                          '<a href="/account/login" class="btn btn-color-primary view-cart">' + theme.strings.login + '</a>',
2817                      '</div>',
2818                  ].join("");
2819                  // Append new quantity selector then remove original
2820                  $.magnificPopup.open({
2821                      callbacks: {
2822                          beforeOpen: function() {
2823                              this.st.mainClass = baselTheme.popupEffect + '  cart-popup-wrapper';
2824                          },
2825                           close: function() {
2826                            $this.parent().removeClass("feid-in");
2827                           }
2828                      },
2829                      items: {
2830                          src: '<div id="login-wishlist" class="gl_login-wishlist white-popup add-to-cart-popup popup-added_to_cart">' + html + '</div>',
2831                          type: 'inline'
2832                      }
2833                  });
2834
2835                  $('.gl_login-wishlist').on('click', '.close-popup', function(e) {
2836                      e.preventDefault();
2837                      $.magnificPopup.close();
2838                  });
2839                }); 
2840            },
2841            /**
2842             *-------------------------------------------------------------------------------------------------------------------------------------------
2843             * add class in wishlist
2844             *-------------------------------------------------------------------------------------------------------------------------------------------
2845             */
2846
2847            wishList: function() {
2848               if( theme.basel_settings.wishlist == 'no' ) return;
2849                var body = $("body");
2850                body.on("click", ".gl_add_wishlist > a", function(event) {
2851                  event.preventDefault();
2852                  var $this = $(this),
2853                     holder = $this.closest('.yith-wcwl-add-to-wis
2853hlist'),
2854                     pr_this = holder.find('.gl_add_wishlist'),
2855                     load = holder.find('.gl_adding_wishlist'),
2856                     added = holder.find('.gl_addedbrowse_wishlist');
2857                  pr_this.hide();
2858                  load.show();
2859                  $.ajax({
2860                     url: 'https://nitro-wishlist.teathemes.net?shop='+ Shopify.shop,
2861                     type: 'POST',
2862                     cache: true,
2863                     data: $this.data(),
2864                     success: function(data,status) {
2865                        try{
2866                           data = $.parseJSON(data);
2867                        }
2868                        catch(ex){
2869                           //console.log(ex);
2870                        }
2871                        if(data.status == 'success' && status == 'success')
2872                        {
2873                           added.show();
2874                           load.hide();
2875                           pr_this.hide();
2876                           $('.gl_count_wishlist').html(function(i, val) { return val*1+1 });
2877                        }else{
2878                           load.hide();
2879                           pr_this.show();
2880                           console.log('Error: '+data.message);
2881                        }
2882                     },
2883                     error: function(data) {
2884                        load.hide();
2885                        pr_this.show();
2886                        if(data.status==404) {
2887                           alert('This feature is not available because there is no  Nitro Wishlist app installed. Please install Nitro Wishlist app first  when using Wishlist in Shop.');
2888                        } else {
2889                           console.log('Error: '+data.message);
2890                        }
2891                     },
2892                 });
2893               });
2894            },
2895            // Remove wishlist
2896             removeWishlist: function() {
2897               if( theme.basel_settings.wishlist == 'no' ) return;
2898               var body = $("body");
2899               body.on("click", ".remove_from_wishlist", function(event) {
2900                  event.preventDefault();
2901                  var $this = $(this),
2902                     value = $(this).data('id');
2903                  $.ajax({
2904                    url: 'https://nitro-wishlist.teathemes.net?shop='+ Shopify.shop,
2905                    type: 'POST',
2906                     data: $this.data(),
2907                     beforeSend: function(data){
2908                       $.blockUI({
2909                          message: null,
2910                          css: {
2911                            backgroundColor: '#fff',
2912                            opacity: 0.6
2913                          }
2914                        });
2915                     },
2916                     success: function(data,status) {
2917                        try{
2918                           data = $.parseJSON(data);
2919                        }
2920                        catch(ex){
2921                           //console.log(ex);
2922                        }
2923                        if(data.status == 'success' && status == 'success') {
2924                           $('.gl_count_wishlist').html(function(i, val) { return val*1-1 });
2925                           $("#yith-wcwl-row-" + value).remove();
2926                           var rowCount = $('.wishlist_table > tbody > tr').length;
2927                           if (rowCount < 1) {
2928                               $('.wishlist_table tbody').empty();
2929                               $('.wishlist_table tbody').append('<tr><td colspan="6" class="wishlist-empty">'+ theme.strings.nowishlist +'</td>');
2930                           } 
2931                        } else {
2932                           console.log('Error: '+data.message);
2933                        }
2934                     },
2935                     error: function(data) {
2936                        $( '.loader' ).remove();
2937                        console.log('Error: '+data.message);
2938                     },
2939                     complete: function() {
2940                        setTimeout(function() {
2941                          $.unblockUI();
2942                        }, 200);
2943                     }
2944                  });
2945               });
2946            }, 
2947
2948            /**
2949             *-------------------------------------------------------------------------------------------------------------------------------------------
2950             * Side shopping cart widget
2951             *-------------------------------------------------------------------------------------------------------------------------------------------
2952             */
2953            cartWidget: function() {
2954                var widget = $('.cart-widget-opener'),
2955                    btn = widget.find('a'),
2956                    body = $('body');
2957
2958                widget.on('click', 'a', function(e) {
2959                    e.preventDefault();
2960
2961                    if( isOpened() ) {
2962                        closeWidget();
2963                    } else {
2964                        setTimeout( function() {
2965                            openWidget();
2966                        }, 10);
2967                    }
2968
2969                });
2970
2971                body.on("click touchstart", ".basel-close-side", function() {
2972                    if( isOpened() ) {
2973                        closeWidget();
2974                    }
2975                });
2976
2977                body.on("click", ".widget-close", function( e ) {
2978                    e.preventDefault();
2979                    if( isOpened() ) {
2980                        closeWidget();
2981                    }
2982                });
2983
2984                var closeWidget = function() {
2985                    $('.website-wrapper').removeClass('basel-wrapper-shifted');
2986                    $('body').removeClass('basel-cart-opened');
2987                };
2988
2989                var openWidget = function() {
2990                    $('.website-wrapper').addClass('basel-wrapper-shifted');
2991                    $('body').addClass('basel-cart-opened');
2992
2993                };
2994
2995                var isOpened = function() {
2996                    return $('body').hasClass('basel-cart-opened');
2997                };
2998            },
2999
3000            /**
3001             *-------------------------------------------------------------------------------------------------------------------------------------------
3002             * Banner hover effect with jquery panr
3003             *-------------------------------------------------------------------------------------------------------------------------------------------
3004             */
3005            bannersHover: function() {
3006                $(".promo-banner.hover-4").panr({
3007                    sensitivity: 20,
3008                    scale: false,
3009                    scaleOnHover: true,
3010                    scaleTo: 1.15,
3011                    scaleDuration: .34,
3012                    panY: true,
3013                    panX: true,
3014                    panDuration: 0.5,
3015                    resetPanOnMouseLeave: true
3016                });
3017            },
3018
3019            /**
3020             *-------------------------------------------------------------------------------------------------------------------------------------------
3021             * Parallax effect
3022             *-------------------------------------------------------------------------------------------------------------------------------------------
3023             */
3024            parallax: function() {
3025                $('.parallax-yes').each(function() {
3026                    var $bgobj = $(this);
3027                    $(window).scroll(function() {
3028                        var yPos = -($(window).scrollTop() / $bgobj.data('speed'));
3029                        var coords = 'center ' + yPos + 'px';
3030                        $bgobj.css({
3031                            backgroundPosition: coords
3032                        });
3033                    });
3034                });
3035
3036                $('.basel-parallax').each(function(){
3037                    var $this = $(this);
3038                    if($this.hasClass('spb_column')) {
3039                        $this.find('> .gl_column-inner').parallax("50%", 0.3);
3040                    } else {
3041                        $this.parallax("50%", 0.3);
3042                    }
3043                });
3044
3045            },
3046
3047            fullWidthRow: function() {
3048               var $elements = $('[data-sp-full-width="true"]');
3049               $.each($elements, function(key, item) {
3050                   var $el = $(this);
3051                   $el.addClass("sp_hidden");
3052                   var $el_full = $el.next(".sp_row-full-width");
3053                   if ($el_full.length || ($el_full = $el.parent().next(".sp_row-full-width")), $el_full.length) {
3054                       var el_margin_left = parseInt($el.css("margin-left"), 10),
3055                           el_margin_right = parseInt($el.css("margin-right"), 10),
3056                           offset = 0 - $el_full.offset().left - el_margin_left,
3057                           width = $(window).width();
3058                       if ($el.css({
3059                               position: "relative",
3060                               left: offset,
3061                               "box-sizing": "border-box",
3062                               width: $(window).width()
3063                           }), !$el.data("spStretchContent")) {
3064                           var padding = -1 * offset;
3065                           0 > padding && (padding = 0);
3066                           var paddingRight = width - padding - $el_full.width() + el_margin_left + el_margin_right;
3067                           0 > paddingRight && (paddingRight = 0), $el.css({
3068                               "padding-left": padding + "px",
3069                               "padding-right": paddingRight + "px"
3070                           })
3071                       }
3072                       $el.attr("data-sp-full-width-init", "true"), $el.removeClass("sp_hidden"), $(document).trigger("sp-full-width-row-single", {
3073                           el: $el,
3074                           offset: offset,
3075                           marginLeft: el_margin_left,
3076                           marginRight: el_margin_right,
3077                           elFull: $el_full,
3078                           width: width
3079                       })
3080                   }
3081               }), $(document).trigger("sp-full-width-row", $elements)
3082           },
3083
3084
3085            /**
3086             *-------------------------------------------------------------------------------------------------------------------------------------------
3087             * Scroll top button
3088             *-------------------------------------------------------------------------------------------------------------------------------------------
3089             */
3090            scrollTop: function() {
3091                //Check to see if the window is top if not then dis
3091play button
3092                $(window).scroll(function() {
3093                    if ($(this).scrollTop() > 100) {
3094                        $('.scrollToTop').addClass('button-show');
3095                    } else {
3096                        $('.scrollToTop').removeClass('button-show');
3097                    }
3098                });
3099
3100                //Click event to scroll to top
3101                $('.scrollToTop').click(function() {
3102                    $('html, body').animate({
3103                        scrollTop: 0
3104                    }, 800);
3105                    return false;
3106                });
3107            },
3108
3109
3110            /**
3111             *-------------------------------------------------------------------------------------------------------------------------------------------
3112             * Quick View
3113             *-------------------------------------------------------------------------------------------------------------------------------------------
3114             */
3115            quickViewInit: function() {
3116                var that = this;
3117                // Open popup with product info when click on Quick View button
3118                $(document).on('click', '.open-quick-view', function(e) {
3119                    e.preventDefault();
3120                    var url_quick = $(this).attr('data-get'),
3121                        btn = $(this);
3122                    btn.addClass('loading');
3123                    $('body').addClass('open_gl_quick_view')
3124                    that.quickViewLoad(url_quick,btn);
3125                });
3126            },
3127
3128            quickViewLoad: function(url,btn) {
3129                $.ajax({
3130                    url: url,
3131                    dataType: 'html',
3132                    type: 'GET',
3133                    success: function(data) {
3134                        // Open directly via API
3135                        $.magnificPopup.open({
3136                            items: {
3137                                src: '<div class="mfp-with-anim white-popup popup-quick-view" id="content_quickview">' + data + '</div>', // can be a HTML string, jQuery object, or CSS selector
3138                                type: 'inline'
3139                            },
3140                            removalDelay: 500, //delay removal by X to allow out-animation
3141                            callbacks: {
3142                                beforeOpen: function() {
3143                                    this.st.mainClass = baselTheme.popupEffect;
3144                                },
3145                                open: function() {
3146                                    $('.product-images-slider_on').addClass('owl-carousel').owlCarousel({
3147                                       rtl: jQuery('body').hasClass('rtl'),
3148                                       items: 1, 
3149                                       dots:false,
3150                                       nav: true,
3151                                       animateOut: 'fadeOut',
3152                                       navText: false
3153                                     });
3154                                    baselThemeModule.countDownTimer(); //countDown
3155                                    baselThemeModule.gl_currency(); //currency
3156                                    baselThemeModule.autoloadCompare();
3157                                    setTimeout(function() {
3158                                          baselThemeModule.nanoScroller();
3159                                    }, 300);
3160                                    baselThemeModule.simpleDropdown();
3161                                     //product review
3162                                     if ($(".shopify-product-reviews-badge").length > 0 && theme.gl_productreviews ) {
3163                                        return window.SPR.registerCallbacks(), window.SPR.initRatingHandler(), window.SPR.initDomEls(), window.SPR.loadProducts(), window.SPR.loadBadges();
3164                                     }
3165                                },
3166                                close: function() {
3167                                  $( '#content_quickview' ).empty();
3168                              }
3169                            },
3170                        });
3171                    },
3172                    complete: function() {
3173                        btn.removeClass('loading');
3174                    },
3175                    error: function() {
3176                      console.log('Quick view error');
3177                    },
3178                });
3179            },
3180
3181
3182            /**
3183             *-------------------------------------------------------------------------------------------------------------------------------------------
3184             * Quick Shop
3185             *-------------------------------------------------------------------------------------------------------------------------------------------
3186             */
3187
3188            quickShop: function() {
3189
3190                var btnSelector = '.btn-quick-shop';
3191
3192                $(document).on('click', btnSelector, function( e ) {
3193                    e.preventDefault();
3194
3195                    var $this = $(this),
3196                        $product = $this.parents('.product'),
3197                        $content = $product.find('.quick-shop-form'),
3198                        ajaxurl = $(this).attr('data-get'),
3199                        loadingClass = 'btn-loading';
3200                    if( $this.hasClass(loadingClass) ) return;
3201
3202
3203                    // Simply show quick shop form if it is already loaded with AJAX previously
3204                    if( $product.hasClass('quick-shop-loaded') ) {
3205                        $product.addClass('quick-shop-shown');
3206                        return;
3207                    }
3208
3209                    $this.addClass(loadingClass);
3210                    $product.addClass('loading-quick-shop');
3211
3212                    $.ajax({
3213                        url: ajaxurl,
3214                        dataType: 'html',
3215                        type: 'GET',
3216                        success: function(data) {
3217
3218                            // insert variations form
3219                            $content.append(data);
3220                            if( theme.basel_settings.enable_variant_simple == 'yes' ){ baselThemeModule.simpleDropdown();}
3221                            baselThemeModule.gl_currency();
3222                            // $( '.variations_form' ).each( function() {
3223                            //     $( this ).wc_variation_form().find('.variations select:eq(0)').change();
3224                            // });
3225                            // $('.variations_form').trigger('wc_variation_form');
3226                            //$('body').trigger('basel-quick-view-displayed');
3227                            //baselThemeModule.swatchesVariations();
3228                            // baselThemeModule.btnsToolTips();
3229
3230                        },
3231                        complete: function() {
3232                            $this.removeClass(loadingClass);
3233                            $product.removeClass('loading-quick-shop');
3234                            $product.addClass('quick-shop-shown quick-shop-loaded');
3235                        },
3236                        error: function() {
3237                          console.log('Quick Shop error');
3238                        },
3239                    });
3240
3241                })
3242
3243                .on('click', '.quick-shop-close', function() {
3244                    var $this = $(this),
3245                        $product = $this.parents('.product'),
3246                        $content = $product.find('.quick-shop-form');
3247                    // $product.removeClass('quick-shop-shown');
3248                    $product.removeClass('quick-shop-shown quick-shop-loaded');
3249                    $content.html('');
3250
3251                });
3252            },
3253
3254            /**
3255             *-------------------------------------------------------------------------------------------------------------------------------------------
3256             * ToolTips titles
3257             *-------------------------------------------------------------------------------------------------------------------------------------------
3258             */
3259            // btnsToolTips: function() {
3260
3261            //     $('.basel-tooltip, .product-actions-btns > a, .product-grid-item .add_to_cart_button, .quick-view a, .product-compare-button a, .product-grid-item .yith-wcwl-add-to-wis
3261hlist a').each(function() {
3262            //         $(this).find('.basel-tooltip-label').remove();
3263            //         $(this).addClass('basel-tooltip').prepend('<span class="basel-tooltip-label">' + $(this).text() +'</span>');
3264            //     });
3265
3266            // },
3267
3268            /**
3269             *-------------------------------------------------------------------------------------------------------------------------------------------
3270             * Sticky footer: margin bottom for main wrapper
3271             *-------------------------------------------------------------------------------------------------------------------------------------------
3272             */
3273            stickyFooter: function() {
3274
3275                if( ! $('body').hasClass( 'sticky-footer-on' ) || $(window).width() < 991 ) return;
3276
3277                var $footer = $('.footer-container'),
3278                    $footerContent = $footer.find('.main-footer, .copyrights-wrapper .container'),
3279                    footerHeight = $footer.outerHeight(),
3280                    $page = $('.main-page-wrapper'),
3281                    $doc = $(document),
3282                    $window = $(window),
3283                    docHeight = $doc.outerHeight(),
3284                    windowHeight = $window.outerHeight(),
3285                    position,
3286                    bottomSpace,
3287                    opacity;
3288
3289                var footerOffset = function() {
3290                    $page.css({
3291                        marginBottom: $footer.outerHeight()
3292                    })
3293                };
3294
3295                var footerEffect = function() {
3296                    position        = $doc.scrollTop();
3297                    docHeight       = $doc.outerHeight();
3298                    windowHeight    = $window.outerHeight();
3299                    bottomSpace     = ( docHeight - (position + windowHeight) );
3300                    footerHeight    = $footer.outerHeight();
3301                    opacity         = parseFloat( (bottomSpace ) / footerHeight).toFixed(5);
3302
3303                    $footer.removeClass('footer-act-sticky');
3304                    // If scrolled to footer
3305                    if( bottomSpace > footerHeight ) return;
3306
3307                    $footerContent.css({
3308                        opacity: (1 - opacity)
3309                    });
3310
3311                    $footer.addClass('footer-act-sticky');
3312
3313                };
3314
3315                $window.on('resize', footerOffset);
3316                $window.on('scroll', footerEffect);
3317
3318                $footer.imagesLoaded(function() {
3319                    footerOffset();
3320                });
3321
3322            },
3323            swatchesOnGrid: function() {
3324
3325                $('body').on('click', '.swatch-on-grid:not(.current-swatch)', function() {
3326
3327                    var src, srcset, image_sizes;
3328
3329                    var imageSrc = $(this).data('image-src'),
3330                        imageSrcset = $(this).data('image-srcset'),
3331                        imageSizes = $(this).data('image-sizes');
3332
3333                    if( typeof imageSrc == 'undefined' ) return;
3334
3335                    var product = $(this).parents('.product-grid-item'),
3336                        image = product.find('img').first(),
3337                        srcOrig = image.data('original-src'),
3338                        srcsetOrig = image.data('original-srcset'),
3339                        sizesOrig = image.data('original-sizes');
3340
3341                    if( typeof srcOrig == 'undefined' ) {
3342                        image.data('original-src', image.attr('src'));
3343                    }
3344
3345                    if( typeof srcsetOrig == 'undefined' ) {
3346                        image.data('original-srcset', image.attr('srcset'));
3347                    }
3348
3349                    if( typeof sizesOrig == 'undefined' ) {
3350                        image.data('original-sizes', image.attr('sizes'));
3351                    }
3352
3353
3354                    if( $(this).hasClass('current-swatch') ) {
3355                        src = srcOrig;
3356                        srcset = srcsetOrig;
3357                        image_sizes = sizesOrig;
3358                        $(this).removeClass('current-swatch');
3359                        product.removeClass('product-swatched');
3360                    } else {
3361                        $(this).parent().find('.current-swatch').removeClass('current-swatch');
3362                        $(this).addClass('current-swatch');
3363                        product.addClass('product-swatched');
3364                        src = imageSrc;
3365                        srcset = imageSrcset;
3366                        image_sizes = imageSizes;
3367                    }
3368
3369                    if( image.attr('src') == src ) return;
3370
3371                    product.addClass('loading-image');
3372
3373                    image.attr('src', src).attr('srcset', srcset).attr('sizes', image_sizes).one('load', function() {
3374                        product.removeClass('loading-image');
3375                    });
3376
3377                });
3378
3379            },
3380
3381
3382            /**
3383             *-------------------------------------------------------------------------------------------------------------------------------------------
3384             * Ajax filters
3385             *-------------------------------------------------------------------------------------------------------------------------------------------
3386             */
3387            ajaxFilters: function() {
3388                if( ! $('body').hasClass('basel-ajax-shop-on') ) return;
3389
3390                var that = this,
3391                    products = $('.products');
3392
3393                $('body').on('click', '.shopify-pagination a', function(e) {
3394                    scrollToTop();
3395                });
3396
3397                $(document).pjax(baselTheme.ajaxLinks, '.main-page-wrapper', {
3398                    timeout: 5000,
3399                    fragment: '.main-page-wrapper',
3400                    scrollTo: false
3401                });
3402
3403
3404                $( document ).on( 'change', 'select.orderby', function() {
3405                    var form = $( '.shopify-ordering'),
3406                        valueSelected = $(this).find(':selected').data('value');
3407                    $.pjax({
3408                        container: '.main-page-wrapper',
3409                        timeout: 4000,
3410                        url: valueSelected,
3411                        fragment: '.main-page-wrapper',
3412                        scrollTo: false
3413                    });
3414
3415                   // return false;
3416                });
3417                // $('.shopify-ordering' ).on( 'change', 'select.orderby', function() {
3418                //     //$( this ).closest( 'form' ).find('[name="_pjax"]').remove();
3419                //   $( this ).closest( 'form' ).submit();
3420                // });
3421
3422                $(document).on('pjax:error', function(xhr, textStatus, error, options) {
3423                    console.log('pjax error ' + error);
3424                });
3425
3426                $(document).on('pjax:start', function(xhr, options) {
3427                    $('body').addClass('basel-loading');
3428                });
3429
3430                $(document).on('pjax:complete', function(xhr, textStatus, options) {
3431                    // var color_curent = $('.gl_color_filter li.with-swatch-color.chosen:first').data('filter');
3432                    // console.log(color_curent);
3433                    // if (color_curent != undefined ) { 
3434                    //   $('.swatches-on-grid:not(.current-swatch) .bg_'+color_curent).trigger('click');
3435                    // }
3436                    if ($('#shopify-section-promo_banner_collection .promo-banner').length > 0) {
3437                     that.bannersHover();
3438                    }
3439                    that.gl_currency();
3440                    that.countDownTimer();
3441                    that.shopPageInit();
3442                    scrollToTop();
3443                    that.gl_productreviews();
3444                    $('body').removeClass('basel-loading');
3445
3446                });
3447
3448                $(document).on('pjax:end', function(xhr, textStatus, options) {
3449
3450                    $('body').removeClass('basel-loading');
3451
3452                });
3453
3454                var scrollToTop = function() {
3455                    var scrollTo = $('.main-page-wrapper').offset().top - 100;
3456
3457                    $('html, body').stop().animate({
3458                        scrollTop: scrollTo
3459                    }, 400);
3460                };
3461
3462            },
3463
3464            /**
3465             *-------------------------------------------------------------------------------------------------------------------------------------------
3466             * init shop page JS functions
3467             *-------------------------------------------------------------------------------------------------------------------------------------------
3468             */
3469            shopPageInit: function() {
3470                // $('.shopify-ordering' ).on( 'change', 'select.orderby', function() {
3471                //     //$( this ).closest( 'form' ).find('[name="_pjax"]').remove();
3472                //   $( this ).closest( 'form' ).submit();
3473                // });
3474                this.shopMasonry();
3475                //this.filtersArea();
3476                this.categorysearch();
3477                //this.productHover();
3478                this.ajaxSearch();
3479                this.compare();
3480                this.autoloadCompare();
3481                //this.filterDropdowns();
3482                this.categoriesMenuBtns();
3483                this.categoriesAccordion();
3484                //this.shopifyPriceSlider();
3485                this.nanoScroller();
3486                 baselThemeModule.clickOnScrollButton( baselTheme.shopLoadMoreBtn , false );
3487                // $('.shopify-ordering' ).on( 'change', 'select.orderby', function() {
3488                //     //$( this ).closest( 'form' ).find('[name="_pjax"]').remove();
3489                //   $( this ).closest( 'form' ).submit();
3490                // });
3491            },
3492
3493            /**
3494             *-------------------------------------------------------------------------------------------------------------------------------------------
3495             * Add filters dropdowns compatibility
3496             *-------------------------------------------------------------------------------------------------------------------------------------------
3497             */
3498            // filterDropdowns: function() {
3499
3500            //     $('.basel-shopify-layered-nav').on('change', 'select', function() {
3501            //         var slug = $( this ).val();
3502
3503            //         var href = $(this).data('filter-url').replace('BASEL_FILTER_VALUE', slug);
3504
3505            //         $(this).siblings('.filter-pseudo-link').attr('href', href);
3506
3507            //          var event;
3508            //          var pseudoLink = $(this).siblings('.filter-pseudo-link');
3509
3510            //          //This is true only for IE,firefox
3511            //          if(document.createEvent){
3512            //          // To create a mouse event , first we need to create an event and then initialize it.
3513            //             event = document.createEvent("MouseEvent");
3514            //             event.initMouseEvent("click",true,true,window,0,0,0,0,0,false,false,false,false,0,null);
3515            //          }
3516            //          else{
3517            //             event = new MouseEvent('click', {
3518            //                 'view': window,
3519            //                 'bubbles': true,
3520            //                 'cancelable': true
3521            //             });
3522            //          }
3523
3524            //          pseudoLink[0].dispatchEvent(event);
3525            //     });
3526            //  },
3527
3528
3529            /**
3530             *-------------------------------------------------------------------------------------------------------------------------------------------
3531             * Back in history
3532             *-------------------------------------------------------------------------------------------------------------------------------------------
3533             */
3534            backHistory: function() {
3535                history.go(-1);
3536
3537                setTimeout(function(){
3538                    $('.filters-area').removeClass('filters-opened').stop().hide();
3539                    $('.open-filters').removeClass('btn-opened');
3540                    if( $(window).width() < 992 ) {
3541                        $('.basel-product-categories').removeClass('categories-opened').stop().hide();
3542                        $('.basel-show-categories').removeClass('button-open');
3543                    }
3544                }, 20);
3545
3546
3547            },
3548
3549            /**
3550             *-------------------------------------------------------------------------------------------------------------------------------------------
3551             * Categories menu for mobile
3552             *-------------------------------------------------------------------------------------------------------------------------------------------
3553             */
3554            categoriesMenu: function() {
3555                if( $(window).width() > 991 ) return;
3556
3557                var categories = $('.basel-product-categories'),
3558                    subCategories = categories.find('li > ul'),
3559                    button = $('.basel-show-categories'),
3560                    time = 200;
3561
3562
3563                //this.categoriesMenuBtns();
3564
3565                $('body').on('click','.icon-drop-category', function(){
3566                    if($(this).parent().find('> ul').hasClass('child-open')){
3567                        $(this).removeClass("basel-act-icon").parent().find('> ul').slideUp(time).removeClass('child-open');
3568                    }else {
3569                        $(this).addClass("basel-act-icon").parent().find('> ul').slideDown(time).addClass('child-open');
3570                    }
3571                });
3572
3573                $('body').on('click', '.basel-show-categories', function(e) {
3574                    e.preventDefault();
3575
3576                    console.log('close click');
3577
3578                    if( isOpened() ) {
3579                        closeCats();
3580                    } else {
3581                        //setTimeout(function() {
3582                            openCats();
3583                        //}, 50);
3584                    }
3585                });
3586
3587                $('body').on('click', '.basel-product-categories a', function(e) {
3588                    closeCats();
3589                    categories.stop().attr('style', '');
3590                });
3591
3592                var isOpened = function() {
3593                    return $('.basel-product-categories').hasClass('categories-opened');
3594                };
3595
3596                var openCats = function() {
3597                    $('.basel-product-categories').addClass('categories-opened').stop().slideDown(time);
3598                    $('.basel-show-categories').addClass('button-open');
3599
3600                };
3601
3602                var closeCats = function() {
3603                    $('.basel-product-categories').removeClass('categories-opened').stop().slideUp(time);
3604                    $('.basel-show-categories').removeClass('button-open');
3605                };
3606            },
3607
3608
3609            categoriesMenuBtns: function() {
3610                if( $(window).width() > 991 ) return;
3611
3612                var categories = $('.basel-product-categories'),
3613                    subCategories = categories.find('li > ul'),
3614                    iconDropdown = '<span class="icon-drop-category"></span>';
3615
3616                categories.addClass('responsive-cateogires');
3617                subCategories.parent().addClass('has-sub').prepend(iconDropdown);
3618            },
3619
3620
3621            /**
3622             *-------------------------------------------------------------------------------------------------------------------------------------------
3623             * Categories toggle accordion
3624             *-------------------------------------------------------------------------------------------------------------------------------------------
3625             */
3626
3627            categoriesAccordion: function() {
3628                if( theme.categories_toggle == 'no' ) return;
3629
3630                var $widget = $('.widget_product_categories'),
3631                    $list = $widget.find('.product-categories'),
3632                    $openBtn = $('<div class="basel-cats-toggle" />'),
3633                    time = 300;
3634
3635                $list.find('.cat-parent').append( $openBtn );
3636
3637                $list.on('click', '.basel-cats-toggle', function() {
3638                    var $btn = $(this),
3639                        $subList = $btn.prev();
3640
3641                    if( $subList.hasClass('list-shown') ) {
3642                        $btn.removeClass('toggle-active');
3643                        $subList.stop().slideUp(time).removeClass('list-shown');
3644                    } else {
3645                        $subList.parent().parent().find('> li >
3645 .list-shown').slideUp().removeClass('list-shown');
3646                        $subList.parent().parent().find('> li > .toggle-active').removeClass('toggle-active');
3647                        $btn.addClass('toggle-active');
3648                        $subList.stop().slideDown(time).addClass('list-shown');
3649                    }
3650                });
3651
3652                if( $list.find(' > li.current-cat.cat-parent, > li.current-cat-parent').length > 0 ) {
3653                    $list.find(' > li.current-cat.cat-parent, > li.current-cat-parent').find('> .basel-cats-toggle').click();
3654                }
3655
3656            },
3657
3658
3659            /**
3660             *-------------------------------------------------------------------------------------------------------------------------------------------
3661             * shopify price filter slider with ajax
3662             *-------------------------------------------------------------------------------------------------------------------------------------------
3663             */
3664
3665            // shopifyPriceSlider: function() {
3666
3667            //     // shopify_price_slider_params is required to continue, ensure the object exists
3668            //     if ( typeof shopify_price_slider_params === 'undefined' || $( '.price_slider_amount #min_price' ).length < 1 || ! $.fn.slider ) {
3669            //         return false;
3670            //     }
3671
3672            //     // Get markup ready for slider
3673            //     $( 'input#min_price, input#max_price' ).hide();
3674            //     $( '.price_slider, .price_label' ).show();
3675
3676            //     // Price slider uses jquery ui
3677            //     var min_price = $( '.price_slider_amount #min_price' ).data( 'min' ),
3678            //         max_price = $( '.price_slider_amount #max_price' ).data( 'max' ),
3679            //         current_min_price = parseInt( min_price, 10 ),
3680            //         current_max_price = parseInt( max_price, 10 );
3681
3682            //     if ( $('.products').attr('data-min_price') && $('.products').attr('data-min_price').length > 0 ) {
3683            //         current_min_price = parseInt( $('.products').attr('data-min_price'), 10 );
3684            //     }
3685            //     if ( $('.products').attr('data-max_price') && $('.products').attr('data-max_price').length > 0 ) {
3686            //         current_max_price = parseInt( $('.products').attr('data-max_price'), 10 );
3687            //     }
3688
3689            //     $( '.price_slider' ).slider({
3690            //         range: true,
3691            //         animate: true,
3692            //         min: min_price,
3693            //         max: max_price,
3694            //         values: [ current_min_price, current_max_price ],
3695            //         create: function() {
3696
3697            //             $( '.price_slider_amount #min_price' ).val( current_min_price );
3698            //             $( '.price_slider_amount #max_price' ).val( current_max_price );
3699
3700            //             $( document.body ).trigger( 'price_slider_create', [ current_min_price, current_max_price ] );
3701            //         },
3702            //         slide: function( event, ui ) {
3703
3704            //             $( 'input#min_price' ).val( ui.values[0] );
3705            //             $( 'input#max_price' ).val( ui.values[1] );
3706
3707            //             $( document.body ).trigger( 'price_slider_slide', [ ui.values[0], ui.values[1] ] );
3708            //         },
3709            //         change: function( event, ui ) {
3710
3711            //             $( document.body ).trigger( 'price_slider_change', [ ui.values[0], ui.values[1] ] );
3712            //         }
3713            //     });
3714
3715            //     setTimeout(function() {
3716            //         $( document.body ).trigger( 'price_slider_create', [ current_min_price, current_max_price ] );
3717            //     }, 10);
3718            // },
3719
3720
3721            /**
3722             *-------------------------------------------------------------------------------------------------------------------------------------------
3723             * Filters area
3724             *-------------------------------------------------------------------------------------------------------------------------------------------
3725             */
3726            filtersArea: function() {
3727                var filters = $('.filters-area'),
3728                    btn = $('.open-filters'),
3729                    time = 200;
3730
3731                $('body').on('click', '.open-filters', function(e) {
3732                    e.preventDefault();
3733
3734                    if( isOpened() ) {
3735                        closeFilters();
3736                    } else {
3737                        openFilters();
3738                    }
3739
3740                });
3741
3742                $('body').on('click', baselTheme.ajaxLinks, function() {
3743                    if( isOpened() ) {
3744                        closeFilters();
3745                    }
3746                });
3747
3748                var isOpened = function() {
3749                    filters = $('.filters-area')
3750                    return filters.hasClass('filters-opened');
3751                };
3752
3753                var closeFilters = function() {
3754                    filters = $('.filters-area')
3755                    filters.removeClass('filters-opened');
3756                    filters.stop().slideUp(time);
3757                    $('.open-filters').removeClass('btn-opened');
3758                };
3759
3760                var openFilters = function() {
3761                    filters = $('.filters-area')
3762                    filters.addClass('filters-opened');
3763                    filters.stop().slideDown(time);
3764                    $('.open-filters').addClass('btn-opened');
3765                    setTimeout(function() {
3766                        baselThemeModule.nanoScroller();
3767                    }, time);
3768                };
3769            },
3770
3771            /**
3772             *-------------------------------------------------------------------------------------------------------------------------------------------
3773             * Ajax Search for products
3774             *-------------------------------------------------------------------------------------------------------------------------------------------
3775             */
3776             ajaxSearch: function() {
3777               if( theme.basel_settings.ajax_search == 'no' || theme.basel_settings.header_search_category == 'yes' ) return;
3778               var currentAjaxRequest = null,
3779                  search_form = $('form.basel-ajax-search');
3780               search_form.each(function() {
3781                  var input = $(this).find('input[name="q"]');
3782                  input.attr('autocomplete', 'off').bind('keyup', function() {
3783                    $('.autocomplete-suggestions').html('').hide();
3784                     var term = $(this).val(),
3785                        form = $(this).closest('form');
3786                     if (term.trim() == '') {
3787                         $('.autocomplete-suggestions').hide();
3788                     }else{
3789                        if( theme.basel_settings.ajax_search_product == 'yes' ) {
3790                           var searchURL = '/search?type=product&q=' + term;
3791                        } else {
3792                           var searchURL = '/search?q=' + term;
3793                        }
3794                        form.addClass('search-loading');
3795                        if (currentAjaxRequest != null) currentAjaxRequest.abort();
3796                        currentAjaxRequest = jQuery.get(searchURL + '&view=json', function(data) {
3797                           $('.autocomplete-suggestions').html(data);
3798                           setTimeout(function() {
3799                             form.removeClass('search-loading');    
3800                           }, 300);   
3801                        });
3802                       setTimeout(function() {
3803                         baselThemeModule.gl_currency();
3804                         $('.autocomplete-suggestions').show();    
3805                       }, 1500); 
3806                     }
3807                  });
3808               });
3809               $('body').bind('click', function(){
3810                  $('.autocomplete-suggestions').hide();
3811                  $('form#searchform').removeClass('search-loading');
3812              });
3813            },
3814            categorysearch: function() {
3815                if( theme.basel_settings.header_search_category == 'no' ) return;
3816               var currentAjaxRequest = null,
3817                  categories_form = $('form.has-categories-dropdown'),
3818                  input = categories_form.find('input[name="q"]');
3819               input.attr('autocomplete', 'off').bind('keyup', function() {
3820                 $('.autocomplete-suggestions').html('').hide();
3821                   var term = input.val(), categories = $('#product_cat').val();
3822                  var searchURL = '/search/collections/'+categories+'?type=product&q=' + term;
3823                  if (term.trim() == '') {
3824                     $('.autocomplete-suggestions').hide();
3825                  }else{
3826                     categories_form.addClass('search-loading');
3827                     if (currentAjaxRequest != null) currentAjaxRequest.abort();
3828                     currentAjaxRequest = jQuery.get(searchURL + '&view=json', function(data) {
3829                        $('.autocomplete-suggestions').html(data);
3830                        setTimeout(function() {
3831                          categories_form.removeClass('search-loading');    
3832                        }, 300);   
3833                     });
3834                     setTimeout(function() {
3835                         baselThemeModule.gl_currency();
3836                         $('.autocomplete-suggestions').show();    
3837                     }, 1500); 
3838                  }
3839               });
3840               $('body').bind('click', function(){
3841                  $('.autocomplete-suggestions').hide();
3842                  $('form#searchform').removeClass('search-loading');
3843               });
3844            },
3845
3846            /**
3847             *-------------------------------------------------------------------------------------------------------------------------------------------
3848             * Search full screen
3849             *-------------------------------------------------------------------------------------------------------------------------------------------
3850             */
3851            searchFullScreen: function() {
3852
3853                var body = $('body'),
3854                    searchWrapper = $('.basel-search-wrapper'),
3855                    offset = 0;
3856
3857                if( ! searchWrapper.find('.searchform').hasClass('basel-ajax-search') && $('.search-button').hasClass('basel-search-dropdown') ) return;
3858
3859                body.on('click', '.search-button > a', function(e) {
3860                    e.preventDefault();
3861                    if( $('.sticky-header.act-scroll').length > 0 ) {
3862                        searchWrapper = $('.sticky-header .basel-search-wrapper');
3863                    } else {
3864                        searchWrapper = $('.main-header .basel-search-wrapper');
3865                    }
3866                    if( isOpened() ) {
3867                        closeWidget();
3868                    } else {
3869                        setTimeout( function() {
3870                            openWidget();
3871                        }, 10);
3872                    }
3873                })
3874
3875
3876                body.on("click", ".basel-close-search, .main-header, .sticky-header, .topbar-wrapp, .main-page-wrapper", function(event) {
3877
3878                    if ( ! $(event.target).is('.basel-close-search') && $(event.target).closest(".basel-search-wrapper").length ) return;
3879
3880                    if( isOpened() ) {
3881                        closeWidget();
3882                    }
3883                });
3884
3885                var closeWidget = function() {
3886                    $('body').removeClass('basel-search-opened');
3887                    searchWrapper.removeClass('search-overlap');
3888                };
3889
3890                var openWidget = function() {
3891                    var bar = $('#wpadminbar').outerHeight();
3892
3893                    var offset = $('.main-header').outerHeight() + bar;
3894
3895                    if( ! $('.main-header').hasClass('act-scroll') ) {
3896                        offset += $('.topbar-wrapp').outerHeight();
3897                    }
3898
3899                    if( $('.sticky-header').hasClass('header-clone') && $('.sticky-header').hasClass('act-scroll') ) {
3900                        offset = $('.sticky-header').outerHeight() + bar;
3901                    }
3902
3903                    if( $('.main-header').hasClass('header-menu-top') && $('.header-spacing') ) {
3904                        offset = $('.header-spacing').outerHeight() + bar;
3905                    }
3906
3907
3908                    searchWrapper.css('top', offset);
3909
3910                    $('body').addClass('basel-search-opened');
3911                    searchWrapper.addClass('search-overlap');
3912                    setTimeout(function() {
3913                        searchWrapper.find('input[type="text"]').focus();
3914                        $(window).one('scroll', function() {
3915                            if( isOpened() ) {
3916                                closeWidget();
3917                            }
3918                        });
3919                    }, 300);
3920                };
3921
3922                var isOpened = function() {
3923                    return $('body').hasClass('basel-search-opened');
3924                };
3925            },
3926
3927
3928            /**
3929             *-------------------------------------------------------------------------------------------------------------------------------------------
3930             * Login tabs for my account page
3931             *-------------------------------------------------------------------------------------------------------------------------------------------
3932             */
3933            loginTabs: function() {
3934                var tabs = $('.basel-register-tabs'),
3935                    btn = tabs.find('.basel-switch-to-register'),
3936                    login = tabs.find('.col-login'),
3937                    register = tabs.find('.col-register'),
3938                    classOpened = 'active-register',
3939                    loginLabel = btn.data('login'),
3940                    registerLabel = btn.data('register');
3941
3942                btn.click(function(e) {
3943                    e.preventDefault();
3944
3945                    if( isShown() ) {
3946                        hideRegister();
3947                    } else {
3948                        showRegister();
3949                    }
3950
3951                    var scrollTo = $('.main-page-wrapper').offset().top - 100;
3952
3953                    if( $(window).width() < 768 ) {
3954                        $('html, body').stop().animate({
3955                            scrollTop: tabs.offset().top - 50
3956                        }, 400);
3957                    }
3958                });
3959
3960                var showRegister = function() {
3961                    tabs.addClass(classOpened);
3962                    btn.text(loginLabel);
3963                };
3964
3965                var hideRegister = function() {
3966                    tabs.removeClass(classOpened);
3967                    btn.text(registerLabel);
3968                };
3969
3970                var isShown = function() {
3971                    return tabs.hasClass(classOpened);
3972                };
3973            },
3974
3975
3976            /**
3977             *-------------------------------------------------------------------------------------------------------------------------------------------
3978             * Product accordion
3979             *-------------------------------------------------------------------------------------------------------------------------------------------
3980             */
3981            productAccordion: function() {
3982                var $accordion = $('.tabs-layout-accordion');
3983
3984                var time = 300;
3985
3986                var hash  = window.location.hash;
3987                var url   = window.location.href;
3988
3989                if ( hash.toLowerCase().indexOf( 'comment-' ) >= 0 || hash === '#reviews' || hash === '#tab-reviews' ) {
3990                    $accordion.find('.tab-title-reviews').addClass('active');
3991                } else if ( url.indexOf( 'comment-page-' ) > 0 || url.indexOf( 'cpage=' ) > 0 ) {
3992                    $accordion.find('.tab-title-reviews').addClass('active');
3993                } else {
3994                    $accordion.find('.basel-accordion-title').first().addClass('active');
3995                }
3996
3997                $accordion.on('click', '.basel-accordion-title', function( e ) {
3998                    e.preventDefault();
3999
4000                    var $this = $(this),
4001                        $panel = $this.siblings('.shopify-Tabs-p
4001anel');
4002
4003                    if( $this.hasClass('active') ) {
4004                        $this.removeClass('active');
4005                        $panel.stop().slideUp(time);
4006                    } else {
4007                        $accordion.find('.basel-accordion-title').removeClass('active');
4008                        $accordion.find('.shopify-Tabs-panel').slideUp();
4009                        $this.addClass('active');
4010                        $panel.stop().slideDown(time);
4011                    }
4012
4013                    $(window).resize();
4014
4015                    setTimeout( function() {
4016                        $(window).resize();
4017                    }, time);
4018
4019                } );
4020            },
4021
4022
4023            /**
4024             *-------------------------------------------------------------------------------------------------------------------------------------------
4025             * Compact product layout
4026             *-------------------------------------------------------------------------------------------------------------------------------------------
4027             */
4028            productCompact: function() {
4029                $(".product-design-compact .basel-scroll").nanoScroller({
4030                    paneClass: 'basel-scroll-pane',
4031                    sliderClass: 'basel-scroll-slider',
4032                    contentClass: 'basel-scroll-content',
4033                    preventPageScrolling: false
4034                });
4035            },
4036
4037
4038            /**
4039             *-------------------------------------------------------------------------------------------------------------------------------------------
4040             * Sale final date countdown
4041             *-------------------------------------------------------------------------------------------------------------------------------------------
4042             */
4043            countDownTimer: function() {
4044
4045                $('.basel-timer').each(function() {
4046                   $(this).countdown($(this).data('end-date'), function(event) {
4047                        $(this).html(event.strftime(''
4048                            + '<span class="countdown-days">%-D <span>' + theme.basel_settings.countdown_days + '</span></span> '
4049                            + '<span class="countdown-hours">%H <span>' + theme.basel_settings.countdown_hours + '</span></span> '
4050                            + '<span class="countdown-min">%M <span>' + theme.basel_settings.countdown_mins + '</span></span> '
4051                            + '<span class="countdown-sec">%S <span>' + theme.basel_settings.countdown_sec + '</span></span>'));
4052                    });
4053                });
4054             },
4055
4056            /**
4057             *-------------------------------------------------------------------------------------------------------------------------------------------
4058             * Remove click delay on mobile
4059             *-------------------------------------------------------------------------------------------------------------------------------------------
4060             */
4061            mobileFastclick: function() {
4062
4063                if ('addEventListener' in document) {
4064                    document.addEventListener('DOMContentLoaded', function() {
4065                        FastClick.attach(document.body);
4066                    }, false);
4067                }
4068
4069            },
4070
4071            /**
4072             *-------------------------------------------------------------------------------------------------------------------------------------------
4073             * Init nanoscroller
4074             *-------------------------------------------------------------------------------------------------------------------------------------------
4075             */
4076            nanoScroller: function() {
4077                $(".basel-scroll").nanoScroller({
4078                    paneClass: 'basel-scroll-pane',
4079                    sliderClass: 'basel-scroll-slider',
4080                    contentClass: 'basel-scroll-content',
4081                    preventPageScrolling: false
4082                });
4083
4084            },
4085
4086            /**
4087             *-------------------------------------------------------------------------------------------------------------------------------------------
4088             * Fix RTL issues
4089             *-------------------------------------------------------------------------------------------------------------------------------------------
4090             */
4091            RTL: function() {
4092                if( ! $('body').hasClass('rtl') ) return;
4093
4094                $(document).on("gl-full-width-row", function(event, el) {
4095                    var $rows = $( '[data-gl-full-width="true"]' );
4096                    $rows.each(function() {
4097                        var $this = $(this),
4098                            left = parseInt( $this.css("left"), 10 );
4099
4100                        $this.css({
4101                            left: -left
4102                        });
4103
4104                        if( $('.main-header').hasClass('header-vertical') ) {
4105                            var paddingLeft = $this.css('padding-left'),
4106                                paddingRight = $this.css('padding-right');
4107
4108                            $this.css({
4109                                paddingLeft: paddingRight,
4110                                paddingRight: paddingLeft
4111                            });
4112
4113                        }
4114                    });
4115                })
4116            },
4117
4118
4119            /**
4120             *-------------------------------------------------------------------------------------------------------------------------------------------
4121             * Fix comments
4122             *-------------------------------------------------------------------------------------------------------------------------------------------
4123             */
4124            // shopifyComments: function() {
4125            //     var hash  = window.location.hash;
4126            //     var url   = window.location.href;
4127
4128            //     if ( hash.toLowerCase().indexOf( 'comment-' ) >= 0 || hash === '#reviews' || hash === '#tab-reviews' || url.indexOf( 'comment-page-' ) > 0 || url.indexOf( 'cpage=' ) > 0 ) {
4129
4130            //         setTimeout(function() {
4131            //             window.scrollTo(0, 0);
4132            //         }, 1);
4133
4134            //         setTimeout(function() {
4135            //             $('html, body').stop().animate({
4136            //                 scrollTop: $(hash).offset().top-100
4137            //             }, 400);
4138            //         }, 10);
4139
4140            //     }
4141            // },
4142             autoloadCompare: function() {
4143              if( theme.basel_settings.compare == 'no' ) return;
4144                var ls = gl_Currency.cookie.tearead('tea-compare');
4145                 if(ls != null){ 
4146                  ls = ls.split(',');
4147                  ls.map(function(elem, index) {
4148                      //console.log(elem);
4149                     $('[data-pid="'+elem+'"]' ).addClass('added').html('<span class="basel-tooltip-label">'+theme.strings.added_label+'</span>'+theme.strings.added_label);
4150                  });
4151                 }else{
4152                   ls = new Array();
4153                 }
4154             },
4155             gl_currency: function() {
4156                var gl_Currency_cookie = gl_Currency.cookie.read();
4157                if( gl_Currency_cookie == null || gl_Currency_cookie == theme.shop_currency ) return;
4158                console.log('currency run');
4159                Currency.convertAll(shopCurrency, gl_Currency.cookie.read());
4160             },
4161             gl_productreviews: function() {
4162                if(theme.gl_productreviews && $(".spr-badge").length > 0 ) {
4163                    $.getScript(window.location.protocol + "//productreviews.shopifycdn.com/assets/v4/spr.js");
4164                }
4165             },
4166             gl_save_note: function() {
4167              if(theme.basel_settings.save_note == 'yes') {
4168                // Save note anytime it's changed
4169                $(document.body).on('change', '#CartSpecialInstructions', function() {
4170                  var newNote = $(this).val(),
4171                      $widget = $('.widget_shopping_cart'),
4172                      $checkout = $('.checkout');
4173                  // Update the cart note in case they don't click update/checkout
4174                  $widget.addClass('removing-process');
4175                  $checkout.attr('disabled', 'disabled').css('pointer-events', 'none');
4176                  $.ajax({
4177                    type: 'POST',
4178                    url: '/cart/update.js',
4179                    data: 'note=' + baselThemeModule.attributeToString(newNote),
4180                    dataType: 'json',
4181                    success:function( cart ) {
4182                    },
4183                    error: function(XMLHttpRequest, textStatus) {
4184                      baselThemeModule.onError(XMLHttpRequest, textStatus);
4185                    },
4186                    complete: function() {
4187                      $widget.removeClass('removing-process');
4188                      $checkout.removeAttr("disabled").css('pointer-events', 'auto');
4189                    }
4190                  });
4191                });
4192              }
4193             },
4194             attributeToString: function(attribute) {
4195              if ((typeof attribute) !== 'string') {
4196                // Converts to a string.
4197                attribute += '';
4198                if (attribute === 'undefined') {
4199                  attribute = '';
4200                }
4201              }
4202              // Removing leading and trailing whitespace.
4203              return jQuery.trim(attribute);
4204            },
4205             
4206             /**
4207             *-------------------------------------------------------------------------------------------------------------------------------------------
4208             * Error functionality with AJAX
4209             *-------------------------------------------------------------------------------------------------------------------------------------------
4210             */
4211            onError: function(XMLHttpRequest, textStatus) {
4212              // Shopify returns a description of the error in XMLHttpRequest.responseText.
4213              // It is JSON.
4214              // Example: {"description":"The product 'Amelia - Small' is already sold out.","status":500,"message":"Cart Error"}
4215              var data = eval('(' + XMLHttpRequest.responseText + ')');
4216              alert(data.message + '(' + data.status  + '): ' + data.description);
4217            },
4218            /**
4219             *-------------------------------------------------------------------------------------------------------------------------------------------
4220             * Add from cart functionality with AJAX
4221             *-------------------------------------------------------------------------------------------------------------------------------------------
4222             */
4223            AJAXFormAddToCart: function() {
4224                if( ! theme.use_ajax_add_to_cart ) return;
4225                $( document ).on('click', '.ajax_form_cart', function(e) {
4226                    e.preventDefault();
4227                    var $this = $(this);
4228                    $(this).attr('disabled', 'disabled').css('pointer-events', 'none').addClass('loading');
4229                    $.ajax({
4230                        type: 'POST',
4231                        url: '/cart/add.js',
4232                        data: $this.closest('form').serialize(),
4233                        dataType: 'json',
4234                        success:function( cart ) {
4235                              $.get('/cart?view=json', function(data) {
4236                                /*optional stuff to do after success */
4237                                $('.widget_shopping_cart_content').html(data);
4238                              });
4239                              $.getJSON('/cart.js', function(cart) {
4240                                $(".cartCount").html(cart.item_count);
4241                                $(".basel-cart-subtotal >span").html(Shopify.formatMoney(cart.total_price, theme.moneyFormat));
4242                              });
4243                              baselThemeModule.gl_currency();
4244                              baselThemeModule.addToCart();
4245                        },
4246                        error: function(XMLHttpRequest, textStatus) {
4247                          baselThemeModule.onError(XMLHttpRequest, textStatus);
4248                        },
4249                        complete: function() {
4250                          $this.removeAttr("disabled").css('pointer-events', 'auto').removeClass("loading");
4251                        }
4252                    });
4253                })
4254            },
4255
4256            /**
4257             *-------------------------------------------------------------------------------------------------------------------------------------------
4258             * Add to cart functionality with AJAX
4259             *-------------------------------------------------------------------------------------------------------------------------------------------
4260             */
4261            AJAXAddToCart: function() {
4262                $( document ).on('click', '.ajax_add_to_cart', function(e) {
4263                    e.preventDefault();
4264                    var $this = $(this),
4265                        variant_id = $this.data('pid');
4266                    $(this).attr('disabled', 'disabled').css('pointer-events', 'none').addClass('loading');
4267                    $.ajax({
4268                        type: 'POST',
4269                        url: '/cart/add.js',
4270                        data: {quantity: 1, id:variant_id},
4271                        dataType: 'json',
4272                        success:function( cart ) {
4273                            if (theme.use_ajax_add_to_cart) {
4274                              $.get('/cart?view=json', function(data) {
4275                                   /*optional stuff to do after success */
4276                                   $('.widget_shopping_cart_content').html(data);
4277                                 });
4278                              $.getJSON('/cart.js', function(cart) {
4279                                $(".cartCount").html(cart.item_count);
4280                                $(".basel-cart-subtotal >span").html(Shopify.formatMoney(cart.total_price, theme.moneyFormat));
4281                              });
4282                              baselThemeModule.gl_currency();
4283                              if( $this.hasClass('add_compare') === false ){
4284                                 baselThemeModule.addToCart();
4285                              }
4286                              $this.removeAttr("disabled").css('pointer-events', 'auto').removeClass("ajax_add_to_cart loading").addClass('added_to_cart').text(theme.strings.view_cart).attr({ href:"/cart"});
4287                            }else{
4288                              window.location.href = '/cart';  
4289                            }
4290                        },
4291                        error: function(XMLHttpRequest, textStatus) {
4292                          $this.removeAttr("disabled").css('pointer-events', 'auto').removeClass("loading");
4293                          baselThemeModule.onError(XMLHttpRequest, textStatus);
4294                        }
4295                    });
4296                })
4297            },
4298            /**
4299             *-------------------------------------------------------------------------------------------------------------------------------------------
4300             * Remove from cart functionality with AJAX
4301             *-------------------------------------------------------------------------------------------------------------------------------------------
4302             */
4303            AJAXRemoveFromCart: function() {
4304                $( document ).on('click', '.widget_shopping_cart .remove', function(e) {
4305                    e.preventDefault();
4306
4307                    var $this = $(this),
4308                        $widget = $('.widget_shopping_cart'),
4309                        remove_item = $this.data('remove_item'),
4310                        variant_id = $this.data('product_id');
4311
4312                    $widget.addClass('removing-process');
4313                    $.ajax({
4314                        type: 'POST',
4315                        url: '/cart/change.js',
4316                        data:  'quantity=0&id='+variant_id,
4317                        dataType: 'json',
4318                        success:function( cart ) {
4319                          $.get('/cart?view=json', function(data) {
4320                               /*optional stuff to do after success */
4321                               $('.widget_shopping_cart_content').html(data);
4322                             });
4323                          $.getJSON('/cart.js', function(cart) {
4324                            $(".cartCount").html(cart.item_count);
4325                            $(".basel-cart-subtotal >span").html(Shopify.formatMoney(cart.total_price, theme.moneyFormat));
4326                          });
4327                          baselThemeModule.gl_currency();
4328                        },
4329                        error: function() {
4330                           baselThemeModule.onError(XMLHttpRequest, textStatus);
4331                        },
4332                        complete: function() {
4333                            $widget.removeClass('removing-process');
4334                        }
4335                    });
4336                })
4337            },
4338              
4339
4340            /**
4341             *-------------------------------------------------------------------------------------------------------------------------------------------
4342             * Quantityt +/-
4343             *-------------------------------------------------------------------------------------------------------------------------------------------
4344             */
4345            shopifyQuantity: function() {
4346              function ShopifyCartChange(variant_id, quantity, c
4346allback) {
4347                var params = {
4348                  type: 'POST',
4349                  url: '/cart/change.js',
4350                  data:  'quantity='+quantity+'&id='+variant_id,
4351                  dataType: 'json',
4352                  success: function(cart) { 
4353                    if ((typeof callback) === 'function') {
4354                      callback(cart);
4355                    }
4356                    else {
4357//                       Shopify.onCartUpdate(cart);
4358                    }
4359                  },
4360                  error: function(XMLHttpRequest, textStatus) {
4361                     baselThemeModule.onError(XMLHttpRequest, textStatus);
4362                  }
4363                };
4364                jQuery.ajax(params);
4365              }
4366              function formatMoney(cents, format) {
4367                var value = '';
4368                var patt = /\{\{\s*(\w+)\s*\}\}/;
4369                var formatString = (format || '${{amount}}');
4370                switch(formatString.match(patt)[1]) {
4371                case 'amount':
4372                  value = floatToString(cents/100.0, 2).replace(/(\d+)(\d{3}[\.,]?)/,'$1 $2');
4373                  break;
4374                case 'amount_no_decimals':
4375                  value = floatToString(cents/100.0, 0).replace(/(\d+)(\d{3}[\.,]?)/,'$1 $2');
4376                  break;
4377                case 'amount_with_comma_separator':
4378                  value = floatToString(cents/100.0, 2).replace(/\./, ',').replace(/(\d+)(\d{3}[\.,]?)/,'$1.$2');
4379                  break;
4380                }    
4381                return value;
4382              };
4383                        if ( ! String.prototype.getDecimals ) {
4384                    String.prototype.getDecimals = function() {
4385                        var num = this,
4386                            match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
4387                        if ( ! match ) {
4388                            return 0;
4389                        }
4390                        return Math.max( 0, ( match[1] ? match[1].length : 0 ) - ( match[2] ? +match[2] : 0 ) );
4391                    }
4392                }
4393				
4394              $( document ).on( 'change keyup', '.custom-qty', function() {
4395              	var $this = $(this);
4396                var vid = $this.data('vid'),val = parseInt($this.val()), format = $this.data('format'),price = $this.data('price'), max = $this.attr('max');
4397                if(isNaN(val)) return 0;
4398                
4399                max = isNaN(parseInt(max)) ? 9999: parseInt(max);
4400                console.log(max);
4401                if(val > max )
4402                {
4403                  console.log('xxxx'+ max);
4404                	$this.attr('value', max).val(max);
4405                }
4406                val = (val > max) ? max : val;
4407                
4408                if(val == 0 ){
4409                	$this.closest('tr').remove();
4410                  	$this.closest('li').remove();
4411                }
4412                ShopifyCartChange(vid,val, function(res){
4413                	 $('.total .shopify-Price-amount, .order-total .shopify-Price-amount,.cart-subtotal .shopify-Price-amount,.basel-cart-subtotal .shopify-Price-amount').html(format.replace(/\{\{.*\}\}/,formatMoney(res.total_price)));
4414                  	$this.closest('tr').find('.product-subtotal .shopify-Price-amount').html(format.replace(/\{\{.*\}\}/,formatMoney(price * val)  ));
4415                  $('.cartCount').html(res.item_count);
4416                  baselThemeModule.gl_currency();
4417                });
4418              });
4419                $( document ).on( 'click', '.plus, .minus', function() {
4420                console.log(1);
4421                    // Get values
4422                    var $qty        = $( this ).closest( '.quantity' ).find( '.qty'),
4423                        currentVal  = parseFloat( $qty.val() ),
4424                        max         = parseFloat( $qty.attr( 'max' ) ),
4425                        min         = parseFloat( $qty.attr( 'min' ) ),
4426                        step        = $qty.attr( 'step' );
4427
4428                    // Format values
4429                    if ( ! currentVal || currentVal === '' || currentVal === 'NaN' ) currentVal = 0;
4430                    if ( max === '' || max === 'NaN' ) max = '';
4431                    if ( min === '' || min === 'NaN' ) min = 0;
4432                    if ( step === 'any' || step === '' || step === undefined || parseFloat( step ) 
4432=== 'NaN' ) step = 1;
4433
4434                    // Change the value
4435                    if ( $( this ).is( '.plus' ) ) {
4436                        if ( max && ( currentVal >= max ) ) {
4437                            $qty.val( max );
4438                        } else {
4439                            $qty.val( ( currentVal + parseFloat( step )).toFixed( step.getDecimals() ) );
4440                        }
4441                    } else {
4442                        if ( min && ( currentVal <= min ) ) {
4443                            $qty.val( min );
4444                        } else if ( currentVal > 0 ) {
4445                            $qty.val( ( currentVal - parseFloat( step )).toFixed( step.getDecimals() ) );
4446                        }
4447                    }
4448
4449                    // Trigger change event
4450                    $qty.trigger( 'change' );
4451                });
4452
4453            },
4454        }
4455    }());
4456
4457})(jQuery);
4458
4459
4460jQuery(document).ready(function() {
4461
4462    baselThemeModule.init();
4463
4464});
4465jQuery( window ).load( function() {
4466    baselThemeModule.shopMasonry();
4467});
4468
4469

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.