1/** 2 * Wolmart Javascript File 3 * 4 * @version 1.0 5 */ 6'use strict'; 7 8var $ = jQuery.noConflict(); 9 10/* jQuery easing */ 11$.extend($.easing, { 12 def: 'easeOutQuad', 13 swing: function (x, t, b, c, d) { 14 return $.easing[$.easing.def](x, t, b, c, d); 15 }, 16 easeOutQuad: function (x, t, b, c, d) { 17 return -c * (t /= d) * (t - 2) + b; 18 }, 19 easeOutQuint: function (x, t, b, c, d) { 20 return c * ((t = t / d - 1) * t * t * t * t + 1) + b; 21 } 22}); 23 24/** 25 * Wolmart Object 26 */ 27window.Wolmart = {}; 28 29/** 30 * Wolmart Base 31 */ 32(function ($) { 33 34 /** 35 * jQuery Window Handle 36 * 37 * @var jQuery jQuery window handle 38 */ 39 Wolmart.$window = $(window); 40 41 /** 42 * jQuery Body Handle 43 * 44 * @var jQuery jQuery body handle 45 */ 46 Wolmart.$body = $(document.body); 47 48 /** 49 * Status 50 * 51 * @var string Status 52 */ 53 Wolmart.status = ''; 54 55 /** 56 * Check if the browser is internet explorer. 57 * 58 * @var boolean isIE 59 */ 60 Wolmart.isIE = navigator.userAgent.indexOf('Trident') >= 0; 61 62 /** 63 * Check if the browser is internet explorer. 64 * 65 * @var boolean isIE 66 */ 67 Wolmart.isEdge = navigator.userAgent.indexOf('Edge') >= 0; 68 Wolmart.isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); 69 70 /** 71 * Make a macro task 72 * 73 * @param {function} fn 74 * @param {number} delay 75 * @return {void} 76 */ 77 Wolmart.call = function (fn, delay) { 78 setTimeout(fn, delay); 79 } 80 81 /** 82 * Parse options string to object 83 * 84 * @param {string} options 85 * @return {object} options 86 */ 87 Wolmart.parseOptions = function (options) { 88 return 'string' == typeof options ? 89 JSON.parse(options.replace(/'/g, '"').replace(';', '')) : 90 {}; 91 } 92 93 /** 94 * Parse html template with variables. 95 * 96 * @param {string} template 97 * @param {object} vars 98 * @return {string} parsed template 99 */ 100 Wolmart.parseTemplate = function (template, vars) { 101 return template.replace(/\{\{(\w+)\}\}/g, function () { 102 return vars[arguments[1]]; 103 }); 104 } 105 106 /** 107 * Get dom element by id 108 * 109 * @param {string} id 110 * @return {HTMLElement} element 111 */ 112 Wolmart.byId = function (id) { 113 return document.getElementById(id); 114 } 115 116 /** 117 * Get dom elements by tagName 118 * 119 * @param {string} tagName 120 * @param {HTMLElement} element this can be omitted. 121 * @return {HTMLCollection} 122 */ 123 Wolmart.byTag = function (tagName, element) { 124 return element ? 125 element.getElementsByTagName(tagName) : 126 document.getElementsByTagName(tagName); 127 } 128 129 /** 130 * Get dom elements by className 131 * 132 * @param {string} className 133 * @param {HTMLElement} element this can be omitted. 134 * @return {HTMLCollection} 135 */ 136 Wolmart.byClass = function (className, element) { 137 return element ? 138 element.getElementsByClassName(className) : 139 document.getElementsByClassName(className); 140 } 141 142 143 /** 144 * Set cookie 145 * 146 * @param {string} name Cookie name 147 * @param {string} value Cookie value 148 * @param {number} exdays Expire period 149 */ 150 Wolmart.setCookie = function (name, value, exdays) { 151 var date = new Date(); 152 date.setTime(date.getTime() + (exdays * 24 * 60 * 60 * 1000)); 153 document.cookie = name + "=" + value + ";expires=" + date.toUTCString() + ";path=/"; 154 } 155 156 /** 157 * Get cookie 158 * 159 * @param {string} name Cookie name 160 * @return {string} Cookie value 161 */ 162 Wolmart.getCookie = function (name) { 163 var n = name + "="; 164 var ca = document.cookie.split(';'); 165 for (var i = 0; i < ca.length; ++i) { 166 var c = ca[i]; 167 while (c.charAt(0) == ' ') { 168 c = c.substring(1); 169 } 170 if (c.indexOf(n) == 0) { 171 return c.substring(n.length, c.length); 172 } 173 } 174 return ""; 175 } 176 177 /** 178 * Get jQuery object 179 * 180 * @param {string|jQuery} selector 181 * @return {jQuery|Object} jQuery Object or {each: $.noop} 182 */ 183 Wolmart.$ = function (selector) { 184 if (selector instanceof jQuery) { 185 return selector; 186 } 187 return $(selector); 188 } 189 190 /** 191 * Check if DOM node is on screen 192 * 193 * @param {HTMLElement} el 194 * @return {boolean} 195 */ 196 Wolmart.isOnScreen = function (el) { 197 198 var a = window.pageXOffset, 199 b = window.pageYOffset, 200 o = el.getBoundingClientRect(), 201 x = o.left + a, 202 y = o.top + b; 203 204 return y + o.height >= b && 205 y <= b + window.innerHeight && 206 x + o.width >= a && 207 x <= a + window.innerWidth; 208 } 209 210 /** 211 * Do appear animations. 212 * 213 * @param {HTMLElement} el 214 * @param {function} fn 215 * @param {object} options 216 * @return {boolean} 217 */ 218 219 Wolmart.appear = function (el, fn, intObsOptions) { 220 var interSectionObserverOptions = { 221 rootMargin: '0px 0px 200px 0px', 222 threshold: 0, 223 alwaysObserve: true 224 }; 225
226 if (intObsOptions && Object.keys(intObsOptions).length) { 227 $.extend(intersectionObserverOptions, intObsOptions); 228 } 229 230 var observer = new IntersectionObserver(function (entries) { 231 for (var i = 0; i < entries.length; i++) { 232 var entry = entries[i]; 233 234 if (entry.intersectionRatio > 0) { 235 if (typeof fn === 'string') { 236 var func = Function('return ' + functionName)(); 237 } else { 238 var callback = fn; 239 240 callback.call($(entry.target)); 241 } 242 } 243 } 244 }, interSectionObserverOptions); 245 246 observer.observe(el); 247 248 return this; 249 } 250 251 /** 252 * Request Timeout 253 * 254 * @param {function} fn 255 * @param {number} delay 256 */ 257 Wolmart.requestTimeout = function (fn, delay) { 258 var handler = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame; 259 if (!handler) { 260 return setTimeout(fn, delay); 261 } 262 263 var start, rt = new Object(); 264 265 function loop(timestamp) { 266 if (!start) { 267 start = timestamp; 268 } 269 var progress = timestamp - start; 270 progress >= delay ? fn() : rt.val = handler(loop); 271 }; 272 273 rt.val = handler(loop); 274 return rt; 275 } 276 277 /** 278 * Request Interval 279 * 280 * @param {function} fn 281 * @param {number} step 282 * @param {number} timeOut 283 */ 284 Wolmart.requestInterval = function (fn, step, timeOut) { 285 var handler = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame; 286 if (!handler) { 287 if (!timeOut) { 288 console.log('settimeout'); 289 return setTimeout(fn, timeOut); 290 } 291 else { 292 console.log('settimeout'); 293 return setInterval(fn, step); 294 } 295 } 296 var start, last, rt = new Object(); 297 function loop(timestamp) { 298 if (!start) { 299 start = last = timestamp; 300 } 301 var progress = timestamp - start; 302 var delta = timestamp - last; 303 if (!timeOut || progress < timeOut) { 304 if (delta > step) { 305 fn(); 306 rt.val = handler(loop); 307 last = timestamp; 308 } else { 309 rt.val = handler(loop); 310 } 311 } else { 312 fn(); 313 } 314 }; 315 rt.val = handler(loop); 316 console.log(rt); 317 return rt; 318 } 319 320 /** 321 * Delete Timeout 322 * 323 * @param {number} timerId 324 */ 325 Wolmart.deleteTimeout = function (timerId) { 326 if (!timerId) { 327 return; 328 } 329 var handler = window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame; 330 if (!handler) { 331 return clearTimeout(timerId); 332 } 333 if (timerId.val) { 334 return handler(timerId.val); 335 } 336 } 337 338 339 /** 340 * Register event for tab click 341 * 342 * @param {string} selector 343 */ 344 Wolmart.setTab = function (selector) { 345 346 function _activeTab(e) { 347 var $this = $(this); 348 e.preventDefault(); 349 350 if (!$this.hasClass("active")) { 351 var $panel = $($this.attr('href')); 352 $panel.siblings('.active').removeClass('in active'); 353 $panel.addClass('active in'); 354 355 $this.parent().parent().find('.active').removeClass('active'); 356 $this.addClass('active'); 357 } 358 } 359 360 function _linkToTab(e) { 361 var selector = $(e.currentTarget).attr('href'), 362 $tab = $(selector), 363 $nav = $tab.parent().siblings('.nav'); 364 e.preventDefault(); 365 366 $tab.siblings().removeClass('active in'); 367 $tab.addClass('active in'); 368 $nav.find('.nav-link').removeClass('active'); 369 $nav.find('[href="' + selector + '"]').addClass('active'); 370 371 $('html').animate({ 372 scrollTop: $tab.offset().top - 150 373 }); 374 } 375 376 Wolmart.$body 377 .on('click', '.tab .nav-link', _activeTab) // tab nav link 378 .on('click', '.link-to-tab', _linkToTab); // link to tab 379 } 380 381 /** 382 * productCartAction 383 * 384 * @param {string} selector 385 */ 386 Wolmart.initCartAction = function (selector) { 387 // Cart dropdown is offcanvas type 388 Wolmart.$body 389 .on('click', selector, function (e) { 390 $('.cart-dropdown').addClass('opened'); 391 e.preventDefault(); 392 }) 393 .on('click', '.cart-offcanvas .cart-overlay', function (e) { 394 $('.cart-dropdown').removeClass('opened'); 395 e.preventDefault(); 396 }) 397 .on('click', '.cart-offcanvas .cart-header, .cart-close', function (e) { 398 $('.cart-dropdown').removeClass('opened'); 399 e.preventDefault(); 400 }) 401 } 402 403 /** 404 * initScrollTopButton 405 * 406 */ 407 Wolmart.initScrollTopButton = function () { 408 // register scroll top button 409 var domScrollTop = Wolmart.byId('scroll-top'); 410 411 domScrollTop.addEventListener('click', function (e) { 412 $('html, body').animate({ scrollTop: 0 }, 600); 413 e.preventDefault(); 414 }); 415 416 var refreshScrollTop = function () { 417 if (window.pageYOffset > 400) { 418 domScrollTop.classList.add('show'); 419 420 // Show scroll position percent in scroll top button 421 var d_height = $(document).height(), 422 w_height = $(window).height(), 423 c_scroll_pos = $(window).scrollTop(); 424 425 var perc = c_scroll_pos / (d_height - w_height) * 214; 426 427 if ($('#progress-indicator').length > 0) { 428 $('#progress-indicator').css('stroke-dasharray', perc + ', 400'); 429 } 430 } else { 431 domScrollTop.classList.remove('show'); 432 } 433 } 434 435 Wolmart.call(refreshScrollTop, 500); 436 window.addEventListener('scroll', refreshScrollTop, { passive: true }); 437 } 438 439 /** 440 * Sticky Default Options 441 */ 442 Wolmart.stickyDefaultOptions = { 443 minWidth: 992, 444 maxWidth: 20000, 445 top: false, 446 hide: false, 447 scrollMode: true 448 } 449 450 Wolmart.stickyToolboxOptions = { 451 minWidth: 0, 452 maxWidth: 767, 453 top: false, 454 scrollMode: true 455 } 456 457 Wolmart.stickyProductOptions = { 458 minWidth: 0, 459 maxWidth: 20000, 460 scrollMode: true, 461 top: false, 462 hide: false 463 } 464 465 /** 466 * Check if window's width is really resized. 467 * 468 * @since 1.0 469 * @param {number} timeStamp 470 * @return {boolean} 471 */ 472 Wolmart.windowResized = function (timeStamp) { 473 if (timeStamp == Wolmart.resizeTimeStamp) { 474 return Wolmart.resizeChanged; 475 } 476 if ( typeof window.innerHeight == 'undefined' ) { 477 window.innerWidth = $( window ).width() + Wolmart.getScrollbarWidth(); 478 } 479 Wolmart.resizeChanged = Wolmart.canvasWidth != window.innerWidth; 480 Wolmart.canvasWidth = window.innerWidth; 481 Wolmart.resizeTimeStamp = timeStamp; 482 return Wolmart.resizeChanged; 483 } 484 485 /** 486 * Get width of scroll bar 487 * 488 * @since 1.0 489 * @param {number} timeStamp 490 * @return {boolean} 491 */ 492 Wolmart.getScrollbarWidth = function () { 493 if ( typeof Wolmart.scrollbarSize == 'undefined' ) { 494 var scrollDiv = document.createElement( "div" ); 495 scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;'; 496 document.body.appendChild( scrollDiv ); 497 Wolmart.scrollbarSize = scrollDiv.offsetWidth - scrollDiv.clientWidth; 498 document.body.removeChild( scrollDiv ); 499 } 500 return Wolmart.scrollbarSize; 501 } 502 503 /** 504 * Initialize Sticky Content 505 * 506 * @class StickyContent 507 * @since 1.0 508 * @param {string, Object} selector 509 * @param {Object} options 510 * @return {void} 511 */ 512 Wolmart.stickyContent = (function () { 513 function StickyContent($el, options) { 514 return this.init($el, options); 515 } 516 517 function refreshAll() { 518 Wolmart.$window.trigger('sticky_refresh.wolmart', { 519 index: 0, 520 offsetTop: 0 521 }); 522 } 523 524 function refreshAllSize(e) { 525 if (!e || Wolmart.windowResized(e.timeStamp)) { 526 Wolmart.$window.trigger('sticky_refresh_size.wolmart'); 527 refreshAll(); 528 } 529 } 530 531 StickyContent.prototype.init = function ($el, options) { 532 this.$el = $el; 533 this.options = $.extend(true, {}, Wolmart.stickyDefaultOptions, options, Wolmart.parseOptions($el.attr('data-sticky-options'))); 534 Wolmart.$window 535 .on('sticky_refresh.wolmart', this.refresh.bind(this)) 536 .on('sticky_refresh_size.wolmart', this.refreshSize.bind(this)); 537 } 538 539 StickyContent.prototype.refreshSize = function (e) { 540 var beWrap = window.innerWidth >= this.options.minWidth && window.innerWidth <= this.options.maxWidth; 541 this.scrollPos = window.pageYOffset; 542 if (typeof this.top == 'undefined') { 543 this.top = this.options.top; 544 } 545 546 if (window.innerWidth >= 768 && this.getTop) { 547 this.top = this.getTop(); 548 } else if (!this.options.top) { 549 this.top = this.isWrap ? 550 this.$el.parent().offset().top : 551 this.$el.offset().top + this.$el[0].offsetHeight; 552 553 // if sticky header has toggle dropdown menu, increase top 554 if (this.$el.hasClass('has-dropdown')) { 555 var $panel = this.$el.find('.category-megamenu-panel'); 556 var $box = this.$el.find('.category-dropdown .dropdown-box'); 557 if ($panel.length) { 558 this.top += $panel[0].offsetHeight; 559 } else if ($box.length) { 560 this.top += $box[0].offsetHeight; 561 } 562 } 563 } 564 565 if (!this.isWrap) { 566 beWrap && this.wrap(); 567 } else { 568 beWrap || this.unwrap(); 569 } 570 571 Wolmart.sticky_top_height = 0; 572 573 e && setTimeout(this.refreshSize.bind(this), 50); 574 } 575 576 StickyContent.prototype.wrap = function () { 577 this.$el.wrap('<div class="sticky-content-wrapper"></div>'); 578 this.isWrap = true; 579 } 580 581 StickyContent.prototype.unwrap = function () { 582 this.$el.unwrap('.sticky-content-wrapper'); 583 this.isWrap = false;
584 } 585 586 StickyContent.prototype.refresh = function (e, data) { 587 var pageYOffset = window.pageYOffset + data.offsetTop; 588 var $el = this.$el; 589 590 // this.refreshSize(); 591 592 // Make sticky 593 if (pageYOffset > this.top && this.isWrap) { 594 595 // calculate height 596 this.height = $el[0].offsetHeight; 597 $el.hasClass('fixed') || $el.parent().css('height', this.height + 'px'); 598 599 // update sticky order 600 if ($el.hasClass('fix-top')) { 601 $el.css('margin-top', data.offsetTop + 'px'); 602 this.zIndex = this.options.max_index - data.index; 603 } else if ($el.hasClass('fix-bottom')) { 604 $el.css('margin-bottom', data.offsetBottom + 'px'); 605 this.zIndex = this.options.max_index - data.index; 606 } else { 607 $el.css({ 'transition': 'opacity .5s', 'z-index': this.zIndex }); 608 } 609 610 // update sticky status 611 if (this.options.scrollMode) { 612 if (this.scrollPos >= pageYOffset && $el.hasClass('fix-top') || 613 this.scrollPos <= pageYOffset && $el.hasClass('fix-bottom')) { 614 615 $el.addClass('fixed'); 616 this.onFixed && this.onFixed(); 617 618 // for only sticky cart form. 619 $el.hasClass('product-sticky-content') && Wolmart.$body.addClass('addtocart-fixed'); 620 } else { 621 $el.removeClass('fixed').css('margin-top', '').css('margin-bottom', ''); 622 this.onUnfixed && this.onUnfixed(); 623 624 // for only sticky cart form. 625 $el.hasClass('product-sticky-content') && Wolmart.$body.removeClass('addtocart-fixed'); 626 } 627 this.scrollPos = pageYOffset; 628 } else { 629 $el.addClass('fixed'); 630 this.onFixed && this.onFixed(); 631 } 632 633 // stack offset 634 if ($el.is('.fixed.fix-top')) { 635 data.offsetTop += $el[0].offsetHeight; 636 637 Wolmart.sticky_top_height = data.offsetTop; 638 } else if ($el.is('.fixed.fix-bottom')) { 639 data.offsetBottom += $el[0].offsetHeight; 640 } 641 } else { 642 $el.parent().css('height', ''); 643 $el.removeClass('fixed').css({ 'margin-top': '', 'margin-bottom': '', 'z-index': '' }); 644 this.onUnfixed && this.onUnfixed(); 645 646 // for only sticky cart form. 647 $el.hasClass('product-sticky-content') && Wolmart.$body.removeClass('addtocart-fixed'); 648 } 649 } 650 651 Wolmart.$window.on('wolmart_complete', function () { 652 window.addEventListener('scroll', refreshAll, { passive: true }); 653 Wolmart.$window.on('resize', refreshAllSize); 654 setTimeout(function () { 655 refreshAllSize(); 656 }, 300); 657 }) 658 659 return function (selector, options) { 660 Wolmart.$(selector).each(function () { 661 var $this = $(this); 662 $this.data('sticky-content') || $this.data('sticky-content', new StickyContent($this, options)); 663 }) 664 } 665 })() 666 667 /** 668 * parallax 669 * 670 * Set parallax background 671 * 672 * @requires themePluginParallax 673 * @param {string} selector 674 */ 675 Wolmart.parallax = function (selector, options) { 676 if ($.fn.themePluginParallax) { 677 Wolmart.$(selector).each(function () { 678 var $this = $(this); 679 $this.themePluginParallax( 680 $.extend(true, Wolmart.parseOptions($this.attr('data-parallax-options')), options) 681 ); 682 }); 683 } 684 } 685 686 Wolmart.skrollrParallax = function () { 687 if (Wolmart.isMobile) { 688 return; 689 } 690 691 if (typeof skrollr == 'undefined') { 692 return; 693 } 694 695 if (Wolmart.$('.skrollable').length) { 696 skrollr.init({ forceHeight: false }); 697 } 698 } 699 700 /** 701 * Initialize floating elements 702 * 703 * @since 1.0 704 * @param {string|jQuery} selector 705 * @return {void} 706 */ 707 Wolmart.initFloatingParallax = function () { 708 if ($.fn.parallax) { 709 Wolmart.$('.floating-item').each(function (e) { 710 var $this = $(this); 711 if ($this.data('parallax')) { 712 $this.parallax('disable'); 713 $this.removeData('parallax'); 714 $this.removeData('options'); 715 } 716 $this.children().addClass('layer').attr('data-depth', $this.attr('data-child-depth')); 717 $this.parallax(Wolmart.parseOptions($this.data('options'))); 718 }); 719 } 720 721 } 722 723 724 Wolmart.isotopeOptions = { 725 itemsSelector: '.grid-item', 726 layoutMode: 'masonry', 727 percentPosition: true, 728 masonry: { 729 columnWidth: '.grid-space' 730 } 731 } 732 /** 733 * isotopes 734 * 735 * 736 * @requires isotope,imagesLoaded 737 * @param {string} selector, 738 * @param {object} options 739 */ 740 Wolmart.isotopes = function (selector, options) { 741 if (typeof imagesLoaded === 'function' && $.fn.isotope) { 742 var self = this; 743 744 Wolmart.$(selector).each(function () { 745 var $this = $(this), 746 settings = $.extend(true, {}, 747 self.isotopeOptions, 748 Wolmart.parseOptions($this.attr('data-grid-options')), 749 options ? options : {} 750 ); 751 Wolmart.lazyLoad($this); 752 753 $this.imagesLoaded(function () { 754 settings.customInitHeight && $this.height($this.height()); 755 settings.customDelay && Wolmart.call(function () { 756 $this.isotope(settings); 757 }, parseInt(settings.customDelay)); 758 759 $this.isotope(settings); 760 }); 761 }); 762 } 763 } 764 765 766 /** 767 * initNavFilter 768 * 769 * 770 * @requires isotope 771 * @param {string} selector 772 */ 773 Wolmart.initNavFilter = function (selector) { 774 if ($.fn.isotope) { 775 776 Wolmart.$(selector).on('click', function (e) { 777 var $this = $(this), 778 filterValue = $this.attr('data-filter'), 779 filterTarget = $this.parent().parent().attr('data-target'); 780 781 (filterTarget ? $(filterTarget) : $('.grid')) 782 .isotope({ filter: filterValue }) 783 .isotope('on', 'arrangeComplete', function () { 784 Wolmart.$window.trigger('appear.check'); 785 }); 786 787 $this.parent().siblings().children().removeClass('active'); 788 $this.addClass('active'); 789 e.preventDefault(); 790 }) 791 } 792 } 793 794 795 /** 796 * ratingTooltip 797 * 798 * 799 * Find all .ratings-full from root, and initialized tooltip. 800 * @param {HTMLElement} root 801 */ 802 Wolmart.ratingTooltip = function (root) { 803 var els = Wolmart.byClass('ratings-full', root ? root : document.body), 804 len = els.length; 805 var ratingHandler = function () { 806 var res = parseInt(this.firstElementChild.style.width.slice(0, -1)) / 20; 807 this.lastElementChild.innerText = res ? res.toFixed(2) : res; 808 } 809 for (var i = 0; i < len; ++i) { 810 els[i].addEventListener('mouseover', ratingHandler); 811 els[i].addEventListener('touchstart', ratingHandler, { passive: true }); 812 } 813 } 814 815 816 /** 817 * setProgressBar 818 * 819 * 820 * Find all .progress-bar and set its value 821 * @param { String } selector 822 */ 823 Wolmart.setProgressBar = function (selector) { 824 Wolmart.$(selector).each(function () { 825 var $this = $(this), 826 sales_count = $this.parent().find('mark')[0].innerHTML, 827 percent = ''; 828 if (-1 != sales_count.indexOf('%')) { 829 percent = sales_count; 830 } else if (-1 != sales_count.indexOf('/')) { 831 percent = parseInt(sales_count.split('/')[0]) / parseInt(sales_count.split('/')[1]) * 100; 832 percent = percent.toFixed(2).toString() + '%'; 833 } 834 835 $this.find('span').css('width', percent); 836 }); 837 } 838 839 840 /** 841 * alert 842 * 843 * Register events for alert 844 * 845 * @param {string} selector 846 */ 847 Wolmart.alert = function (selector) { 848 Wolmart.$body.on('click', selector + ' .btn-close', function (e) { 849 e.preventDefault(); 850 $(this).closest(selector).fadeOut(function () { 851 $(this).remove(); 852 }); 853 }); 854 } 855 /** 856 * closeTopNotice 857 * 858 * Register events for close 859 * 860 * @param {string} selector 861 */ 862 Wolmart.closeTopNotice = function (selector) { 863 Wolmart.$body.on('click', selector, function (e) { 864 e.preventDefault(); 865 $('.top-banner').slideUp(); 866 }); 867 } 868 869 870 /** 871 * accordion 872 * 873 * Register events for accordion 874 * 875 * @param {String} selector 876 */ 877 Wolmart.accordion = function (selector) { 878 Wolmart.$body.on('click', selector, function (e) { 879 var $this = $(this), 880 $body = $this.closest('.card').find($this.attr('href')), 881 $parent = $this.closest('.accordion'); 882 883 e.preventDefault(); 884 885 if (0 === $parent.find(".collapsing").length && 0 === $parent.find(".expanding").length) { 886 if ($body.hasClass('expanded')) { 887 if (!$parent.hasClass('radio-type')) 888 toggleSlide($body); 889 } else if ($body.hasClass('collapsed')) { 890 if ($parent.find('.expanded').length > 0) { 891 if (Wolmart.isIE) { 892 toggleSlide($parent.find('.expanded'), function () { 893 toggleSlide($body); 894 }); 895 896 } else { 897 toggleSlide($parent.find('.expanded')); 898 toggleSlide($body); 899 } 900 } else { 901 toggleSlide($body); 902 } 903 } 904 } 905 }); 906 907 var toggleSlide = function ($wrap, cb) { 908 var $header = $wrap.closest('.card').find(selector); 909 if ($wrap.hasClass('expanded')) { 910 $header.removeClass('collapse').addClass('expand'); 911 $wrap.addClass('collapsing').slideUp(300, function () { 912 $wrap.removeClass('expanded collapsing').addClass('collapsed'); 913 cb && cb(); 914 }); 915 } else if ($wrap.hasClass("collapsed")) { 916 $header.removeClass("expand").addClass("collapse"); 917 $wrap.addClass("expanding").slideDown(300, function () { 918 $wrap.removeClass("collapsed expanding").addClass("expanded"); 919 cb && cb(); 920 }); 921 } 922 }; 923 } 924 925 926 Wolmart.animationOptions = { 927 name: 'fadeIn', 928 duration: '1.2s', 929 delay: '.2s' 930 } 931 932 /** 933 * appearAnimate 934 * 935 * 936 * @param {String} selector 937 */ 938 Wolmart.appearAnimate = function (selector) { 939 Wolmart.$(selector).each(function () { 940 var el = this; 941
942 Wolmart.appear(el, function () { 943 if (el.classList.contains('appear-animate')) { 944 var settings = $.extend({}, Wolmart.animationOptions, Wolmart.parseOptions(el.getAttribute('data-animation-options'))); 945 946 setTimeout(function () { 947 el.style['animation-duration'] = settings.duration; 948 el.classList.add(settings.name); 949 el.classList.add('appear-animation-visible'); 950 }, settings.delay ? Number(settings.delay.slice(0, -1)) * 1000 : 0); 951 } 952 }); 953 }); 954 } 955 956 957 /** 958 * countDown 959 * 960 * 961 * @param {String} selector 962 */ 963 Wolmart.countDown = function (selector) { 964 if ($.fn.countdown) { 965 Wolmart.$(selector).each(function () { 966 var $this = $(this), 967 untilDate = $this.data('until'), 968 compact = $this.data('compact'), 969 dateFormat = (!$this.data('format')) ? 'DHMS' : $this.data('format'), 970 newLabels = (!$this.data('labels-short')) ? 971 ['Years', 'Months', 'Weeks', 'Days', 'Hours', 'Minutes', 'Seconds'] : 972 ['Years', 'Months', 'Weeks', 'Days', 'Hrs', 'Mins', 'Secs'], 973 newLabels1 = (!$this.data('labels-short')) ? 974 ['Year', 'Month', 'Week', 'Day', 'Hour', 'Minute', 'Second'] : 975 ['Year', 'Month', 'Week', 'Day', 'Hour', 'Min', 'Sec']; 976 977 var newDate; 978 979 // Split and created again for ie and edge 980 if (!$this.data('relative')) { 981 var untilDateArr = untilDate.split(", "), // data-until 2019, 10, 8 - yy,mm,dd 982 newDate = new Date(untilDateArr[0], untilDateArr[1] - 1, untilDateArr[2]); 983 } else { 984 newDate = untilDate; 985 } 986 987 $this.countdown({ 988 until: newDate, 989 format: dateFormat, 990 padZeroes: true, 991 compact: compact, 992 compactLabels: [' y', ' m', ' w', ' days, '], 993 timeSeparator: ' : ', 994 labels: newLabels, 995 labels1: newLabels1 996 }); 997 }); 998 //$('.product-countdown, .countdown').countdown('pause'); 999 } 1000 } 1001 1002 /** 1003 * priceSlider 1004 * 1005 * Create Price Slider 1006 * 1007 * @requires noUiSlider 1008 * @param {string} selector 1009 * @param {object} option 1010 */ 1011 Wolmart.priceSlider = function (selector, option) { 1012 if (typeof noUiSlider === 'object') { 1013 Wolmart.$(selector).each(function () { 1014 var self = this; 1015 1016 noUiSlider.create(self, $.extend(true, { 1017 start: [0, 400], 1018 connect: true, 1019 step: 1, 1020 range: { 1021 min: 0, 1022 max: 635 1023 } 1024 }, option)); 1025 1026 // Update Price Value 1027 self.noUiSlider.on('update', function (values, handle) { 1028 var values = values.map(function (value) { 1029 return '$' + parseInt(value); 1030 }); 1031 1032 $(self).parent().find('.filter-price-range').text(values.join(' - ')); 1033 }); 1034 }); 1035 } 1036 } 1037 1038 1039 /** 1040 * Wolmart Stickysidebar Options 1041 */ 1042 Wolmart.stickySidebarOptions = { 1043 autoInit: true, 1044 minWidth: 991, 1045 containerSelector: '.sticky-sidebar-wrapper', 1046 autoFit: true, 1047 activeClass: 'sticky-sidebar-fixed', 1048 top: 0, 1049 bottom: 0 1050 }; 1051 1052 /** 1053 * stickySidebar 1054 * 1055 * 1056 * @requires themeSticky 1057 * @param {string} selector 1058 */ 1059 Wolmart.stickySidebar = function (selector) { 1060 if ($.fn.themeSticky) { 1061 var top = 0; 1062 if (!$('.sticky-sidebar > .filter-actions').length && $(window).width() >= 992) { 1063 $('.sticky-content.fix-top').each(function (e) { 1064 if (!$(this).hasClass('sticky-toolbox')) { 1065 var $fixed = $(this).hasClass('fixed'); 1066 top += $(this).addClass('fixed').outerHeight(); 1067 $fixed || $(this).removeClass('fixed'); 1068 } 1069 }); 1070 } 1071 1072 Wolmart.$(selector).each(function () { 1073 var $this = $(this); 1074 $this.themeSticky($.extend({}, Wolmart.stickySidebarOptions, { padding: { top: top } }, Wolmart.parseOptions($this.attr('data-sticky-options')))); 1075 }); 1076 1077 function recalcSticky() { 1078 Wolmart.$(selector).trigger('recalc.pin'); 1079 $(window).trigger('appear.check'); 1080 } 1081 1082 setTimeout(recalcSticky, 300); 1083 Wolmart.$window.on('click', '.tab .nav-link', function () { 1084 setTimeout(recalcSticky); 1085 }); 1086 } 1087 } 1088 1089 /** 1090 * Wolmart Image Zoom Options 1091 */ 1092 Wolmart.zoomImageOptions = { 1093 responsive: true, 1094 borderSize: 0, 1095 zoomType: 'inner', 1096 onZoomIn: true, 1097 magnify: 1.1, 1098 }; 1099 Wolmart.zoomImageObjects = []; 1100 1101 /** 1102 * zoomImageOptions 1103 * 1104 * 1105 * @requires zoom 1106 * @param {jQuery} $el 1107 */ 1108 Wolmart.zoomImage = function ($el) { 1109 1110 if ($.fn.zoom && $el) { 1111 (('string' === typeof $el) ? $($el) : $el) 1112 .find('img').each(function () { 1113 var $this = $(this); 1114 Wolmart.zoomImageOptions.target = $this.parent(); 1115 Wolmart.zoomImageOptions.url = $this.attr('data-zoom-image'); 1116 $this.zoom(Wolmart.zoomImageOptions); 1117 Wolmart.zoomImageObjects.push($this); 1118 }); 1119 } 1120 } 1121 1122 /** 1123 * zoomImageOnResize 1124 * 1125 */ 1126 Wolmart.zoomImageOnResize = function () {
1127 Wolmart.zoomImageObjects.forEach(function ($img) { 1128 $img.each(function () { 1129 var zoom = $(this).data('zoom'); 1130 zoom && zoom.refresh(); 1131 }) 1132 }); 1133 } 1134 1135 1136 /** 1137 * lazyLoad 1138 * 1139 * 1140 * lazyload element 1141 * @param {string} selector 1142 * @param {boolean} force 1143 */ 1144 Wolmart.lazyLoad = function (selector, force) { 1145 function load() { 1146 this.setAttribute('src', this.getAttribute('data-src')); 1147 this.addEventListener('load', function () { 1148 this.style['padding-top'] = ''; 1149 this.classList.remove('lazy-img'); 1150 }); 1151 } 1152 1153 // Lazyload Images 1154 Wolmart.$(selector).find('.lazy-img').each(function () { 1155 if ('undefined' != typeof force && force) { 1156 load.call(this); 1157 } else { 1158 Wolmart.appear(this, load); 1159 } 1160 }); 1161 } 1162 1163 1164 /** 1165 * initPopup 1166 * 1167 */ 1168 Wolmart.initPopup = function (options, preset) { 1169 1170 // Newsletter popup 1171 if (Wolmart.$body.hasClass('home') && Wolmart.getCookie('hideNewsletterPopup') !== 'true') { 1172 setTimeout(function () { 1173 Wolmart.popup({ 1174 items: { 1175 src: ".newsletter-popup" 1176 }, 1177 type: 'inline', 1178 tLoading: '', 1179 mainClass: 'mfp-newsletter mfp-fadein-popup', 1180 callbacks: { 1181 beforeClose: function () { 1182 // if "do not show" is checked 1183 $('#hide-newsletter-popup')[0].checked && Wolmart.setCookie('hideNewsletterPopup', true, 7); 1184 } 1185 }, 1186 }); 1187 }, 7500); 1188 } 1189 1190 // Video popup 1191 Wolmart.$body.on('click', '.btn-iframe', function (e) { 1192 e.preventDefault(); 1193 Wolmart.popup({ 1194 items: { 1195 src: '<video src="' + $(e.currentTarget).attr('href') + '" autoplay loop controls>', 1196 type: "inline" 1197 }, 1198 mainClass: "mfp-video-popup" 1199 }, "video") 1200 }); 1201 1202 // Login popup 1203 Wolmart.$body 1204 .on('click', '.sign-in', function (e) { 1205 e.preventDefault(); 1206 1207 Wolmart.popup({ 1208 items: { 1209 src: $(e.currentTarget).attr('href') 1210 } 1211 }, 'login') 1212 }) 1213 1214 .on('click', '.register', function (e) { 1215 e.preventDefault(); 1216 Wolmart.popup({ 1217 items: { 1218 src: $(e.currentTarget).attr('href') 1219 }, 1220 callbacks: { 1221 ajaxContentAdded: function () { 1222 this.wrap.find('[href="#sign-up"]').click(); 1223 } 1224 } 1225 }, 'login') 1226 }); 1227 1228 } 1229 1230 /** 1231 * initNotificationAlert 1232 * 1233 */ 1234 Wolmart.initNotificationAlert = function () { 1235 if (Wolmart.$body.hasClass('has-notification')) { 1236 setTimeout(function () { 1237 Wolmart.$body.addClass('show-notification'); 1238 }, 5000); 1239 } 1240 } 1241 1242 /** 1243 * countTo 1244 * 1245 * 1246 * @requires jQuery.countTo 1247 * @param {String} selector 1248 */ 1249 Wolmart.countTo = function (selector) { 1250 if ($.fn.countTo) { 1251 Wolmart.$(selector).each(function () { 1252 Wolmart.appear(this, function () { 1253 var $this = $(this); 1254 setTimeout(function () { 1255 $this.countTo({ 1256 onComplete: function () { 1257 $this.addClass('complete'); 1258 } 1259 }) 1260 }, 300); 1261 }) 1262 }); 1263 } 1264 } 1265 1266 Wolmart.minipopupOption = { 1267 // info 1268 productClass: '', // ' product-cart', ' product-list-sm' 1269 imageSrc: '', 1270 imageLink: '#', 1271 name: '', 1272 nameLink: '#', // 'product.html', 1273 message: '', 1274 actionTemplate: '',
1275 isPurchased: false, 1276 1277 // option 1278 delay: 4000, // milliseconds 1279 space: 20, 1280 1281 // template 1282 1283 template: '<div class="minipopup-box">' + 1284 '<div class="product product-list-sm {{productClass}}">' + 1285 '<figure class="product-media">' + 1286 '<a href="{{imageLink}}">' + 1287 '<img src="{{imageSrc}}" alt="Product" width="80" height="90" />' + 1288 '</a></figure>' + 1289 '<div class="product-details">' + 1290 '<h4 class="product-name"><a href="{{nameLink}}">{{name}}</a></h4>' + 1291 '{{message}}</div></div>' + 1292 '<div class="product-action">{{actionTemplate}}</div></div>', 1293 1294 } 1295 /** 1296 * @class MiniPopup 1297 */ 1298 Wolmart.Minipopup = (function () { 1299 // Private Members 1300 var $area, 1301 offset = 0, 1302 boxes = [], 1303 isPaused = false, 1304 timers = [], 1305 timerId = false, 1306 timerInterval = 200, 1307 timerClock = function () { 1308 if (isPaused) { 1309 return; 1310 } 1311 for (var i = 0; i < timers.length; ++i) { 1312 (timers[i] -= timerInterval) <= 0 && this.close(i--); 1313 } 1314 } 1315 1316 // Public Members 1317 return { 1318 init: function () { 1319 // init area 1320 var self = this; 1321 var area = document.createElement('div'); 1322 area.className = "minipopup-area"; 1323 Wolmart.byClass('page-wrapper')[0].appendChild(area); 1324 $area = $(area); 1325 1326 // bind methods 1327 this.close = this.close.bind(this); 1328 timerClock = timerClock.bind(this); 1329 }, 1330 1331 open: function (options, callback) { 1332 var self = this, 1333 settings = $.extend(true, {}, Wolmart.minipopupOption, options), 1334 $box; 1335 1336 $box = $(Wolmart.parseTemplate(settings.template, settings)); 1337 self.space = settings.space; 1338 1339 // open 1340 var $img = $box.appendTo($area).css('top', - offset).find("img"); 1341 $img.length && $img.on('load', function () { 1342 offset += $box[0].offsetHeight + self.space; 1343 1344 $box.addClass('show'); 1345 if ($box.offset().top - window.pageYOffset < 0) { 1346 self.close(); 1347 $box.css('top', - offset + $box[0].offsetHeight + self.space); 1348 } 1349 $box.on('mouseenter', function () { self.pause() }) 1350 .on('mouseleave', function () { self.resume() }) 1351 .on('touchstart', function (e) { self.pause(); e.stopPropagation(); }) 1352 .on('mousedown', function () { 1353 $(this).addClass('focus'); 1354 }) 1355 .on('mouseup', function () { 1356 self.close($(this).index()); 1357 }); 1358 Wolmart.$body.on('touchstart', function () { 1359 self.resume(); 1360 }); 1361 1362 boxes.push($box); 1363 1364 if (!timers.length) { 1365 timerId = setInterval(timerClock, timerInterval); 1366 } 1367 timers.push(settings.delay); 1368 1369 callback && callback($box); 1370 }); 1371 }, 1372 1373 close: function (indexToClose) { 1374 var self = this, 1375 index = ('undefined' === typeof indexToClose) ? 0 : indexToClose, 1376 $box = boxes.splice(index, 1)[0]; 1377 1378 1379 // remove timer 1380 timers.splice(index, 1)[0]; 1381 1382 var height = $box[0].offsetHeight; 1383 1384 // remove box 1385 offset -= height + self.space; 1386 $box.removeClass('show'); 1387 setTimeout(function () { 1388 $box.remove(); 1389 }, 300); 1390 1391 // slide down other boxes
1392 boxes.forEach(function ($box, i) { 1393 if (i >= index && $box.hasClass('show')) { 1394 $box.stop(true, true).animate({ 1395 top: parseInt($box.css('top')) + height + 20 1396 }, 600, 'easeOutQuint'); 1397 } 1398 }); 1399 1400 // clear timer 1401 boxes.length || clearTimeout(timerId); 1402 }, 1403 1404 pause: function () { 1405 isPaused = true; 1406 }, 1407 1408 resume: function () { 1409 isPaused = false; 1410 } 1411 } 1412 })(); 1413 1414 /** 1415 * Sticky footer's header search toggle 1416 * @function headerSearchToggle 1417 * @param {String} selector 1418 */ 1419 1420 Wolmart.headerToggleSearch = function (selector) { 1421 var $search = Wolmart.$(selector); 1422 Wolmart.$body.on('click', '.hs-toggle .search-toggle', function (e) { 1423 e.preventDefault(); 1424 }); 1425 if ('ontouchstart' in document) { 1426 $search.find('.search-toggle').on('click', function (e) { 1427 $search.toggleClass('show'); 1428 }); 1429 Wolmart.$body.on('click', function (e) { 1430 $search.removeClass('show'); 1431 }) 1432 $search.on('click', function (e) { 1433 e.preventDefault(); 1434 e.stopPropagation(); 1435 }) 1436 } else { 1437 $search.find('.form-control').on('focusin', function (e) { 1438 $search.addClass('show'); 1439 }).on('focusout', function (e) { 1440 $search.removeClass('show'); 1441 }); 1442 } 1443 } 1444 Wolmart.scrollTo = function (target, duration) { 1445 var _duration = typeof duration == 'undefined' ? 0 : duration; 1446 var offset; 1447 1448 if (typeof target == 'number') { 1449 offset = target; 1450 } else { 1451 var $target = Wolmart.$(target); 1452 if (!$target.length || $target.css('display') == 'none') { 1453 return; 1454 } 1455 1456 var offset = $target.offset().top; 1457 var $wpToolbar = $('#wp-toolbar'); 1458 window.innerWidth > 600 && $wpToolbar.length && (offset -= $wpToolbar.parent().outerHeight()); 1459 $('.sticky-content.fix-top.fixed').each(function () { 1460 offset -= this.offsetHeight; 1461 }) 1462 } 1463 1464 $('html,body').stop().animate({ scrollTop: offset }, _duration); 1465 } 1466})(jQuery); 1467 1468(function ($) { 1469 /** 1470 * Wolmart Menu Plugins 1471 */ 1472 1473 // Private members 1474 var showMobileMenu = function (e) { 1475 e.preventDefault(); 1476 Wolmart.$body.addClass('mmenu-active'); 1477 $('.mobile-menu-toggle').attr('aria-expanded', 'true'); 1478 }; 1479 var hideMobileMenu = function (e) { 1480 e.preventDefault(); 1481 Wolmart.$body.removeClass('mmenu-active'); 1482 $('.mobile-menu-toggle').attr('aria-expanded', 'false'); 1483 }; 1484 1485 /** 1486 * Init Menu 1487 */ 1488 var Menu = { 1489 init: function () { 1490 this.initMenu(); 1491 this.initCategoryMenu(); 1492 this.initMobileMenu(); 1493 this.initFilterMenu(); 1494 this.initCollapsibleWidget(); 1495 this.initSubmenu(); 1496 }, 1497 initMenu: function () { 1498 // setup menu 1499 $('.menu li').each(function () { 1500 if (this.lastElementChild && ( 1501 this.lastElementChild.tagName === 'UL' || 1502 this.lastElementChild.classList.contains('megamenu')) && 1503 !$(this).parent().hasClass('megamenu') 1504 ) { 1505 this.classList.add('has-submenu'); 1506 !this.lastElementChild.classList.contains('megamenu') && this.lastElementChild.classList.add('submenu'); 1507 } 1508 }); 1509 1510 // calc megamenu position 1511 Wolmart.$window.on('resize', function () { 1512 $('.main-nav megamenu').each(function () { 1513 var $this = $(this), 1514 left = $this.offset().left, 1515 outerWidth = $this.outerWidth(), 1516 offset = (left + outerWidth) - (window.innerWidth - 20); 1517 if (offset > 0 && left > 20) { 1518 $this.css('margin-left', -offset); 1519 } 1520 }); 1521 }); 1522 }, 1523 initCategoryMenu: function () { 1524 var $dropdown = $('.category-dropdown'); 1525 if (!$dropdown.length) { 1526 return; 1527 } 1528 if ($dropdown.data('categoryMegamenuInit')) { 1529 return; 1530 } 1531 1532 var $header = $('.header-redesign'); 1533 var $panel = $('.category-megamenu-panel');
1534 var $overlay = $('.category-megamenu-overlay'); 1535 var $toggle = $('.category-toggle'); 1536 var closeTimer = null; 1537 var megamenuMinWidth = 768; 1538 1539 function isMegamenuViewport() { 1540 return window.innerWidth >= megamenuMinWidth; 1541 } 1542 1543 function escapeHtml(text) { 1544 return $('<div>').text(text).html(); 1545 } 1546 1547 function resetMegamenuLayout() { 1548 $panel.css('top', ''); 1549 $overlay.css('top', ''); 1550 } 1551 1552 function updateMegamenuLayout() { 1553 if (!$panel.length || !$panel.hasClass('is-open')) { 1554 return; 1555 } 1556 1557 var $anchor = $('.header-bottom.sticky-header'); 1558 if (!$anchor.length) { 1559 $anchor = $('.header-bottom'); 1560 } 1561 if (!$anchor.length) { 1562 return; 1563 } 1564 1565 var anchorBottom = $anchor[0].getBoundingClientRect().bottom; 1566 $panel.css({ top: anchorBottom + 'px' }); 1567 1568 var panelBottom = $panel[0].getBoundingClientRect().bottom; 1569 $overlay.css('top', panelBottom + 'px'); 1570 } 1571 1572 function clearActiveCategory() { 1573 $('.category-megamenu__item').removeClass('is-active'); 1574 var $content = $('.category-megamenu__content'); 1575 if ($content.length) { 1576 $content.attr('hidden', true); 1577 } 1578 $('.category-megamenu__col').empty(); 1579 } 1580 1581 function openMenu() { 1582 if (!isMegamenuViewport() || !$panel.length) { 1583 return; 1584 } 1585 clearTimeout(closeTimer); 1586 $header.addClass('category-megamenu-open'); 1587 $dropdown.addClass('show'); 1588 $panel.addClass('is-open').attr('aria-hidden', 'false'); 1589 $overlay.addClass('is-open').attr('aria-hidden', 'false'); 1590 $toggle.attr('aria-expanded', 'true'); 1591 updateMegamenuLayout(); 1592 } 1593 1594 function closeMenu() { 1595 closeTimer = setTimeout(function () { 1596 $header.removeClass('category-megamenu-open'); 1597 $dropdown.removeClass('show'); 1598 $panel.removeClass('is-open').attr('aria-hidden', 'true'); 1599 $overlay.removeClass('is-open').attr('aria-hidden', 'true'); 1600 $toggle.attr('aria-expanded', 'false'); 1601 clearActiveCategory(); 1602 resetMegamenuLayout(); 1603 }, 300); 1604 } 1605 1606 function fillSubcolumns($item) { 1607 var raw = $item.attr('data-subcategories'); 1608 if (!raw) { 1609 return; 1610 } 1611 var children; 1612 try { 1613 children = JSON.parse(raw); 1614 } catch (e) { 1615 return; 1616 } 1617 if (!children.length) { 1618 return; 1619 } 1620 1621 var mid = Math.ceil(children.length / 2); 1622 var col1 = children.slice(0, mid); 1623 var col2 = children.slice(mid); 1624 var $col1 = $('.category-megamenu__col[data-col="1"]'); 1625 var $col2 = $('.category-megamenu__col[data-col="2"]'); 1626 1627 $col1.empty(); 1628 $col2.empty(); 1629 1630 col1.forEach(function (child) { 1631 $col1.append('<li><a href="' + escapeHtml(child.url) + '">' + escapeHtml(child.text) + '</a></li>'); 1632 }); 1633 col2.forEach(function (child) { 1634 $col2.append('<li><a href="' + escapeHtml(child.url) + '">' + escapeHtml(child.text) + '</a></li>'); 1635 }); 1636 1637 $('.category-megamenu__content').removeAttr('hidden'); 1638 updateMegamenuLayout(); 1639 } 1640 1641 if ($panel.length) { 1642 var $hoverZone = $dropdown.add($panel); 1643 1644 $hoverZone.on('mouseenter', function () { 1645 if (isMegamenuViewport()) { 1646 openMenu(); 1647 } 1648 }); 1649 1650 $hoverZone.on('mouseleave', function () { 1651 if (isMegamenuViewport()) { 1652 closeMenu(); 1653 } 1654 }); 1655 1656 $panel.on('mouseenter', '.category-megamenu__item--has-children', function () { 1657 var $item = $(this); 1658 $('.category-megamenu__item').removeClass('is-active'); 1659 $item.addClass('is-active'); 1660 fillSubcolumns($item); 1661 }); 1662 1663 $panel.on('mouseenter', '.category-megamenu__item:not(.category-megamenu__item--has-children)', function () { 1664 $('.category-megamenu__item').removeClass('is-active'); 1665 $(this).addClass('is-active'); 1666 $('.category-megamenu__content').attr('hidden', true); 1667 $('.category-megamenu__col').empty(); 1668 }); 1669 1670 $toggle.on('click', function (e) { 1671 e.preventDefault(); 1672 if (!isMegamenuViewport()) { 1673 return; 1674 } 1675 if ($panel.hasClass('is-open')) { 1676 clearTimeout(closeTimer); 1677 $header.removeClass('category-megamenu-open'); 1678 $dropdown.removeClass('show'); 1679 $panel.removeClass('is-open').attr('aria-hidden', 'true'); 1680 $overlay.removeClass('is-open').attr('aria-hidden', 'true'); 1681 $toggle.attr('aria-expanded', 'false'); 1682 clearActiveCategory(); 1683 resetMegamenuLayout(); 1684 } else { 1685 openMenu(); 1686 } 1687 }); 1688 1689 $(document).on('keydown.categoryMegamenu', function (e) { 1690 if (e.key === 'Escape' && $panel.hasClass('is-open')) { 1691 clearTimeout(closeTimer); 1692 $header.removeClass('category-megamenu-open'); 1693 $dropdown.removeClass('show'); 1694 $panel.removeClass('is-open').attr('aria-hidden', 'true'); 1695 $overlay.removeClass('is-open').attr('aria-hidden', 'true'); 1696 $toggle.attr('aria-expanded', 'false'); 1697 clearActiveCategory(); 1698 resetMegamenuLayout(); 1699 } 1700 }); 1701 1702 Wolmart.$window.on('resize.categoryMegamenu scroll.categoryMegamenu', function () { 1703 if ($panel.hasClass('is-open')) { 1704 updateMegamenuLayout(); 1705 } 1706 if (!isMegamenuViewport()) { 1707 clearTimeout(closeTimer); 1708 $header.removeClass('category-megamenu-open'); 1709 $dropdown.removeClass('show'); 1710 $panel.removeClass('is-open').attr('aria-hidden', 'true'); 1711 $overlay.removeClass('is-open').attr('aria-hidden', 'true'); 1712 $toggle.attr('aria-expanded', 'false'); 1713 clearActiveCategory(); 1714 resetMegamenuLayout(); 1715 } 1716 }); 1717 1718 $dropdown.data('categoryMegamenuInit', true); 1719 return; 1720 } 1721 1722 var $box = $dropdown.find('.dropdown-box'); 1723 if ($box.length) { 1724 var top = $('.main').offset().top + $box[0].offsetHeight; 1725 1726 if (window.pageYOffset <= top || window.innerWidth < desktopMinWidth) { 1727 $dropdown.removeClass('show'); 1728 } 1729 1730 window.addEventListener('scroll', function () { 1731 if (window.pageYOffset <= top && window.innerWidth >= desktopMinWidth) { 1732 $dropdown.removeClass('show'); 1733 } 1734 }, { passive: true }); 1735 1736 $('.category-toggle').on('click', function (e) { 1737 e.preventDefault(); 1738 }); 1739 1740 $dropdown.on('mouseover', function () { 1741 if ($dropdown.hasClass('menu-fixed') && window.pageYOffset > top && window.innerWidth >= desktopMinWidth) { 1742 $dropdown.addClass('show'); 1743 } else if (!$dropdown.hasClass('menu-fixed') && window.innerWidth >= desktopMinWidth) { 1744 $dropdown.addClass('show'); 1745 } 1746 }); 1747 1748 $dropdown.on('mouseleave', function () { 1749 if ($dropdown.hasClass('menu-fixed') && window.pageYOffset > top && window.innerWidth >= desktopMinWidth) { 1750 $dropdown.removeClass('show'); 1751 } else if (!$dropdown.hasClass('menu-fixed') && window.innerWidth >= desktopMinWidth) { 1752 $dropdown.removeClass('show'); 1753 } 1754 }); 1755 } 1756 1757 if ($dropdown.hasClass('with-sidebar')) { 1758 var sidebar = Wolmart.byClass('sidebar'); 1759 if (sidebar.length) { 1760 $dropdown.find('.dropdown-box').css('width', sidebar[0].offsetWidth - 20); 1761 1762 Wolmart.$window.on('resize', function () { 1763 $dropdown.find('.dropdown-box').css('width', (sidebar[0].offsetWidth - 20)); 1764 }); 1765 } 1766 } 1767 1768 $dropdown.data('categoryMegamenuInit', true); 1769 }, 1770 initMobileMenu: function () { 1771 $('.mobile-menu li, .toggle-menu li').each(function () { 1772 if (this.lastElementChild && ( 1773 this.lastElementChild.tagName === 'UL' || 1774 this.lastElementChild.classList.contains('megamenu')) 1775 ) { 1776 var span = document.createElement('span'); 1777 span.className = "toggle-btn"; 1778 this.firstElementChild.appendChild(span); 1779 // this.firstElementChild.insertAdjacentHTML('beforeend', '<span class="toggle-btn"></span>' ); 1780 } 1781 }); 1782 $('.mobile-menu-toggle').on('click', showMobileMenu); 1783 $('.mobile-menu-overlay').on('click', hideMobileMenu); 1784 $('.mobile-menu-close').on('click', hideMobileMenu); 1785 $('.mobile-menu-redesign').on('click', '.mobile-menu-redesign__chevron', function (e) { 1786 e.preventDefault(); 1787 e.stopPropagation(); 1788 var $li = $(this).closest('li'); 1789 $li.children('ul').slideToggle(300); 1790 $li.toggleClass('show'); 1791 }); 1792 Wolmart.$window.on('resize', hideMobileMenu); 1793 }, 1794 initFilterMenu: function () { 1795 $('.search-ul li').each(function () { 1796 if (this.lastElementChild && this.lastElementChild.tagName === 'UL') { 1797 var i = document.createElement('i'); 1798 i.className = "la la-angle-down"; 1799 this.classList.add('with-ul'); 1800 this.firstElementChild.appendChild(i); 1801 } 1802 }); 1803 $('.with-ul > a i, .toggle-btn').on('click', function (e) { 1804 var $this = $(this); 1805 $(this).parent().next().slideToggle(300).parent().toggleClass("show"); 1806 e.preventDefault(); 1807 }); 1808 }, 1809 initCollapsibleWidget: function () { 1810 // Add toggle span 1811 $('.widget-collapsible .widget-title').each(function () { 1812 var span = document.createElement('span'); 1813 span.className = 'toggle-btn'; 1814 this.appendChild(span); 1815 }); 1816 1817 // Slide Toggle 1818 $('.widget-collapsible .widget-title').on('click', function (e) { 1819 var $this = $(this), 1820 $body = $this.siblings('.widget-body'); 1821 1822 $this.hasClass('collapsed') || $body.css('display', 'block'); 1823 1824 $body.stop().slideToggle(300); 1825 $this.toggleClass('collapsed'); 1826 1827 // if collapsible widget exists in sticky sidebar 1828 setTimeout(function () { 1829 $('.sticky-sidebar').trigger('recalc.pin'); 1830 }, 300); 1831 }); 1832 }, 1833 initSubmenu: function () { 1834 $('.submenu-toggle-btn').on('click', function (e) { 1835 $(this).parent().parent().toggleClass("show"); 1836 e.preventDefault(); 1837 }); 1838 Wolmart.$window.on('resize', function () { 1839 if (window.innerWidth >= 1200) { 1840 $('.submenu-toggle-btn').parent().parent().removeClass('show'); 1841 } 1842 }); 1843 } 1844 } 1845 1846 Wolmart.menu = Menu; 1847 1848 $(function () { 1849 Wolmart.menu.initCategoryMenu(); 1850 }); 1851})(jQuery); 1852 1853/** 1854 * Wolmart Dependent Plugin - Slider 1855 * 1856 */ 1857 1858(function ($) { 1859 function Slider($el, options) { 1860 return this.init($el, options); 1861 } 1862 1863 // Private Properties 1864 var onInitialize = function (e) { 1865 var wrapperEl = this.wrapperEl; 1866 var cls = wrapperEl.getAttribute('class'); 1867 var match = cls.match(/row|gutter\-\w\w|cols\-\d|cols\-\w\w-\d/g); 1868 if (match) { 1869 wrapperEl.setAttribute('class', cls.replace(/row|gutter\-\w\w|cols\-\d|cols\-\w\w-\d/g, '').replace(/\s+/, ' ')); 1870 }
1871 if (wrapperEl.classList.contains("animation-slider")) { 1872 var els = wrapperEl.children, 1873 len = els.length; 1874 for (var i = 0; i < len; ++i) { 1875 els[i].setAttribute('data-index', i + 1); 1876 } 1877 } 1878 } 1879 var onInitialized = function (e) { 1880 var els = this.firstElementChild.firstElementChild.children, 1881 i, 1882 len = els.length; 1883 for (i = 0; i < len; ++i) { 1884 if (!els[i].classList.contains('active')) { 1885 var animates = Wolmart.byClass('appear-animate', els[i]), 1886 j; 1887 for (j = animates.length - 1; j >= 0; --j) { 1888 animates[j].classList.remove('appear-animate'); 1889 } 1890 } 1891 } 1892 } 1893 var onTranslated = function (e) { 1894 $(window).trigger('appear.check'); 1895 1896 // Video Play 1897 var $el = $(e.currentTarget), 1898 $activeVideos = $el.find('.swiper-slide.active video'); 1899 1900 $el.find('.swiper-slide:not(.swiper-slide-active) video').each(function () { 1901 if (!this.paused) { 1902 $el.trigger('autoplayStart'); 1903 } 1904 this.pause(); 1905 this.currentTime = 0; 1906 }); 1907 1908 if ($activeVideos.length) { 1909 if (true === $el.data('slider').options.autoplay) { 1910 $el.trigger('autoplayStop'); 1911 } 1912 $activeVideos.each(function () { 1913 this.paused && this.play(); 1914 }); 1915 } 1916 } 1917 var onSliderInitialized = function () { 1918 var self = this, 1919 $el = $(this.wrapperEl); 1920 1921 // carousel content animation 1922 $el.find('.swiper-slide-active .slide-animate').each(function () { 1923 var $animation_item = $(this), 1924 settings = $.extend(true, {}, 1925 Wolmart.animationOptions, 1926 Wolmart.parseOptions($animation_item.data('animation-options')) 1927 ), 1928 duration = settings.duration, 1929 delay = settings.delay, 1930 aniName = settings.name; 1931 1932 setTimeout(function () { 1933 $animation_item.css('animation-duration', duration); 1934 $animation_item.css('animation-delay', delay); 1935 $animation_item.addClass(aniName); 1936 1937 if ($animation_item.hasClass('maskLeft')) { 1938 $animation_item.css('width', 'fit-content'); 1939 var width = $animation_item.width(); 1940 $animation_item.css('width', 0).css( 1941 'transition', 1942 'width ' + (duration ? duration : '0.75s') + ' linear ' + (delay ? delay : '0s')); 1943 $animation_item.css('width', width); 1944 } 1945 duration = duration ? duration : '0.75s'; 1946 var temp = Wolmart.requestTimeout(function () { 1947 $animation_item.addClass('show-content'); 1948 }, (delay ? Number((delay).slice(0, -1)) * 1000 + 200 : 200)); 1949 1950 self.timers.push(temp); 1951 }, 300); 1952 }); 1953 } 1954 var onSliderResized = function (e) { 1955 $(this.wrapperEl).find('.swiper-slide-active .slide-animate').each(function () { 1956 var $animation_item = $(this); 1957 $animation_item.addClass('show-content'); 1958 $animation_item.attr('style', ''); 1959 }); 1960 } 1961 var onSliderTranslate = function (e) { 1962 var self = this, 1963 $el = $(this.wrapperEl); 1964 self.translateFlag = 1; 1965 self.prev = self.next; 1966 $el.find('.swiper-slide .slide-animate').each(function () { 1967 var $animation_item = $(this), 1968 settings = $.extend(true, {}, Wolmart.animationOptions, Wolmart.parseOptions($animation_item.data('animation-options'))); 1969 $animation_item.removeClass(settings.name); 1970 }); 1971 } 1972 var onSliderTranslated = function (e) { 1973 var self = this, 1974 $el = $(this.wrapperEl); 1975 if (1 == self.translateFlag) { 1976 self.next = this.slider.activeIndex; 1977 $el.find('.show-content').removeClass('show-content'); 1978 if (self.prev != self.next) { 1979 $el.find('.show-content').removeClass('show-content'); 1980 /* clear all animations that are running. */
1981 if ($el.hasClass("animation-slider")) { 1982 for (var i = 0; i < self.timers.length; i++) { 1983 Wolmart.deleteTimeout(self.timers[i]); 1984 } 1985 self.timers = []; 1986 } 1987 $el.find('.swiper-slide-active .slide-animate').each(function () { 1988 var $animation_item = $(this), 1989 settings = $.extend(true, {}, Wolmart.animationOptions, Wolmart.parseOptions($animation_item.data('animation-options'))), 1990 duration = settings.duration, 1991 delay = settings.delay, 1992 aniName = settings.name; 1993 1994 $animation_item.css('animation-duration', duration); 1995 $animation_item.css('animation-delay', delay); 1996 $animation_item.css('transition-property', 'visibility, opacity'); 1997 $animation_item.css('transition-delay', delay); 1998 $animation_item.css('transition-duration', duration); 1999 $animation_item.addClass(aniName); 2000 2001 duration = duration ? duration : '0.75s'; 2002 2003 var temp = Wolmart.requestTimeout(function () { 2004 $animation_item.css('transition-property', ''); 2005 $animation_item.css('transition-delay', ''); 2006 $animation_item.css('transition-duration', ''); 2007 $animation_item.addClass('show-content'); 2008 self.timers.splice(self.timers.indexOf(temp), 1) 2009 }, (delay ? Number((delay).slice(0, -1)) * 1000 + Number((duration).slice(0, -1)) * 500 : Number((duration).slice(0, -1)) * 500)); 2010 self.timers.push(temp); 2011 }); 2012 } else { 2013 $el.find('.swiper-slide').eq(this.slider.activeIndex).find('.slide-animate').addClass('show-content'); 2014 } 2015 self.translateFlag = 0; 2016 } 2017 } 2018 2019 // Public Properties 2020 Slider.defaults = { 2021 slidesPerView: 1, 2022 speed: 300 2023 } 2024 2025 Slider.presets = { 2026 'product-thumbs-wrap': { 2027 slidesPerView: 4, 2028 spaceBetween: 10, 2029 freeMode: true, 2030 watchSlidesVisibility: true, 2031 watchSlidesProgress: true, 2032 freeModeSticky: true 2033 } 2034 } 2035 2036 Slider.prototype.init = function ($el, options) { 2037 this.timers = []; 2038 this.translateFlag = 0; 2039 this.prev = 0; 2040 this.next = 0; 2041 this.container = $el[0]; 2042 this.wrapperEl = $el.children()[0]; 2043 var $navigationNext = $el.children('.swiper-button-next'), 2044 $navigationPrev = $el.children('.swiper-button-prev'), 2045 $pagination = $el.children('.swiper-pagination'), 2046 $dotscontainer = $el.children('.custom-dots'); 2047 2048 if ($el.data('slider')) { 2049 return; 2050 } 2051 2052 Wolmart.lazyLoad($el, true); 2053 var classes = $el.attr('class').split(' '), 2054 settings = $.extend(true, {}, Slider.defaults); 2055 2056 // extend preset options 2057 classes.forEach(function (className) { 2058 var preset = Slider.presets[className]; 2059 preset && $.extend(true, settings, preset); 2060 }); 2061 2062 // navigation and pagination 2063 $navigationNext.length && $.extend(true, settings, { 2064 navigation: { 2065 nextEl: $navigationNext[0] 2066 } 2067 }); 2068 $navigationPrev.length && $.extend(true, settings, { 2069 navigation: { 2070 prevEl: $navigationPrev[0] 2071 } 2072 }); 2073 $pagination.length && $.extend(true, settings, { 2074 pagination: { 2075 el: $pagination[0], 2076 clickable: true 2077 } 2078 }); 2079 2080 // video 2081 var $videos = $el.find('video'); 2082 $videos.each(function () { 2083 this.loop = false; 2084 }); 2085 2086 // extend user options 2087 $.extend(true, settings, Wolmart.parseOptions($el.attr('data-swiper-options')), options); 2088 2089 // init 2090 onInitialize.call(this); // remove grid classes from swiper-wrapper 2091 2092 this.slider = new Swiper(this.container, settings); 2093 $el.data('slider', this.slider); 2094 2095 $el.trigger('initialized.slider', this.slider); 2096 2097 this.slider.on('afterInit', onInitialized) 2098 .on('transitionEnd', onTranslated); 2099 2100 // if animation slider
2101 if ($el.hasClass('animation-slider')) { 2102 onSliderInitialized.call(this); 2103 } 2104 $el.hasClass('animation-slider') && 2105 this.slider.on('resize', onSliderResized) 2106 .on('transitionStart', onSliderTranslate.bind(this)) 2107 .on('transitionEnd', onSliderTranslated.bind(this)); 2108 2109 // if slider has custom dots container 2110 if ($dotscontainer.length) { 2111 this.slider.on('transitionEnd', function () { 2112 var curIndex = this.activeIndex; 2113 $dotscontainer.children('a:nth-child(' + (++curIndex) + ')').addClass('active').siblings().removeClass('active'); 2114 }); 2115 $dotscontainer.children('a').on('click', function (e) { 2116 e.preventDefault(); 2117 2118 var $this = $(this); 2119 2120 if (!$this.hasClass('active')) { 2121 var index = $this.index(), 2122 $slider = $this.closest('.swiper-container').data('slider'); 2123 2124 $slider.slideTo(index); 2125 $this.addClass('active').siblings().removeClass('active'); 2126 } 2127 }); 2128 } 2129 } 2130 2131 Wolmart.slider = function (selector, options = {}, createDirectly = false) { 2132 Wolmart.$(selector).each(function () { 2133 var $this = $(this); 2134 2135 createDirectly ? new Slider($this, options) : Wolmart.call(function () { 2136 new Slider($this, options); 2137 }); 2138 }); 2139 } 2140 2141 function getHomeProductsPageInfo(swiper) { 2142 var group = swiper.params.slidesPerGroup || 1; 2143 var useGroupPaging = swiper.params.slidesPerView === 'auto' || group > 1; 2144 2145 if (!useGroupPaging && swiper.snapGrid && swiper.snapGrid.length) { 2146 var totalPages = swiper.snapGrid.length; 2147 var currentPage = (typeof swiper.snapIndex !== 'undefined' ? swiper.snapIndex : swiper.activeIndex) + 1; 2148 2149 if (currentPage > totalPages) { 2150 currentPage = totalPages; 2151 } 2152 2153 return { 2154 current: currentPage, 2155 total: totalPages 2156 }; 2157 } 2158 2159 var totalPages = Math.max(1, Math.ceil(swiper.slides.length / group)); 2160 var currentPage = Math.min(totalPages, Math.floor(swiper.activeIndex / group) + 1); 2161 2162 return { 2163 current: currentPage, 2164 total: totalPages 2165 }; 2166 } 2167 2168 function getHomeCarouselSegmentClass($progress) { 2169 if ($progress.hasClass('home-promo__progress')) { 2170 return 'home-promo__progress-segment'; 2171 } 2172 2173 if ($progress.hasClass('home-news__progress')) { 2174 return 'home-news__progress-segment'; 2175 } 2176 2177 return 'home-products__progress-segment'; 2178 } 2179 2180 function updateHomeProductsPanel($panel, swiper) { 2181 if (!$panel.length || !swiper) { 2182 return; 2183 } 2184 2185 var info = getHomeProductsPageInfo(swiper); 2186 var $progress = $panel.find('.home-products__progress, .home-promo__progress, .home-news__progress'); 2187 var segmentSelector = '.home-products__progress-segment, .home-promo__progress-segment, .home-news__progress-segment'; 2188 var $segments = $progress.find(segmentSelector); 2189 2190 if ($segments.length !== info.total) { 2191 $progress.empty(); 2192 2193 for (var i = 0; i < info.total; i++) { 2194 $progress.append('<span class="' + getHomeCarouselSegmentClass($progress) + '"></span>'); 2195 } 2196 2197 $segments = $progress.find(segmentSelector); 2198 } 2199 2200 $panel.find('.home-products__fraction, .home-promo__fraction, .home-news__fraction').text(info.current + ' / ' + info.total); 2201 $segments.removeClass('home-products__progress-segment--active home-promo__progress-segment--active home-news__progress-segment--active') 2202 .eq(info.current - 1) 2203 .addClass(getHomeCarouselSegmentClass($progress) + '--active'); 2204 $panel.find('.home-products__arrow--prev, .home-promo__arrow--prev, .home-news__arrow--prev').toggleClass('swiper-button-disabled', swiper.isBeginning); 2205 $panel.find('.home-products__arrow--next, .home-promo__arrow--next, .home-news__arrow--next').toggleClass('swiper-button-disabled', swiper.isEnd); 2206 } 2207 2208 function bindHomeProductsSlider($container) { 2209 var swiper = $container.data('slider'); 2210 2211 if (!swiper || $container.data('homeProductsBound')) { 2212 return; 2213 } 2214 2215 $container.data('homeProductsBound', true); 2216 2217 var $panel = $container.closest('.home-products__panel, .home-promo__carousel, .home-news__slider'); 2218 var updatePager = function () { 2219 updateHomeProductsPanel($panel, swiper); 2220 }; 2221 2222 updatePager(); 2223 2224 swiper.on('init slideChange slideChangeTransitionEnd resize breakpoint snapIndexChange', updatePager); 2225 2226 $panel.find('.home-products__arrow--prev, .home-promo__arrow--prev, .home-news__arrow--prev').off('click.homeProducts').on('click.homeProducts', function (e) { 2227 e.preventDefault(); 2228 swiper.slidePrev(); 2229 }); 2230 2231 $panel.find('.home-products__arrow--next, .home-promo__arrow--next, .home-news__arrow--next').off('click.homeProducts').on('click.homeProducts', function (e) { 2232 e.preventDefault(); 2233 swiper.slideNext(); 2234 }); 2235 } 2236 2237 Wolmart.initHomeProducts = function () { 2238 $('.home-products .swiper-container, .home-promo .swiper-container, .home-news .swiper-container').each(function () { 2239 bindHomeProductsSlider($(this)); 2240 }); 2241 } 2242 2243 Wolmart.setupHomeProducts = function () { 2244 Wolmart.$body.off('initialized.slider.homeProducts', '.home-products .swiper-container, .home-promo .swiper-container, .home-news .swiper-container') 2245 .on('initialized.slider.homeProducts', '.home-products .swiper-container, .home-promo .swiper-container, .home-news .swiper-container', function () { 2246 bindHomeProductsSlider($(this)); 2247 }); 2248 2249 $('.home-products__tabs-nav .nav-link').off('click.homeProducts').on('click.homeProducts', function () { 2250 var selector = $(this).attr('href'); 2251 var $panel = $(selector); 2252 2253 window.setTimeout(function () { 2254 var $container = $panel.find('.swiper-container'); 2255 var swiper = $container.data('slider'); 2256 2257 if (swiper) {
2258 swiper.update(); 2259 updateHomeProductsPanel($panel, swiper); 2260 } 2261 }, 0); 2262 }); 2263 } 2264 2265 Wolmart.slider.pgToggle = function () { 2266 $(".swiper-container:not([class*='pg-']) .swiper-pagination").each(function () { 2267 var $this = $(this); 2268 if ($this.find('*').length <= 1) 2269 $this.css('display', 'none'); 2270 else 2271 $this.css('display', 'block'); 2272 }); 2273 } 2274})(jQuery); 2275 2276/** 2277 * Wolmart Plugin - Sidebar 2278 * 2279 * sidebar active class will be added to body tag: "sidebar class" + "-active" 2280 */ 2281 2282(function ($) { 2283 'use strict'; 2284 2285 function Sidebar(name) { 2286 return this.init(name); 2287 } 2288 var onResizeNavigationStyle = function () { 2289 if (window.innerWidth < 992) { 2290 this.$sidebar.find('.sidebar-content').removeAttr('style'); 2291 this.$sidebar.find('.sidebar-content').attr('style', ''); 2292 this.$sidebar.find('.toolbox').children(':not(:first-child)').removeAttr('style'); 2293 } 2294 } 2295 2296 Sidebar.prototype.init = function (name) { 2297 var self = this; 2298 2299 self.name = name; 2300 self.$sidebar = $('.' + name); 2301 self.isNavigation = false; 2302 2303 // If sidebar exists 2304 if (self.$sidebar.length) { 2305 2306 // check if navigation style 2307 self.isNavigation = self.$sidebar.hasClass('sidebar-fixed') && self.$sidebar.parent().hasClass('toolbox-wrap'); 2308 2309 if (self.isNavigation) { 2310 onResizeNavigationStyle = onResizeNavigationStyle.bind(this); 2311 Wolmart.$window.on('resize', onResizeNavigationStyle); 2312 } 2313 2314 Wolmart.$window.on('resize', function (e) { 2315 if (Wolmart.windowResized(e.timeStamp)) { 2316 Wolmart.$body.removeClass(name + '-active'); 2317 } 2318 }); 2319 2320 // Register toggle event 2321 self.$sidebar.find('.sidebar-toggle, .sidebar-toggle-btn') 2322 .add(name === 'sidebar' ? '.left-sidebar-toggle' : '.' + name + '-toggle') 2323 .on('click', function (e) { 2324 self.toggle(); 2325 $(this).blur(); 2326 e.preventDefault(); 2327 }); 2328 2329 // Register close event 2330 self.$sidebar.find('.sidebar-overlay, .sidebar-close') 2331 .on('click', function (e) { 2332 Wolmart.$body.removeClass(name + '-active'); 2333 e.preventDefault(); 2334 }); 2335 } 2336 return false; 2337 } 2338 2339 Sidebar.prototype.toggle = function () { 2340 var self = this; 2341 var minwidth = 992; 2342 //if Xl sidebar 2343 if (self.$sidebar.hasClass('sidebar-switch-xl')) { 2344 minwidth = 1200; 2345 } 2346 // if fixed sidebar 2347 if (window.innerWidth >= minwidth && self.$sidebar.hasClass('sidebar-fixed')) { 2348 2349 // is closed ? 2350 var isClosed = self.$sidebar.hasClass('closed'); 2351 2352 // if navigation style's sidebar 2353 if (self.isNavigation) { 2354 2355 isClosed || self.$sidebar.find('.filter-clean').hide(); 2356 2357 self.$sidebar.siblings('.toolbox').children(':not(:first-child)').fadeToggle('fast'); 2358 2359 self.$sidebar 2360 .find('.sidebar-content') 2361 .stop() 2362 .animate( 2363 { 2364 'height': 'toggle', 2365 'margin-bottom': isClosed ? 'toggle' : -6 2366 }, function () { 2367 $(this).css('margin-bottom', ''); 2368 isClosed && self.$sidebar.find('.filter-clean').fadeIn('fast'); 2369 } 2370 ); 2371 } 2372 2373 // If shop sidebar 2374 if (self.$sidebar.hasClass('shop-sidebar')) { 2375 2376 // change column 2377 var $wrapper = $('.main-content .product-wrapper'); 2378 if ($wrapper.length) { 2379 if ($wrapper.hasClass('product-lists')) { 2380 2381 // if list type, toggle 2 cols or 1 col 2382 $wrapper.toggleClass('row cols-xl-2', !isClosed); 2383 } else { 2384 2385 } 2386 } 2387 } 2388 } else { 2389 self.$sidebar.find('.sidebar-overlay .sidebar-close').css('margin-left', - (window.innerWidth - document.body.clientWidth)); 2390 2391 // activate sidebar 2392 Wolmart.$body 2393 .toggleClass(self.name + '-active') 2394 .removeClass('closed'); 2395 } 2396 2397 setTimeout(function () { 2398 $(window).trigger('appear.check'); 2399 }, 400); 2400 } 2401 2402 Wolmart.sidebar = function (name) { 2403 return new Sidebar().init(name); 2404 } 2405})(jQuery); 2406 2407 2408/** 2409 * Wolmart Dependent Plugin - Shop 2410 * 2411 * @requires 2412 */ 2413(function ($) { 2414 2415 var initSelectMenu = function () { 2416 2417 var selector = '.select-menu'; 2418 2419 // show or hide select menu 2420 Wolmart.$body.on('mousedown', '.select-menu', function (e) { 2421 var $selectMenu = $(e.currentTarget), 2422 $target = $(e.target), 2423 isOpened = $selectMenu.hasClass('opened'); 2424 2425 // close all select menu 2426 $('.select-menu').removeClass('opened'); 2427 2428 if ($selectMenu.is($target.parent())) { // if select menu toggle is clicked 2429 !isOpened && $selectMenu.addClass('opened'); 2430 2431 e.stopPropagation(); 2432 } else { // if select menu item is clicked 2433 2434 $target.parent().toggleClass('active'); // add active class to li tag 2435 2436 if ($target.parent().hasClass('active')) { 2437 2438 // if only clean all button remains 2439 if ($('.selected-items').children().length < 2) { 2440 // show selected items 2441 $('.selected-items').show(); 2442 } 2443 2444 // add selected item 2445 $('<a href="#" class="selected-item">' + $target.text().split('(')[0] + '<i class="w-icon-times-solid"></i></a>') 2446 .insertBefore('.selected-items .filter-clean') 2447 .hide().fadeIn() // hide and show item with effect - fadeIn 2448 .data('link', $target.parent()); 2449 } else { 2450 // remove selected item from selected items 2451 $('.selected-items > .selected-item').filter(function (i, el) { 2452 return el.innerText == $target.text().split('(')[0]; 2453 }).fadeOut(function () { 2454 $(this).remove(); 2455 2456 // if only clean all buttpn remains 2457 if ($('.selected-items').children().length < 2) { 2458 // then hide selected items 2459 $('.selected-items').hide(); 2460 } 2461 }) 2462 } 2463 } 2464 }) 2465 .on('click', '.selected-item', function (e) { 2466 var $item = $(this), 2467 $link = $item.data('link'); 2468 if ($link) { 2469 $link.removeClass('active') 2470 .fadeOut(function () { 2471 $item.remove(); 2472 }); 2473 } 2474 e.preventDefault(); 2475 }); 2476 2477 // Clean selected items 2478 $('.selected-items .filter-clean').on('click', function (e) { 2479 var $clean = $(this); 2480 $clean.siblings().each(function () { 2481 var $link = $(this).data('link'); 2482 $link && $link.removeClass('active'); 2483 }); 2484 $clean.parent().fadeOut(function () { 2485 $clean.siblings().remove(); 2486 }); 2487 e.preventDefault(); 2488 }); 2489 2490 // $('.filter-clean').on('click', function (e) { 2491 // $('.shop-sidebar .filter-items .active').removeClass('active'); 2492 // e.preventDefault(); 2493 // }); 2494 2495 Wolmart.$body.on('click', '.select-menu a', function (e) { 2496 e.preventDefault(); 2497 }); 2498 2499 Wolmart.$body.on('click', '.selected-item i', function (e) { 2500 $(e.currentTarget).parent().fadeOut(function () { 2501 var $this = $(this), 2502 $link = $this.data('link'); 2503 2504 $link && $link.toggleClass('active'); 2505 $this.remove(); 2506 2507 // if only clean all button remains 2508 if ($('.select-items').children().length < 2) { 2509 // then hide select-items 2510 $('.select-items').hide(); 2511 } 2512 }); 2513 2514 e.preventDefault(); 2515 }); 2516 2517 // if click outside of select menu, hide select menu 2518 Wolmart.$body.on('mousedown', function (e) { 2519 $('.select-menu').removeClass('opened'); 2520 }); 2521 2522 // Wolmart.$body.on('click', '.filter-items a', function (e) { 2523 // var $ul = $(this).closest('.filter-items'); 2524 // if (!$ul.hasClass('search-ul') && !$ul.parent().hasClass('select-menu')) { 2525 // $(this).parent().toggleClass('active'); 2526 // e.preventDefault(); 2527 // } 2528 // }); 2529 } 2530 2531 var initProductCartAction = function () { 2532 var selector = '.product:not(.product-select) .btn-cart, .product-popup .btn-cart, .home .product-single .btn-cart'; 2533 2534 Wolmart.$body.on('click', selector, function (e) { 2535 e.preventDefault(); 2536 var $this = $(this), 2537 $product = $this.closest('.product, .product-popup'); 2538 2539 if ($this.hasClass('disabled')) { 2540 alert('Please select some product options before adding this product to your cart.'); 2541 return; 2542 } 2543 2544 $this.toggleClass('added').addClass('load-more-overlay loading'); 2545 2546 setTimeout(function () { 2547 $this.removeClass('load-more-overlay loading'); 2548 2549 Wolmart.Minipopup.open({ 2550 productClass: ' product-cart', 2551 name: $product.find('.product-name, .product-title').text(), 2552 nameLink: $product.find('.product-name > a, .product-title > a').attr('href'), 2553 imageSrc: $product.find('.product-media img, .product-image:first-child img').attr('src'), 2554 imageLink: $product.find('.product-name > a').attr('href'), 2555 message: '<p>has been added to cart:</p>', 2556 actionTemplate: '<a href="cart.html" class="btn btn-rounded btn-sm">View Cart</a><a href="checkout.html" class="btn btn-dark btn-rounded btn-sm">Checkout</a>' 2557 }); 2558 }, 500); 2559 }); 2560 } 2561 2562 var initWishlistAction = function () { 2563 Wolmart.$body.on('click', '.product:not(.product-single) .btn-wishlist', function (e) { 2564 e.preventDefault(); 2565 var $this = $(this); 2566 $this.toggleClass('added').addClass('load-more-overlay loading'); 2567 2568 setTimeout(function () { 2569 $this.removeClass('load-more-overlay loading'); 2570 $this.toggleClass('w-icon-heart').toggleClass('w-icon-heart-full'); 2571 }, 500); 2572 }); 2573 } 2574 2575 var initCompare = function () { 2576 var products = [], 2577 $compare = $('.page-wrapper > .compare-popup'),
2578 productCount, addToProduct, removeProduct, removeAllProduct; 2579 2580 function initComparePopup() { 2581 var compareHtml = 2582 '<div class="compare-popup">\ 2583 <div class="container">\ 2584 <div class="compare-title">\ 2585 <h4 class="title title-center">Compare Products</h4>\ 2586 </div>\ 2587 <ul class="compare-product-list list-style-none">\ 2588 <li></li><li></li><li></li><li></li>\ 2589 </ul>\ 2590 <a href="#" class="btn btn-clean">Clean All</a>\ 2591 <a href="compare.html" class="btn btn-dark btn-rounded">Start Compare !</a>\ 2592 </div>\ 2593 </div>\ 2594 <div class="compare-popup-overlay">\ 2595 </div>'; 2596 2597 if (!$compare.length && !document.body.classList.contains('docs')) { 2598 $('.page-wrapper').append(compareHtml); 2599 $compare = $('.page-wrapper > .compare-popup'); 2600 } 2601 } 2602 2603 function addToCompare(e) { 2604 2605 var $this = $(this); 2606 2607 addToProduct = false; 2608 2609 if ($this.hasClass('added')) { 2610 returne(); 2611 } 2612 e.preventDefault(); 2613 $this.toggleClass('added').addClass('load-more-overlay loading'); 2614 2615 setTimeout(function () { 2616 $this.removeClass('load-more-overlay loading'); 2617 $this.toggleClass('w-icon-compare').toggleClass('w-icon-check-solid'); 2618 $this.attr('href', 'compare.html'); 2619 2620 $compare.addClass('show'); 2621 }, 500); 2622 2623 2624 var src = $this.closest('.product').find('img').eq(0).attr('src'); 2625 2626 if (products.length >= 4) { 2627 products.shift(); 2628 } 2629 products.push(src); 2630 2631 $('.compare-popup li').each(function (i) { 2632 if (products[i]) { 2633 this.innerHTML = '<a href="product-default.html"><figure><img src="' + products[i] + '"/></figure></a>\ 2634 <a href="#" class="btn btn-remove"><i class="w-icon-times-solid"></i></a>'; 2635 } 2636 }); 2637 2638 productCount = products.length; 2639 compareCount(); 2640 2641 } 2642 2643 function removeCompare(e) { 2644 e.preventDefault(); 2645 var $li = $(e.currentTarget).closest('li'), 2646 $index = $li.index(), 2647 srcCompare = $li.find('img').attr('src'); 2648 2649 if (srcCompare) { 2650 $('.page-wrapper .product img').each(function () { 2651 var srcProduct = this.getAttribute('src'); 2652 if (srcProduct == srcCompare) { 2653 2654 var $compareButton = $(this).closest('.product').find('.btn-compare'); 2655 if ($compareButton.length) { 2656 $compareButton.removeClass('added').attr('href', '#'); 2657 $compareButton.toggleClass('w-icon-check-solid').toggleClass('w-icon-compare'); 2658 } 2659 } 2660 }) 2661 } 2662 2663 products.splice($index, 1); 2664 2665 if ($index == 3) { 2666 $li.empty(); 2667 } 2668 2669 $li.nextAll().each(function () { 2670 $(this).prev().html($(this).html()); 2671 }).last().empty(); 2672 2673 productCount = products.length; 2674 compareCount(); 2675 } 2676 2677 function removeAllCompare(e) { 2678 e.preventDefault(); 2679 removeAllProduct = false; 2680 2681 $('.page-wrapper .product img').each(function () { 2682 var $this = $(this); 2683 var srcProduct = this.getAttribute('src'); 2684 products.forEach(function (srcCompare) { 2685 if (srcProduct == srcCompare) { 2686 var $compareButton = $this.closest('.product').find('.btn-compare'); 2687 if ($compareButton.length) { 2688 $compareButton.removeClass('added').attr('href', '#'); 2689 $compareButton.toggleClass('w-icon-check-solid').toggleClass('w-icon-compare'); 2690 } 2691 } 2692 }); 2693 }) 2694 products.splice(0, 4);
2695 productCount = products.length; 2696 $(this).parent().find('.compare-product-list li').empty(); 2697 compareCount(); 2698 2699 } 2700 2701 function compareCount() { 2702 $compare.find('.title').after('<p class="compare-count text-center text-light mb-0">(' + productCount + ' Products)</p>'); 2703 if ($compare.find('.compare-count').length > 1) { 2704 $compare.find('p:last-child').remove(); 2705 } 2706 } 2707 2708 initComparePopup(); 2709 2710 Wolmart.$body 2711 .on('click', '.product .btn-compare', addToCompare) 2712 .on('click', '.compare-popup .btn-remove', removeCompare) 2713 .on('click', '.compare-popup .btn-clean', removeAllCompare) 2714 2715 Wolmart.$body.on('click', '.compare-popup-overlay', function () { 2716 $compare.removeClass('show'); 2717 }); 2718 2719 } 2720 2721 var quickviewCloseBtnHtml = 2722 '<button type="button" class="mfp-close product-popup__close" title="ÐакÑÑÑÑ" aria-label="ÐакÑÑÑÑ">' 2723 + '<i class="close-icon" aria-hidden="true"></i></button>'; 2724 2725 var ensureQuickviewCloseStyles = function () { 2726 if (document.getElementById('product-popup-close-style')) { 2727 return; 2728 } 2729 // Ðак news-modal__close + .close-icon (ÑоÑма «ÐадаÑÑ Ð²Ð¾Ð¿ÑоÑ») 2730 var css = '' 2731 + '.mfp-product .product-popup{position:relative!important;}' 2732 + '.mfp-product .product-popup>.mfp-close,' 2733 + '.mfp-product .product-popup__close{' 2734 + 'position:absolute!important;top:1.2rem!important;right:1.2rem!important;left:auto!important;' 2735 + 'display:flex!important;align-items:center!important;justify-content:center!important;' 2736 + 'width:3.2rem!important;height:3.2rem!important;padding:0!important;margin:0!important;' 2737 + 'z-index:10050!important;border:0!important;border-radius:0!important;background:transparent!important;' 2738 + 'box-shadow:none!important;color:transparent!important;font-size:0!important;line-height:0!important;' 2739 + 'opacity:1!important;transform:none!important;cursor:pointer!important;' 2740 + '}' 2741 + '.mfp-product .product-popup>.mfp-close::before,' 2742 + '.mfp-product .product-popup>.mfp-close::after,' 2743 + '.mfp-product .product-popup__close::before,' 2744 + '.mfp-product .product-popup__close::after{content:none!important;display:none!important;}' 2745 + '.mfp-product .product-popup__close .close-icon{' 2746 + 'display:block!important;position:relative!important;width:2rem!important;height:2rem!important;' 2747 + 'transform:rotateZ(45deg)!important;pointer-events:none!important;' 2748 + '}' 2749 + '.mfp-product .product-popup-skeleton>.product-popup__close,' 2750 + '.mfp-product .product-popup-skeleton>.mfp-close{pointer-events:auto!important;}' 2751 + '.mfp-product .product-popup__close .close-icon::before,' 2752 + '.mfp-product .product-popup__close .close-icon::after{' 2753 + 'content:""!important;display:block!important;position:absolute!important;background-color:#999!important;' 2754 + 'transition:background-color .2s;' 2755 + '}' 2756 + '.mfp-product .product-popup__close .close-icon::before{' 2757 + 'height:2px!important;width:100%!important;left:0!important;top:50%!important;transform:translateY(-50%)!important;' 2758 + '}' 2759 + '.mfp-product .product-popup__close .close-icon::after{' 2760 + 'width:2px!important;height:100%!important;top:0!important;left:50%!important;transform:translateX(-50%)!important;' 2761 + '}' 2762 + '.mfp-product .product-popup__close:hover .close-icon::before,' 2763 + '.mfp-product .product-popup__close:hover .close-icon::after,' 2764 + '.mfp-product .product-popup__close:focus .close-icon::before,' 2765 + '.mfp-product .product-popup__close:focus .close-icon::after{background-color:#2b2b2b!important;}' 2766 + '.mfp-product .product-popup>.mfp-close:active,' 2767 + '.mfp-product .product-popup__close:active{top:1.2rem!important;}'; 2768 var style = document.createElement('style'); 2769 style.id = 'product-popup-close-style'; 2770 style.appendChild(document.createTextNode(css)); 2771 document.head.appendChild(style); 2772 }; 2773 2774 var mountQuickviewCloseButton = function () { 2775 ensureQuickviewCloseStyles(); 2776 var $popup = $('.mfp-product .product-popup'); 2777 if (!$popup.length) { 2778 return; 2779 } 2780 $popup.children('.mfp-close').remove(); 2781 $popup.prepend(quickviewCloseBtnHtml); 2782 }; 2783 2784 var quickviewSkeletonMarkup = '<div class="product product-single product-popup product-popup-skeleton">' + 2785 quickviewCloseBtnHtml + 2786 '<div class="row gutter-lg">' + 2787 '<div class="col-md-6 mb-4 mb-md-0"><div class="skeleton-block skeleton-gallery"></div></div>' + 2788 '<div class="col-md-6 mb-4 mb-md-0"><div class="product-details product-popup__details">' + 2789 '<div class="skeleton-block skeleton-line skeleton-line-title"></div>' + 2790 '<div class="skeleton-block skeleton-line skeleton-line-sm"></div>' + 2791 '<div class="skeleton-block skeleton-line skeleton-line-sm"></div>' + 2792 '<div class="skeleton-block skeleton-line skeleton-line-text"></div>' + 2793 '<div class="skeleton-block skeleton-line skeleton-line-text"></div>' + 2794 '<div class="skeleton-block skeleton-line skeleton-line-text"></div>' + 2795 '<div class="skeleton-block skeleton-btn"></div>' + 2796 '</div></div>' + 2797 '</div>' + 2798 '</div>'; 2799 2800 var initProductQuickview = function () { 2801 // var $popup = $('.product-popup'); 2802 // if (!$popup.length) { 2803 // return; 2804 // } 2805 var quickviewXhr = null; 2806 2807 // Magnific Popup закÑÑÐ²Ð°ÐµÑ ÑолÑко еÑли e.target Ñам .mfp-close. 2808 // Ðлик по <i class="close-icon"> инаÑе не Ð´Ð¾Ñ Ð¾Ð´Ð¸Ñ Ð´Ð¾ close(). 2809 Wolmart.$body.on('click', '.mfp-product .product-popup__close', function (e) { 2810 e.preventDefault(); 2811 $.magnificPopup.close(); 2812 }); 2813 2814 Wolmart.$body.on('click', '.btn-quickview', function (e) { 2815 e.preventDefault(); 2816 let dataGet = { 2817 id: $(this).data('id'), 2818 categoryId: $(this).data('category-id') 2819 } 2820 2821 if (quickviewXhr) { 2822 quickviewXhr.abort(); 2823 } 2824 2825 ensureQuickviewCloseStyles(); 2826 2827 Wolmart.popup({ 2828 items: { 2829 src: quickviewSkeletonMarkup 2830 }, 2831 callbacks: { 2832 close: function () { 2833 if (quickviewXhr) { 2834 quickviewXhr.abort(); 2835 quickviewXhr = null; 2836 } 2837 $('.mfp-product .swiper-container').each(function () { 2838 var slider = $(this).data('slider'); 2839 if (slider) { 2840 slider.destroy(); 2841 } 2842 }); 2843 } 2844 } 2845 }, 'quickview'); 2846 2847 setTimeout(mountQuickviewCloseButton, 0); 2848 2849 quickviewXhr = $.get( '/product/quickview', dataGet ).done(function (data) { 2850 if (!$.magnificPopup.instance.isOpen) { 2851 return; 2852 } 2853 var mfp = $.magnificPopup.instance; 2854 mfp.contentContainer.html(data); 2855 mfp.content = mfp.contentContainer.children(); 2856 mountQuickviewCloseButton(); 2857 Wolmart.productSingle($('.mfp-product .product-single')); 2858 }).always(function () { 2859 quickviewXhr = null; 2860 }); 2861 }); 2862 } 2863 2864 2865 // Public Properties 2866 var Shop = { 2867 init: function () { 2868 Wolmart.call(Wolmart.ratingTooltip, 500); 2869 Wolmart.call(Wolmart.setProgressBar('.progress-bar'), 500); 2870 this.initVariation(); 2871 this.initProductsScrollLoad('.scroll-load'); 2872 2873 // Functions for shop page 2874 initSelectMenu(); 2875 initProductCartAction(); 2876 initWishlistAction(); 2877 initProductQuickview(); 2878 initCompare(); 2879 2880 Wolmart.priceSlider('.filter-price-slider'); 2881 }, 2882 2883 initVariation: function (type) { 2884 $('.product:not(.product-single) .product-variations > a').on('click', function (e) { 2885 var $this = $(this), 2886 $image = $this.closest('.product').find('.product-media img'); 2887 2888 if (!$image.data('image-src')) 2889 $image.data('image-src', $image.attr('src')); 2890 2891 $this.toggleClass('active').siblings().removeClass('active'); 2892 2893 if ($this.hasClass('active')) { 2894 $image.attr('src', $this.data('src')); 2895 } else { 2896 $image.attr('src', $image.data('image-src')); 2897 $this.blur(); 2898 } 2899 e.preventDefault(); 2900 }) 2901 }, 2902 initProductsScrollLoad: function ($obj) { 2903 var $wrapper = Wolmart.$($obj) 2904 , top; 2905 var url = $($obj).data('url'); 2906 if (!url) { 2907 url = 'assets/ajax/products.html'; 2908 } 2909 var loadProducts = function (e) { 2910 if (window.pageYOffset > top + $wrapper.outerHeight() - window.innerHeight - 150 && 'loading' != $wrapper.data('load-state')) { 2911 $.ajax({ 2912 url: url, 2913 success: function (result) { 2914 var $newItems = $(result); 2915 $wrapper.data('load-state', 'loading'); 2916 if (!$wrapper.next().hasClass('load-more-overlay')) { 2917 $('<div class="mt-4 mb-4 load-more-overlay loading"></div>').insertAfter($wrapper); 2918 } else { 2919 $wrapper.next().addClass('loading'); 2920 } 2921 setTimeout(function () { 2922 $wrapper.next().removeClass('loading'); 2923 $wrapper.append($newItems); 2924 setTimeout(function () { 2925 $wrapper.find('.product-wrap.fade:not(.in)').addClass('in'); 2926 }, 200); 2927 $wrapper.data('load-state', 'loaded'); 2928 Wolmart.countDown($newItems.find('.product-countdown')); 2929 }, 500); 2930 var loadCount = parseInt($wrapper.data('load-count') ? $wrapper.data('load-count') : 0); 2931 $wrapper.data('load-count', ++loadCount); 2932 loadCount > 2 && window.removeEventListener('scroll', loadProducts, { passive: true }); 2933 }, 2934 failure: function () { 2935 $this.text("Sorry something went wrong."); 2936 } 2937 }); 2938 } 2939 } 2940 if ($wrapper.length > 0) { 2941 top = $wrapper.offset().top; 2942 window.addEventListener('scroll', loadProducts, { passive: true }); 2943 } 2944 } 2945 } 2946 2947 Wolmart.shop = Shop; 2948})(jQuery); 2949 2950/** 2951 * Wolmart Plugin - QuantityInput 2952 * 2953 * @instance multiple 2954 */ 2955 2956(function ($) { 2957 function QuantityInput($el) { 2958 return this.init($el); 2959 } 2960 2961 // Public Members 2962 QuantityInput.min = 1; 2963 QuantityInput.max = 1000000; 2964 QuantityInput.value = 1; 2965 2966 QuantityInput.prototype.init = function ($el) { 2967 var self = this; 2968 2969 self.$minus = false;
2970 self.$plus = false; 2971 self.$value = false; 2972 self.value = false; 2973 2974 // Bind Events 2975 self.startIncrease = self.startIncrease.bind(self); 2976 self.startDecrease = self.startDecrease.bind(self); 2977 self.stop = self.stop.bind(self); 2978 2979 // Variables 2980 self.min = parseInt($el.attr('min')); 2981 self.max = parseInt($el.attr('max')); 2982 2983 self.min || ($el.attr('min', self.min = QuantityInput.min)); 2984 self.max || ($el.attr('max', self.max = QuantityInput.max)); 2985 2986 // Add DOM elements and event listeners 2987 self.$value = $el.val(self.value = QuantityInput.value); 2988 2989 self.$minus = $el.parent().find('.quantity-minus') 2990 .on('mousedown', function (e) { 2991 e.preventDefault(); 2992 self.startDecrease(); 2993 }) 2994 .on('touchstart', function (e) { 2995 if (e.cancelable) { 2996 e.preventDefault(); 2997 } 2998 self.startDecrease(); 2999 }) 3000 .on('mouseup', self.stop); 3001 3002 self.$plus = $el.parent().find('.quantity-plus') 3003 .on('mousedown', function (e) { 3004 e.preventDefault(); 3005 self.startIncrease(); 3006 }) 3007 .on('touchstart', function (e) { 3008 if (e.cancelable) { 3009 e.preventDefault(); 3010 } 3011 self.startIncrease(); 3012 }) 3013 .on('mouseup', self.stop); 3014 3015 Wolmart.$body.on('mouseup', self.stop) 3016 .on('touchend', self.stop) 3017 .on('touchcancel', self.stop); 3018 } 3019 3020 QuantityInput.prototype.startIncrease = function (e) { 3021 e && e.preventDefault(); 3022 3023 var self = this; 3024 self.value = self.$value.val(); 3025 3026 self.value < self.max && self.$value.val(++self.value); 3027 self.increaseTimer = Wolmart.requestTimeout(function () { 3028 self.speed = 1; 3029 self.increaseTimer = Wolmart.requestInterval(function () { 3030 self.$value.val(self.value = Math.min(self.value + Math.floor(self.speed *= 1.05), self.max)); 3031 }, 50); 3032 }, 400); 3033 } 3034 3035 QuantityInput.prototype.startDecrease = function (e) { 3036 e && e.preventDefault(); 3037 3038 var self = this; 3039 self.value = self.$value.val(); 3040 self.value > self.min && self.$value.val(--self.value); 3041 3042 self.decreaseTimer = Wolmart.requestTimeout(function () { 3043 self.speed = 1; 3044 self.decreaseTimer = Wolmart.requestInterval(function () { 3045 self.$value.val(self.value = Math.max(self.value - Math.floor(self.speed *= 1.05), self.min)) 3046 }, 50); 3047 }, 400); 3048 } 3049 3050 QuantityInput.prototype.stop = function (e) { 3051 Wolmart.deleteTimeout(this.increaseTimer); 3052 Wolmart.deleteTimeout(this.decreaseTimer); 3053 } 3054 3055 Wolmart.initQtyInput = function (selector) { 3056 Wolmart.$(selector).each(function () { 3057 var $this = $(this); 3058 3059 // if not initialized 3060 $this.data('quantityInput') || 3061 $this.data('quantityInput', new QuantityInput($this)); 3062 }) 3063 } 3064})(jQuery); 3065 3066/** 3067 * Wolmart Plugin - Popup 3068 * 3069 */ 3070 3071(function ($) { 3072 'use strict'; 3073 3074 function Popup(options, preset) { 3075 return this.init(options, preset); 3076 } 3077 3078 Popup.defaults = { 3079 removalDelay: 300, 3080 closeOnBgClick: false, 3081 callbacks: { 3082 open: function () { 3083 $('html').css('overflow-y', 'hidden'); 3084 $('body').css('overflow-x', 'visible'); 3085 $('.mfp-wrap').css('overflow', 'hidden auto'); 3086 $('.sticky-header.fixed').css('padding-right', window.innerWidth - document.body.clientWidth); 3087 }, 3088 close: function () { 3089 $('html').css('overflow-y', ''); 3090 $('body').css('overflow-x', 'hidden'); 3091 $('.mfp-wrap').css('overflow', ''); 3092 $('.sticky-header.fixed').css('padding-right', ''); 3093 } 3094 } 3095 } 3096 3097 3098 Popup.presets = { 3099 'quickview': { 3100 type: 'inline', 3101 mainClass: 'mfp-product mfp-fade', 3102 tLoading: 'Loading...' 3103 }, 3104 'video': { 3105 type: 'iframe', 3106 mainClass: "mfp-fade", 3107 preloader: false, 3108 closeBtnInside: false 3109 }, 3110 'login': { 3111 type: 'ajax', 3112 mainClass: "mfp-login-popup mfp-fade ", 3113 tLoading: '', 3114 preloader: false 3115 } 3116 } 3117 3118 Popup.prototype.init = function (options, preset) { 3119 var mpIns = $.magnificPopup.instance; 3120 3121 if ( mpIns.isOpen ) { 3122 if ( mpIns.content ) { 3123 setTimeout( function () { 3124 Wolmart.popup( options, preset ); 3125 }, 5000 ); 3126 } else { 3127 $.magnificPopup.close(); 3128 } 3129 } else { 3130 // if nothing is opened, open new 3131 $.magnificPopup.open( 3132 $.extend(true, {}, 3133 Popup.defaults, 3134 preset ? Popup.presets[preset] : {}, 3135 options 3136 ) 3137 ); 3138 } 3139 3140 // Close magnific popup by mousedown on outside of the content 3141 function closePopupByBgClick(e) { 3142 if (!$(e.target).closest('.mfp-content').length || $(e.target).hasClass('mfp-content')) { 3143 $.magnificPopup.instance.close(); 3144 } 3145 else { 3146 mpIns.st.closeOnBgClick = false;
3147 mpIns.st.closeOnBgContentClick = false; 3148 } 3149 } 3150 Wolmart.$body.on('mousedown', '.mfp-wrap', closePopupByBgClick); 3151 if ('ontouchstart' in document) { 3152 document.addEventListener('touchstart', closePopupByBgClick, { passive: true }); 3153 } 3154 } 3155 3156 Wolmart.popup = function (options, preset) { 3157 return new Popup(options, preset); 3158 } 3159})(jQuery); 3160 3161/** 3162 * Wolmart Plugin - Product Single 3163 * 3164 * @requires SwiperContainer 3165 * @requires zoom 3166 * @instance multiple 3167 */ 3168 3169(function ($) { 3170 function ProductSingle($el) { 3171 return this.init($el); 3172 } 3173 3174 var thumbsInit = function (self) { 3175 // properties for thumbnails 3176 self.$thumbs = self.$wrapper.find('.product-thumbs'); 3177 self.$thumbsWrap = self.$thumbs.parent(); 3178 self.$thumbUp = self.$thumbsWrap.find('.thumb-up'); 3179 self.$thumbDown = self.$thumbsWrap.find('.thumb-down'); 3180 self.$thumbsDots = self.$thumbs.children(); 3181 self.thumbsCount = self.$thumbsDots.length; 3182 self.$productThumb = self.$thumbsDots.eq(0); 3183 self._isPgVertical = self.$thumbsWrap.parent().hasClass('product-gallery-vertical'); 3184 self.thumbsIsVertical = self._isPgVertical && window.innerWidth >= 992; 3185 3186 // refresh thumbs 3187 3188 Wolmart.slider(self.$thumbsWrap, {}, true); 3189 } 3190 3191 var variationInit = function (self) { 3192 self.$selects = self.$wrapper.find('.product-variations select'); 3193 self.$items = self.$wrapper.find('.product-variations'); 3194 self.$priceWrap = self.$wrapper.find('.product-variation-price'); 3195 self.$clean = self.$wrapper.find('.product-variation-clean'), 3196 self.$btnCart = self.$wrapper.find('.btn-cart'); 3197 3198 // check 3199 self.variationCheck(); 3200 self.$selects.on('change', function (e) { 3201 self.variationCheck(); 3202 }); 3203 self.$items.children('a').on('click', function (e) { 3204 $(this).toggleClass('active').siblings().removeClass('active'); 3205 e.preventDefault(); 3206 self.variationCheck(); 3207 if (self.$items.parent('.product-image-swatch')) { 3208 self.swatchImage(); 3209 } 3210 }); 3211 3212 // clean 3213 self.$clean.on('click', function (e) { 3214 e.preventDefault(); 3215 self.variationClean(true); 3216 }); 3217 3218 } 3219 3220 // For only Quickview 3221 var recalcDetailsHeight = function () { 3222 var self = this; 3223 self.$wrapper.find('.product-details').css( 3224 'height', 3225 window.innerWidth > 767 ? self.$wrapper.find('.product-gallery')[0].clientHeight : '' 3226 ); 3227 } 3228 3229 var wishlistAction = function (e) { 3230 var $this = $(this); 3231 if ($this.hasClass('added')) { 3232 return; 3233 } 3234 e.preventDefault(); 3235 $this.addClass('load-more-overlay loading'); 3236 3237 setTimeout(function () { 3238 $this 3239 .removeClass('load-more-overlay loading') 3240 .toggleClass('w-icon-heart').toggleClass('w-icon-heart-full') 3241 .addClass('added') 3242 .attr('href', 'wishlist.html'); 3243 }, 500); 3244 } 3245 3246 var goToReviewPan = function (e) { 3247 e.preventDefault(); 3248 Wolmart.scrollTo($('.product-tabs > .nav a[href="' + this.getAttribute('href') + '"]').trigger('click')); 3249 } 3250 3251 // Public Properties 3252 ProductSingle.prototype.init = function ($el) { 3253 var self = this, 3254 $slider = $el.find('.product-single-swiper'); 3255 3256 // members 3257 self.$wrapper = $el; 3258 self.isQuickView = !!$el.closest('.mfp-content').length; 3259 self._isPgVertical = false;
3260 3261 // bind 3262 if (self.isQuickView) { 3263 recalcDetailsHeight = recalcDetailsHeight.bind(this); 3264 Wolmart.ratingTooltip(); 3265 } 3266 3267 // init thumbs 3268 thumbsInit(self); 3269 // if not quickview, make full image toggle 3270 // add gallery-video button 3271 if (!document.body.classList.contains('home')) { 3272 if ($slider.parent().hasClass('product-gallery-video')) { 3273 self.isQuickView || $slider.append('<a href="#" class="product-gallery-btn product-degree-viewer" title="Product 360 Degree Gallery"><i class="w-icon-rotate-3d"></i></a>'); 3274 self.isQuickView || $slider.append('<a href="#" class="product-gallery-btn product-video-viewer" title="Product Video Thumbnail"><i class="w-icon-movie"></i></a>'); 3275 } 3276 } 3277 3278 //Wishlist button event 3279 self.$wrapper.on('click', '.btn-wishlist', wishlistAction); 3280 3281 //Rating reviews evnet 3282 self.$wrapper.on('click', '.rating-reviews', goToReviewPan); 3283 3284 // if this is created after document ready, init plugins 3285 if ('complete' === Wolmart.status) { 3286 Wolmart.slider($slider, { 3287 thumbs: { 3288 swiper: self.$thumbsWrap.data('slider') 3289 } 3290 }); 3291 Wolmart.initQtyInput($el.find('.quantity')); 3292 } 3293 3294 if ($slider.length) { 3295 window.addEventListener('resize', function () { 3296 Wolmart.requestTimeout(function () { 3297 if ($slider.data('slider') != undefined) { 3298 $slider.data('slider').update(); 3299 self.$thumbsWrap.data('slider').update(); 3300 } 3301 }, 100) 3302 }, { passive: true }); 3303 } 3304 3305 // self.$wrapper.find('.product-single-swiper').on('initialized.slider', function (e) { 3306 // $(e.target).find('.product-image').zoom(Wolmart.zoomImageOptions); 3307 // }) 3308 3309 // init sticky thumbnail 3310 3311 if (self.$wrapper.find('.product-thumbs-sticky').length) { 3312 self.isStickyScrolling = false; 3313 self.$wrapper.on('click', '.product-thumb:not(.active)', self.clickStickyThumbnail.bind(this)); 3314 window.addEventListener('scroll', self.scrollStickyThumbnail.bind(this), { passive: true }); 3315 } 3316 3317 variationInit(this); 3318 } 3319 3320 ProductSingle.prototype.variationCheck = function () { 3321 var self = this, 3322 isAllSelected = true; 3323 3324 // check all select variations are selected 3325 self.$selects.each(function () { 3326 return this.value || (isAllSelected = false); 3327 }); 3328 3329 // check all item variations are selected 3330 self.$items.each(function () { 3331 var $this = $(this); 3332 if ($this.children('a:not(.size-guide)').length) { 3333 return $this.children('.active').length || (isAllSelected = false); 3334 } 3335 }); 3336 3337 isAllSelected ? 3338 self.variationMatch() : 3339 self.variationClean(); 3340 } 3341 3342 ProductSingle.prototype.variationMatch = function () { 3343 var self = this; 3344 self.$priceWrap.find('span').text('$' + (Math.round(Math.random() * 50) + 200) + '.00'); 3345 self.$priceWrap.slideDown(); 3346 self.$clean.slideDown(); 3347 self.$btnCart.removeClass('disabled'); 3348 } 3349 3350 ProductSingle.prototype.variationClean = function (reset) { 3351 reset && this.$selects.val(''); 3352 reset && this.$items.children('.active').removeClass('active'); 3353 this.$priceWrap.slideUp();
3354 this.$clean.css('display', 'none'); 3355 this.$btnCart.addClass('disabled'); 3356 3357 } 3358 3359 ProductSingle.prototype.clickStickyThumbnail = function (e) { 3360 var self = this; 3361 var $thumb = $(e.currentTarget); 3362 var currentIndex = $thumb.parent().children('.active').index(); 3363 var newIndex = $thumb.index() + 1; 3364 3365 $thumb.addClass('active').siblings('.active').removeClass('active'); 3366 this.isStickyScrolling = true; 3367 var target = $thumb.closest('.product-thumbs-sticky').find('.product-image-wrapper > :nth-child(' + newIndex + ')'); 3368 if (target.length) { 3369 target = target.offset().top + 10; 3370 Wolmart.scrollTo(target, 500); 3371 } 3372 3373 setTimeout(function () { 3374 self.isStickyScrolling = false; 3375 }, 300); 3376 } 3377 3378 ProductSingle.prototype.scrollStickyThumbnail = function () { 3379 var self = this; 3380 if (!this.isStickyScrolling) { 3381 self.$wrapper.find('.product-image-wrapper .product-image').each(function () { 3382 if (Wolmart.isOnScreen(this)) { 3383 self.$wrapper.find('.product-thumbs > :nth-child(' + ($(this).index() + 1) + ')') 3384 .addClass('active').siblings().removeClass('active'); 3385 return false; 3386 } 3387 }); 3388 } 3389 } 3390 3391 ProductSingle.prototype.swatchImage = function () { 3392 var src = this.$items.find('.active img').attr('src'), 3393 productImage = this.$wrapper.find('.swiper-slide:first-child .product-image img'), 3394 thumbImage = this.$wrapper.find('.swiper-slide:first-child .product-thumb img'); 3395 3396 productImage.attr('src', src); 3397 thumbImage.attr('src', src); 3398 } 3399 3400 Wolmart.productSingle = function (selector) { 3401 Wolmart.$(selector).each(function () { 3402 var $this = $(this); 3403 if (!$this.is('body > *')) { 3404 $this.data('product-single', new ProductSingle($this)); 3405 } 3406 }) 3407 return null; 3408 } 3409})(jQuery); 3410 3411/** 3412 * Wolmart Plugin - Product Single Page 3413 * 3414 * @requires Slider 3415 * @requires ProductSingle 3416 * @requires PhotoSwipe 3417 * @instance single 3418 */ 3419 3420(function ($) { 3421 3422 // Open Image Gallery 3423 // function openImageGallery(e) { 3424 // e.preventDefault(); 3425 // 3426 // var $this = $(e.currentTarget), 3427 // $product = $this.closest('.product-single'), 3428 // $review = $this.closest('.review-image'), 3429 // $images, images; 3430 // if ($this.closest('.review-image').length) { 3431 // $images = $this.closest('.review-image').find('img'); 3432 // } else if ($product.find('.product-single-swiper').length) { // single carousel 3433 // $images = $product.find('.product-single-swiper .swiper-slide:not(.cloned) img:first-child'); 3434 // } else if ($product.find('.product-gallery-carousel').length) { // gallery carousel 3435 // $images = $product.find('.product-gallery-carousel .swiper-slide:not(.cloned) img'); 3436 // } else { // simple gallery 3437 // $images = $product.find('.product-image img:first-child'); 3438 // } 3439 // 3440 // if ($images.length) { 3441 // images = $images.map(function () { 3442 // var $this = $(this); 3443 // 3444 // return { 3445 // src: $this.attr('data-zoom-image'), 3446 // w: $this.attr('width'), 3447 // h: $this.attr('height'), 3448 // title: $this.attr('alt') 3449 // }; 3450 // }).get(); 3451 // 3452 // var swiper = $product.find('.product-single-swiper').data('slider'), 3453 // curIndex = swiper ? 3454 // // Carousel Type 3455 // swiper.activeIndex : 3456 // // Gallery Type 3457 // $product.find('.product-gallery .product-gallery-btn').index($this); 3458 // if ($review.length == 1) { 3459 // var reviewIndex = $review.find('img').index($this); 3460 // curIndex = reviewIndex; 3461 // } 3462 // 3463 // if (typeof PhotoSwipe !== 'undefined') { 3464 // var pswpElement = $('.pswp')[0]; 3465 // 3466 // if (Wolmart.$body.attr('dir') == 'rtl') { 3467 // var photoSwipe = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, images, { 3468 // index: curIndex, 3469 // closeOnScroll: false, 3470 // showAnimationDuration: 0, 3471 // rtl: true 3472 // }); 3473 // } 3474 // else { 3475 // var photoSwipe = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, images, { 3476 // index: curIndex, 3477 // closeOnScroll: false, 3478 // showAnimationDuration: 0, 3479 // }); 3480 // } 3481 // photoSwipe.init(); 3482 // Wolmart.photoSwipe = photoSwipe; 3483 // } 3484 // } 3485 // } 3486 3487 // Open Image Gallery 3488 function openImageGallery(e) { 3489 e.preventDefault(); 3490 3491 var $this = $(e.currentTarget), 3492 $product = $this.closest('.product-single'), 3493 $review = $this.closest('.review-image'), 3494 $images, images = [], 3495 imagesLoaded = 0, 3496 totalImages; 3497 3498 if ($this.closest('.review-image').length) { 3499 $images = $this.closest('.review-image').find('img'); 3500 } else if ($product.find('.product-single-swiper').length) { // single carousel
3501 $images = $product.find('.product-single-swiper .swiper-slide:not(.cloned) img:first-child'); 3502 } else if ($product.find('.product-gallery-carousel').length) { // gallery carousel 3503 $images = $product.find('.product-gallery-carousel .swiper-slide:not(.cloned) img'); 3504 } else { // simple gallery 3505 $images = $product.find('.product-image img:first-child'); 3506 } 3507 3508 if ($images.length) { 3509 totalImages = $images.length; 3510 3511 $images.each(function () { 3512 var $this = $(this); 3513 var img = new Image(); 3514 img.onload = function () { 3515 images.push({ 3516 src: $this.attr('data-zoom-image'), 3517 w: this.width, 3518 h: this.height, 3519 title: $this.attr('alt') 3520 }); 3521 imagesLoaded++; 3522 // ÐÑли вÑе изобÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð·Ð°Ð³ÑÑженÑ, иниÑиализиÑÑем PhotoSwipe 3523 if (imagesLoaded === totalImages) { 3524 var swiper = $product.find('.product-single-swiper').data('slider'), 3525 curIndex = swiper ? 3526 // Carousel Type 3527 swiper.activeIndex : 3528 // Gallery Type 3529 $product.find('.product-gallery .product-gallery-btn').index($this); 3530 if ($review.length == 1) { 3531 var reviewIndex = $review.find('img').index($this); 3532 curIndex = reviewIndex; 3533 } 3534 3535 if (typeof PhotoSwipe !== 'undefined') { 3536 var pswpElement = $('.pswp')[0]; 3537 3538 var options = { 3539 index: curIndex, 3540 closeOnScroll: false, 3541 showAnimationDuration: 0 3542 }; 3543 3544 if (Wolmart.$body.attr('dir') == 'rtl') { 3545 options.rtl = true; 3546 } 3547 3548 var photoSwipe = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, images, options); 3549 photoSwipe.init(); 3550 Wolmart.photoSwipe = photoSwipe; 3551 } 3552 } 3553 }; 3554 img.onerror = function () { 3555 // ÐÑли изобÑажение не загÑÑжаеÑÑÑ, добавлÑем его в ÑпиÑок Ñ Ð½ÑлевÑми ÑазмеÑами 3556 images.push({ 3557 src: $this.attr('data-zoom-image'), 3558 w: 0, 3559 h: 0, 3560 title: $this.attr('alt') 3561 }); 3562 imagesLoaded++; 3563 // ÐÑли вÑе изобÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð·Ð°Ð³ÑÑженÑ, иниÑиализиÑÑем PhotoSwipe 3564 if (imagesLoaded === totalImages) { 3565 var swiper = $product.find('.product-single-swiper').data('slider'), 3566 curIndex = swiper ? 3567 // Carousel Type 3568 swiper.activeIndex : 3569 // Gallery Type 3570 $product.find('.product-gallery .product-gallery-btn').index($this); 3571 if ($review.length == 1) { 3572 var reviewIndex = $review.find('img').index($this); 3573 curIndex = reviewIndex; 3574 } 3575 3576 if (typeof PhotoSwipe !== 'undefined') { 3577 var pswpElement = $('.pswp')[0]; 3578 3579 var options = { 3580 index: curIndex, 3581 closeOnScroll: false, 3582 showAnimationDuration: 0 3583 }; 3584 3585 if (Wolmart.$body.attr('dir') == 'rtl') { 3586 options.rtl = true; 3587 } 3588 3589 var photoSwipe = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, images, options); 3590 photoSwipe.init(); 3591 Wolmart.photoSwipe = photoSwipe; 3592 } 3593 } 3594 }; 3595 img.src = $this.attr('data-zoom-image'); 3596 }); 3597 } 3598 } 3599 3600 3601 // Open Video 3602 function openVideo(e) { 3603 e.preventDefault(); 3604 Wolmart.popup({ 3605 items: { 3606 src: '<video src="assets/video/memory-of-a-woman.mp4" autoplay loop controls>', 3607 type: "inline" 3608 }, 3609 mainClass: "mfp-video-popup" 3610 }, "video") 3611 } 3612 3613 // Open 360 Degree 3614 function open360DegreeView(e) { 3615 e.preventDefault(); 3616 Wolmart.popup({ 3617 type: 'inline', 3618 mainClass: "product-popupbox wm-fade product-360-popup", 3619 preloader: false, 3620 items: { 3621 src: '<div class="product-gallery-degree">\ 3622 <div class="w-loading"><i></i></div>\ 3623 <ul class="product-degree-images"></ul>\ 3624 </div>' 3625 }, 3626 callbacks: { 3627 open: function () { 3628 this.container.find('.product-gallery-degree').ThreeSixty({ 3629 imagePath: 'assets/images/products/video/', 3630 filePrefix: '360-', 3631 ext: '.jpg', 3632 totalFrames: 18, 3633 endFrame: 18, 3634 currentFrame: 1, 3635 imgList: this.container.find('.product-degree-images'), 3636 progress: '.w-loading', 3637 height: 500, 3638 width: 830, 3639 navigation: true 3640 }); 3641 }, 3642 beforeClose: function () { 3643 this.container.empty(); 3644 } 3645 } 3646 }); 3647 } 3648 3649 /** 3650 * Event handler when rating control is clicked in single product page's review form. 3651 * 3652 * @since 1.0 3653 * @param {object} e 3654 * @return {void} 3655 */ 3656 function clickRatingForm(e) { 3657 var $star = $(this); 3658 $star.addClass('active').siblings().removeClass('active'); 3659 $star.parent().addClass('selected'); 3660 $star.closest('.rating-form').find('select').val($star.text()); 3661 e.preventDefault(); 3662 } 3663 3664 function onAddToCartSingle(e) { 3665 3666 var $this = $(this), 3667 $alert = $('.main-content > .alert, .container > .alert'), 3668 productName; 3669 3670 if ($this.hasClass('disabled')) { 3671 alert('Please select some product options before adding this product to your cart.'); 3672 return; 3673 } 3674 3675 if ($alert.length) { 3676 $alert.fadeOut(function () { 3677 $alert.fadeIn(); 3678 }) 3679 } else { 3680 productName = $this.closest('.product-single').find('.product-title').text(); 3681 var alertHtml = '<div class="alert alert-success alert-cart-product mb-2">\ 3682 <a href="cart.html" class="btn btn-success btn-rounded">View Cart</a>\ 3683 <p class="mb-0 ls-normal">â'+ productName + 'â has been added to your cart.</p>\ 3684 <a href="#" class="btn btn-link btn-close" aria-label="button">\<i class="close-icon"></i>\</a>\ 3685 </div>' 3686 $this.closest('.product-single').before(alertHtml); 3687 } 3688 3689 $('.product-sticky-content').trigger('recalc.pin'); 3690 } 3691 3692 function stickyProduct(selector) { 3693 3694 var $this = $(selector), 3695 $product = $this.closest('.product-single'), 3696 src = $product.find('.product-image img').eq(0).attr('src'), 3697 name = $product.find('.product-details .product-title').text(), 3698 newPrice = $product.find('.new-price').text(), 3699 oldPrice = $product.find('.old-price').text(), 3700 stickyProductDetailsHtml = '<div class="product product-list-sm mr-auto">\ 3701 <figure class="product-media">\ 3702 <img src="'+ src + '" alt="Product" width="85" height="85" />\ 3703 </figure>\ 3704 <div class="product-details pt-0 pl-2 pr-2">\ 3705 <h4 class="product-name font-weight-normal mb-1">'+ name + '</h4>\ 3706 <div class="product-price mb-0">\ 3707 <ins class="new-price">'+ newPrice + '</ins><del class="old-price">' + oldPrice + '</del></div>\ 3708 </div></div>'; 3709 3710 $this.find('.product-qty-form').before(stickyProductDetailsHtml); 3711 3712 function refreshStickyProduct() { 3713 if ($this.hasClass('fix-top') && window.innerWidth > 767) { 3714 $this.removeClass('fix-top').addClass('fix-bottom'); 3715 } 3716 3717 if ($this.hasClass('fix-bottom') && window.innerWidth > 767) { 3718 return; 3719 } 3720 3721 if ($this.hasClass('fix-bottom') && window.innerWidth < 768) { 3722 $this.removeClass('fix-bottom').addClass('fix-top'); 3723 } 3724 3725 if ($this.hasClass('fix-top') && window.innerWidth < 768) { 3726 return; 3727 } 3728 } 3729 3730 window.addEventListener('resize', refreshStickyProduct, { passive: true }); 3731 refreshStickyProduct(); 3732 } 3733 3734 Wolmart.initProductSinglePage = function () { 3735 // Zoom Image for grid type 3736 $('.product-gallery').each(function () { 3737 var $this = $(this), 3738 $images = $this.find('.product-image'); 3739 $images.length && $this.find('.swiper-container').length == 0 && $images.zoom(Wolmart.zoomImageOptions); 3740 }); 3741 3742 stickyProduct('.product-sticky-content') 3743 3744 // Register events 3745 if (!document.body.classList.contains('home')) { 3746 Wolmart.$body 3747 .on('click', '.product-image-full', openImageGallery) 3748 .on('click', '.product-single-swiper .product-image', openImageGallery) 3749 .on('click', '.review-image img', openImageGallery) 3750 .on('click', '.product-video-viewer', openVideo) 3751 .on('click', '.product-degree-viewer', function (e) { 3752 e.preventDefault(e); 3753 if ($.fn.ThreeSixty) { 3754 open360DegreeView(e); 3755 } 3756 }) 3757 .on('click', '.rating-form .rating-stars > a', clickRatingForm) 3758 .on('click', '.product-single:not(.product-popup) .btn-cart', onAddToCartSingle); 3759 } 3760 } 3761})(jQuery); 3762 3763/** 3764 * Wolmart Plugin - Code Popup 3765 * 3766 * 3767*/ 3768 3769(function ($) { 3770 Wolmart.initCodePopup = function () { 3771 $('.box-btn.showcode span').each(function () { 3772 $(this).text('</>'); 3773 }); 3774 3775 $('.show-code-action').each(function () { 3776 var $this = $(this); 3777 3778 var tempCode = $this[0].outerHTML.replace('show-code-action', ''), 3779 deleteEnd = tempCode.slice(1, tempCode.length - 1).indexOf("<"), 3780 deleteFirst = tempCode.indexOf(">"), 3781 strTemp, code; 3782 if (deleteEnd - deleteFirst > 6) { 3783 strTemp = new RegExp('\n' + String(' ').repeat(deleteEnd - deleteFirst - 6), 'gi'); 3784 code = tempCode.replace(strTemp, '\n'); 3785 } 3786 else { 3787 code = tempCode; 3788 } 3789 $this.data('codepopup', code); 3790 }); 3791 3792 Wolmart.$body.on('click', '.box-btn.showcode', function () { 3793 var $this = $(this); 3794 if ($this.hasClass('enabled')) { 3795 $this.removeClass('enabled').addClass('disabled'); 3796 $this.children('p')[0].innerHTML = 'Show Code: Disabled'; 3797 $('.show-code-action').each(function () { 3798 var $wrapper = $(this); 3799 $wrapper.removeClass('show-code-added'); 3800 setTimeout(function () { 3801 $wrapper[0].removeChild($wrapper[0].lastElementChild); 3802 }, 300); 3803 }); 3804 } 3805 else { 3806 $this.removeClass('disabled').addClass('enabled'); 3807 $this.children('p')[0].innerHTML = 'Show Code: Enabled'; 3808 $('.show-code-action').each(function () { 3809 var $this = $(this); 3810 var showCode = document.createElement('span'); 3811 showCode.className = 'show-code'; 3812 showCode.appendChild(document.createTextNode('</>')); 3813 this.appendChild(showCode); 3814 setTimeout(function () { $this.addClass('show-code-added') }, 200); 3815 }); 3816 } 3817 }); 3818 3819 Wolmart.$body.on('click', '.show-code', function (e) { 3820 e.stopPropagation(); 3821 var $wrapper = $(this).parent(); 3822 if ($wrapper.hasClass('show-code-added')) { 3823 var btnCopy = $wrapper[0].lastElementChild; 3824 $wrapper[0].removeChild(btnCopy); 3825 3826 $('.code-popup #textareaCode').text($wrapper.data('codepopup')); 3827 3828 $('.code-copy a').html('<i class="copy-icon far fa-copy"></i>Copy to Clipboard'); 3829 Wolmart.$body.on('click', '.code-copy a', function (e) { 3830 e.preventDefault(); 3831 $('.code-popup #textareaCode').trigger('select'); 3832 document.execCommand('copy'); 3833 $(this).html('<i class="copy-icon far fa-copy"></i>Copied'); 3834 }); 3835 setTimeout(function () { 3836 Wolmart.popup({ 3837 items: { 3838 src: ".code-popup" 3839 }, 3840 type: 'inline', 3841 tLoading: '', 3842 mainClass: 'mfp-code mfp-fadein-popup' 3843 }); 3844 3845 $('.CodeMirror').remove(); 3846 CodeMirror.fromTextArea(document.getElementById('textareaCode'), 3847 { 3848 mode: 'text/html', 3849 htmlMode: true, 3850 lineWrapping: false, 3851 smartIndent: false, 3852 spellcheck: true, 3853 addModeClass: true, 3854 readOnly: true 3855 }); 3856 }, 100); 3857 3858 $wrapper[0].appendChild(btnCopy); 3859 } 3860 }); 3861 3862 Wolmart.$body.on('mouseenter mouseleave', '.show-code-action', function (e) { 3863 e.stopPropagation(); 3864 }); 3865 } 3866})(jQuery); 3867 3868/** 3869 * Womart Plugin - Calendar 3870 * 3871 * @instance multiple 3872 */ 3873 3874(function ($) { 3875 3876 function Calendar(el, options) { 3877 return this.init(el, options); 3878 } 3879 3880 // Private Members 3881 var updateHeader = function (date) { 3882 var self = this; 3883 var mt = self.settings.months[date.getMonth()]; 3884 mt += self.settings.displayYear ? ' ' + date.getFullYear() : ''; 3885 3886 self.element.find('.calendar-title').html(mt); 3887 } 3888 3889 // Public Members 3890 Calendar.defaultOptions = { 3891 months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], 3892 days: ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'], 3893 displayYear: true, // Display year in header 3894 fixedStartDay: true, // Week always begins with Sunday or Monday by setting number 0 or 1. If startDay is false, week always begin with firstday of month 3895 dayNumber: 0, // Week always begins with Sunday 3896 dayExcerpt: 3, // length of abbreviation of day. If it is equal to 3, the day will be "Sun", "Mon", etc 3897 } 3898 3899 Calendar.prototype.init = function ($el, options) { 3900
3900 var self = this; 3901 self.element = $el; // calendar container element 3902 self.settings = $.extend({}, true, 3903 Calendar.defaultOptions, 3904 Wolmart.parseOptions($el.attr('data-calendar-options')), 3905 options 3906 ); // extend default options with user defined options 3907 self.today = new Date(); 3908 3909 // Bind this to update header 3910 updateHeader = updateHeader.bind(this); 3911 3912 var $calendar = $('<div class="calendar"></div>'), 3913 $header = $('<div class="calendar-header">' + 3914 '<a href="#" class="btn-calendar btn-calendar-prev"><i class="la la-angle-left"></i></a>' + 3915 '<span class="calendar-title"></span>' + 3916 '<a href="#" class="btn-calendar btn-calendar-next"><i class="la la-angle-right"></i></a>' + 3917 '</div>'); 3918 3919 $calendar.append($header); 3920 $el.append($calendar); 3921 3922 // update Calendar header 3923 updateHeader(self.today); 3924 3925 self.render(self.today, $calendar); 3926 3927 self.bindEvents(); 3928 } 3929 3930 /** 3931 * render 3932 * 3933 * 3934 * Render Calendar 3935 * @param {Date} fd 3936 * @param {HTMLElement} $calendar 3937 */ 3938 Calendar.prototype.render = function (fd, $calendar) { 3939 var self = this; 3940 3941 // if calendar table already exists, remove it 3942 $calendar.find('table') && 3943 $calendar.find('table').remove(); 3944 3945 var $table = $('<table></table>'), 3946 $thead = $('<thead></thead>'), 3947 $tbody = $('<tbody></tbody'), 3948 y = fd.getFullYear(), 3949 m = fd.getMonth(); 3950 3951 var firstDay = new Date(y, m, 1), // get the first day of the month 3952 lastDay = new Date(y, m + 1, 0), // get the last day of the month 3953 startDayOfWeek = firstDay.getDay(); // get the first day of the week 3954 3955 if (self.settings.fixedStartDay) { 3956 startDayOfWeek = self.settings.dayNumber; 3957 3958 // If the first day of the month is different with start of week, get more days of prev month to fill calendar 3959 while (firstDay.getDay() != startDayOfWeek) { 3960 firstDay.setDate(firstDay.getDate() - 1); 3961 } 3962 3963 // If the last day of the month is difference with end of week, get more days of next month to be displayed in calendar 3964 while (lastDay.getDay() != (startDayOfWeek + 7) % 7) { 3965 lastDay.setDate(lastDay.getDate() + 1); 3966 } 3967 } 3968 3969 // Get days in week 3970 for (var i = startDayOfWeek; i < startDayOfWeek + 7; i++) { 3971 var th = $('<th>' + self.settings.days[i % 7].substring(0, self.settings.dayExcerpt) + '</th>'); 3972 3973 i % 7 == 0 && th.addClass('holiday'); 3974 3975 $thead.append(th); 3976 } 3977 3978 // Displays days from fristday to lastday in calendar 3979 3980 for (var day = firstDay; day < lastDay; day.setDate(day.getDate())) { 3981 var tr = $('<tr></tr>'); 3982 3983 // Make each row of calendar 3984 for (var i = 0; i < 7; i++) { 3985 var td = $('<td><span class="day" data-date="' + day.toISOString() + '">' + day.getDate() + '</span></td>'); 3986 3987 // If the day is equal to today 3988 (day.toDateString() == (new Date).toDateString()) && 3989 td.find('.day').addClass('today'); 3990 3991 // If the day is out of current month 3992 (day.getMonth() != fd.getMonth()) && 3993 td.find('.day').addClass('disabled'); 3994 3995 tr.append(td); 3996 day.setDate(day.getDate() + 1); 3997 } 3998 $tbody.append(tr); 3999 }; 4000 4001 $table.append($thead); 4002 $table.append($tbody); 4003 $calendar.append($table); 4004 } 4005 4006 /** 4007 * changeMonth 4008 * 4009 * 4010 * Change Month 4011 * @param {Number} dm - increment of month 4012 */ 4013 Calendar.prototype.changeMonth = function (dm) { 4014 this.today.setMonth(this.today.getMonth() + dm, 1); 4015 this.render(this.today, $(this.element).find('.calendar')); 4016 updateHeader(this.today); 4017 } 4018 4019 4020 /** 4021 * bindEvents 4022 * 4023 * 4024 * Bind events to prev & next button 4025 */ 4026 Calendar.prototype.bindEvents = function () { 4027 var self = this; 4028 4029 // Register event to prev btn 4030 $(self.element).find('.btn-calendar-prev').on('click', function (e) { 4031 self.changeMonth(-1); 4032 e.preventDefault(); 4033 }); 4034 4035 // Register event to next btn 4036 $(self.element).find('.btn-calendar-next').on('click', function (e) { 4037 self.changeMonth(1); 4038 e.preventDefault(); 4039 }); 4040 } 4041 4042 4043 Wolmart.calendar = function (selector, options) { 4044 Wolmart.$(selector).each(function () { 4045 var $this = $(this); 4046 4047 Wolmart.call(function () { 4048 new Calendar($this, options); 4049 }); 4050 }); 4051 } 4052 4053 Wolmart.initVendor = function (selector) { 4054 var $this = $(selector), 4055 $btnSearchVendor = $this.closest('.page-content').find('.toolbox .vend
4055or-search-toggle'), 4056 $phone = $this.find('.store-phone'); 4057 4058 $btnSearchVendor.on('click', function (e) { 4059 var $searchWrapper = $btnSearchVendor.closest('.vendor-toolbox').next('.vendor-search-wrapper'); 4060 if (!$searchWrapper.hasClass('open')) { 4061 $searchWrapper.addClass('open').slideDown(); 4062 } else { 4063 $searchWrapper.removeClass('open').slideUp(); 4064 } 4065 e.preventDefault(); 4066 }); 4067 4068 $phone.on('click', function () { 4069 alert('Always open these types of links in the associated app'); 4070 }); 4071 } 4072 4073 Wolmart.slideContent = function (selector) { 4074 var $this = $(selector), 4075 $content = $this.next(); 4076 4077 $this.on('click', function (e) { 4078 e.preventDefault(); 4079 4080 if (!$content.hasClass('open')) { 4081 $content.addClass('open').slideDown(); 4082 $this.find('.custom-checkbox').addClass('checked'); 4083 4084 } else { 4085 $content.removeClass('open').slideUp(); 4086 $this.find('.custom-checkbox').removeClass('checked'); 4087 } 4088 }) 4089 } 4090 4091 // Login vendor in login page 4092 Wolmart.initLoginVendor = function (selector) { 4093 var $this = $(selector), 4094 $LoginVendorPanel = $this.parent().find('.login-vendor'), 4095 $checkCustomer = $this.find('.check-customer'), 4096 $checkVendor = $this.find('.check-seller'); 4097 4098 $checkVendor.on('click', function () { 4099 $this.find('#check-seller').addClass('active'); 4100 $this.find('#check-customer').removeClass('active'); 4101 $LoginVendorPanel.slideDown(); 4102 }); 4103 4104 $checkCustomer.on('click', function () { 4105 $this.find('#check-customer').addClass('active'); 4106 $this.find('#check-seller').removeClass('active'); 4107 $LoginVendorPanel.slideUp(); 4108 }); 4109 } 4110})(jQuery); 4111/** 4112 * Wolmart Theme 4113 */ 4114(function ($) { 4115 4116 // Initialize Method while document is interactive 4117 Wolmart.initLayout = function () { 4118 // do something later... 4119 Wolmart.isotopes('.grid:not(.grid-float)'); 4120 Wolmart.stickySidebar('.sticky-sidebar'); 4121 }; 4122 4123 // Initialize Method after document has been loaded 4124 Wolmart.init = function () { 4125 // do something later... 4126 Wolmart.appearAnimate('.appear-animate'); // Run appear animation 4127 Wolmart.setTab('.nav-tabs'); // Initialize Tab 4128 Wolmart.stickyContent('.sticky-header', { scrollMode: false }); // Initialize Sticky Content 4129 Wolmart.stickyContent('.sticky-footer', { 4130 minWidth: 0, 4131 maxWidth: 767, 4132 top: 150, 4133 hide: true, 4134 max_index: 2100, 4135 scrollMode: true 4136 }); // Initialize Sticky Footer 4137 Wolmart.stickyContent('.sticky-toolbox', Wolmart.stickyToolboxOptions); 4138 Wolmart.stickyContent('.product-sticky-content', Wolmart.stickyProductOptions); 4139 Wolmart.parallax('.parallax'); // Initialize Parallax 4140 Wolmart.skrollrParallax(); // Initialize Skrollr Parallax 4141 Wolmart.initFloatingParallax(); // Initialize Floating Parallax 4142 Wolmart.menu.init(); // Initialize Menu 4143 Wolmart.initScrollTopButton(); // Initialize scroll top button 4144 Wolmart.shop.init(); // Initialize Shop 4145 Wolmart.alert('.alert') // Initialize Alert 4146 Wolmart.closeTopNotice('.banner-close'); // Initialize Close Top Notice 4147 Wolmart.accordion('.card-header > a') // Initialize Accordion 4148 Wolmart.sidebar('sidebar'); // Initialize Sidebar 4149 Wolmart.sidebar('right-sidebar'); // Initialize Right Sidebar 4150 Wolmart.productSingle('.product-single'); // Initialize all single products 4151 Wolmart.initProductSinglePage(); // Initialize Single Product Page 4152 Wolmart.initQtyInput('.quantity'); // Initialize Quantity Input 4153 Wolmart.initNavFilter('.nav-filters .nav-filter') // Initialize Isotope Navigation Filters 4154 Wolmart.calendar('.calendar-container'); // Initialize Calendar 4155 Wolmart.countDown('.product-countdown, .countdown'); // Initialize CountDown 4156 // Wolmart.initPopup(); // Initialize Popup 4157 Wolmart.initNotificationAlert(); // Initialize Notification Alert 4158 Wolmart.countTo('.count-to'); // Initialize CountTo 4159 Wolmart.initCartAction('.cart-offcanvas .cart-toggle'); // Initialize Product Cart 4160 Wolmart.Minipopup.init(); // Initialize minipopup 4161 Wolmart.headerToggleSearch('.hs-toggle'); // Initialize Header toggle search 4162 Wolmart.initVendor('.store'); // Initialize Vendor 4163 Wolmart.slideContent('.login-toggle'); // Initialize Slide Content 4164 Wolmart.slideContent('.coupon-toggle'); 4165 Wolmart.slideContent('.checkbox-toggle'); 4166 Wolmart.initLoginVendor('.user-checkbox'); // Initialize Vendor's Login 4167 Wolmart.initCodePopup(); 4168 4169 Wolmart.setupHomeProducts(); 4170 Wolmart.slider('.swiper-container'); // Initialize Slider 4171 Wolmart.call(function () { 4172 Wolmart.initHomeProducts(); 4173 }); 4174 Wolmart.call(Wolmart.slider.pgToggle); 4175 Wolmart.$window.on('resize', function () { 4176 Wolmart.call(Wolmart.slider.pgToggle); 4177 }); 4178 }; 4179})(jQuery); 4180/** 4181 * PhotoSwipe 4182 */ 4183(function ($) { 4184 var openPhotoSwipe = function($el) { 4185 var items = [ 4186 {src: $el.attr('href'), w: 0, h: 0} 4187 ]; 4188 var pswpElement = document.querySelectorAll('.pswp')[0]; 4189 var options = {}; 4190 var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options); 4191 gallery.listen('gettingData', function(index, item) { 4192 if (item.w < 1 || item.h < 1) { // unknown size 4193 var img = new Image(); 4194 img.onload = function() { // will get size after load 4195 item.w = this.width; // set image width 4196 item.h = this.height; // set image height 4197 gallery.invalidateCurrItems(); // reinit Items 4198 gallery.updateSize(true); // reinit Items 4199 } 4200 img.src = item.src; // let's download image 4201 } 4202 }); 4203 gallery.init(); 4204 }; 4205 4206 $('.image-popup-no-margins').on('click', function (e) { 4207 e.preventDefault(); 4208 openPhotoSwipe($(this)) 4209 }); 4210})(jQuery); 4211/** 4212 * Smooth Scroll 4213 */ 4214(function ($) { 4215 $('.scroll-easing').bind('click', function(event) { 4216 var anchor = $(this); 4217 $('html, body').animate({ 4218 scrollTop: $(anchor.attr('href')).offset().top -55 4219 }, 600); 4220 event.preventDefault(); 4221 }); 4222})(jQuery); 4223/** 4224 * tooltipster 4225 */ 4226$('.tooltip').tooltipster({ 4227 maxWidth: 400, 4228 contentAsHTML: true, 4229 interactive: true, 4230 // interactive: true, 4231 theme: ['tooltipster-light'] 4232}); 4233 4234/** 4235 * Wolmart Theme Initializer 4236 */ 4237(function ($) { 4238 'use strict'; 4239 4240 window.onload = function () { 4241 // Canvas Size 4242 Wolmart.canvasWidth = window.innerWidth; 4243 Wolmart.resizeTimeStamp = 0; 4244 Wolmart.resizeChanged = false;
4245 4246 // loaded 4247 Wolmart.status = 'loaded'; 4248 document.body.classList.add('loaded'); 4249 4250 Wolmart.call(Wolmart.initLayout); 4251 Wolmart.call(Wolmart.init); 4252 Wolmart.status = 'complete'; 4253 Wolmart.$window.trigger('wolmart_complete'); 4254 } 4255})(jQuery);
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.