1/** 2 * Donald Main Javascript File 3 */ 4"use strict"; 5 6var $ = jQuery.noConflict(); 7 8/* jQuery easing */ 9$.extend($.easing, { 10 def: 'easeOutQuad', 11 swing: function (x, t, b, c, d) { 12 return $.easing[$.easing.def](x, t, b, c, d); 13 }, 14 easeOutQuad: function (x, t, b, c, d) { 15 return -c * (t /= d) * (t - 2) + b; 16 }, 17 easeOutQuint: function (x, t, b, c, d) { 18 return c * ((t = t / d - 1) * t * t * t * t + 1) + b; 19 } 20}); 21 22/** 23 * Donald Object 24 */ 25window.Donald = {}; 26 27(function () { 28 29 var zoomSettingJson = '{"responsive":"true","zoomWindowFadeIn":"750","zoomWindowFadeOut":"500","borderSize":"0","zoomType":"inner","cursor":"crosshair"}'; 30 if ($('#ZoomSetting').length > 0) { 31 if ($('#ZoomSetting').val().length > 0) { 32 zoomSettingJson = $('#ZoomSetting').val(); 33 } 34 } 35 // Donald Properties 36 Donald.$window = $(window); 37 Donald.$body = $(document.body); 38 Donald.status = ''; // Donald Status 39 Donald.minDesktopWidth = 992; // Detect desktop screen 40 Donald.isIE = navigator.userAgent.indexOf("Trident") >= 0; // Detect Internet Explorer 41 Donald.isEdge = navigator.userAgent.indexOf("Edge") >= 0; // Detect Edge 42 Donald.isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); // Detect Mobile 43 //console.log(Donald.isMobile) 44 Donald.defaults = { 45 animation: { 46 name: 'fadeIn', 47 duration: '1.2s', 48 delay: '.2s' 49 }, 50 isotope: { 51 itemsSelector: '.grid-item', 52 layoutMode: 'masonry', 53 percentPosition: true, 54 masonry: { 55 columnWidth: '.grid-space' 56 }, 57 isOriginLeft: false 58 }, 59 minipopup: { 60 // info 61 message: '', 62 productClass: '', // ' product-cart', ' product-list-sm' 63 imageSrc: '', 64 imageLink: '#', 65 name: '', 66 nameLink: '#', // 'product.html', 67 price: '', 68 count: null, 69 rating: null, 70 71 // option 72 delay: 4000, // milliseconds 73 space: 20, 74 75 // template 76 priceTemplate: '<span class="product-price">{{price}}</span>', 77 ratingTemplate: '<div class="ratings-container"><div class="ratings-full"><span class="ratings" style="width:{{rating}}"></span><span class="tooltiptext tooltip-top"></span></div></div>', 78 priceQuantityTemplate: '<div class="price-box"><span class="product-quantity">{{count}}</span><span class="product-price">{{price}}</span></div>', 79 80 template: '<div class="minipopup-box"><p class="minipopup-title">{{message}}</p>' + 81 '<div class="product {{productClass}} mb-0">' + 82 '<figure class="product-media"><a href="{{imageLink}}"><img src="{{imageSrc}}" alt="{{name}}" width="90" height="90"></a></figure>' + 83 '<div class="product-detail">' + 84 '<a href="{{nameLink}}" class="product-name">{{name}}</a>' + 85 '{{detailTemplate}}' + 86 '</div>' + 87 '</div></div>', 88 }, 89 popup: { 90 removalDelay: 350, 91 callbacks: { 92 open: function () { 93 $('html').css('overflow-y', 'hidden'); 94 $('body').css('overflow-x', 'visible'); 95 $('.mfp-wrap').css('overflow', 'hidden auto'); 96 $('.sticky-header.fixed').css('padding-right', window.innerWidth - document.body.clientWidth); 97 }, 98 close: function () { 99 $('html').css('overflow-y', ''); 100 $('body').css('overflow-x', 'hidden'); 101 $('.mfp-wrap').css('overflow', ''); 102 $('.sticky-header.fixed').css('padding-right', ''); 103 } 104 } 105 }, 106 popupPresets: { 107 login: { 108 type: 'ajax', 109 mainClass: "mfp-login mfp-fade", 110 tLoading: '', 111 preloader: false 112 }, 113 video: { 114 type: 'iframe', 115 mainClass: "mfp-fade", 116 preloader: false, 117 closeBtnInside: false 118 }, 119 quickview: { 120 type: 'ajax', 121 mainClass: "mfp-product mfp-fade", 122 tLoading: '', 123 preloader: false 124 } 125 }, 126 slider: { 127 responsiveClass: true, 128 navText: ['<i class="d-icon-angle-left">', '<i class="d-icon-angle-right">'], 129 checkVisible: false, 130 items: 1, 131 smartSpeed: Donald.isEdge ? 200 : 500, 132 autoplaySpeed: Donald.isEdge ? 200 : 1000, 133 autoplayTimeout: 10000 134 135 }, 136 sliderPresets: { 137 'intro-slider': { 138 animateIn: 'fadeIn', 139 animateOut: 'fadeOut' 140 }, 141 'product-single-carousel': { 142 dots: false, 143 nav: true, 144 }, 145 'product-gallery-carousel': { 146 dots: false, 147 nav: true, 148 margin: 20, 149 items: 1, 150 responsive: { 151 576: { 152 items: 2 153 }, 154 768: { 155 items: 3 156 } 157 }, 158 } 159 }, 160 sliderThumbs: { 161 margin: 0, 162 items: 4, 163 dots: false, 164 nav: true, 165 navText: ['<i class="fas fa-chevron-left">', '<i class="fas fa-chevron-right">'] 166 }, 167 stickyContent: { 168 minWidth: Donald.minDesktopWidth, 169 maxWidth: 20000, 170 top: 300, 171 hide: false, // hide when it is not sticky. 172 max_index: 1060, // maximum z-index of sticky contents 173 scrollMode: false 174 }, 175 stickyHeader: { 176 // activeScreenWidth: Donald.minDesktopWidth 177 activeScreenWidth: 768 178 }, 179 stickyFooter: { 180 minWidth: 0, 181 maxWidth: 767, 182 //top: 100, 183 hide: false, 184 scrollMode: false 185 }, 186 stickyToolbox: { 187 minWidth: 0, 188 maxWidth: 767, 189 scrollMode: true 190 }, 191 stickySidebar: { 192 autoInit: true, 193 minWidth: 991, 194 containerSelector: '.sticky-sidebar-wrapper', 195 autoFit: true, 196 activeClass: 'sticky-sidebar-fixed', 197 top: 93, 198 bottom: 0, 199 }, 200 templateCartAddedAlert: '<div class="alert alert-simple alert-btn cart-added-alert">
200' + 201 '<a href="/cart" class="btn btn-success btn-md">Ù Ø´Ø§ÙØ¯Ù سبد Ø®Ø±ÛØ¯</a>' + 202 '<span>"{{name}}" has been added to your cart.</span>' + 203 '<button type="button" class="btn btn-link btn-close"><i class="d-icon-times"></i></button>' + 204 '</div>', 205 zoomImage: $.parseJSON(zoomSettingJson) 206 } 207 208 /** 209 * Get jQuery object 210 * @param {string|jQuery} selector 211 */ 212 Donald.$ = function (selector) { 213 return selector instanceof jQuery ? selector : $(selector); 214 } 215 216 /** 217 * Make a macro task 218 * @param {function} fn 219 * @param {number} delay 220 */ 221 Donald.call = function (fn, delay) { 222 setTimeout(fn, delay); 223 } 224 225 /** 226 * Get dom element by id 227 * @param {string} id 228 */ 229 Donald.byId = function (id) { 230 return document.getElementById(id); 231 } 232 233 /** 234 * Get dom elements by tagName 235 * @param {string} tagName 236 * @param {HTMLElement} element this can be omitted. 237 */ 238 Donald.byTag = function (tagName, element) { 239 return element ? 240 element.getElementsByTagName(tagName) : 241 document.getElementsByTagName(tagName); 242 } 243 244 /** 245 * Get dom elements by className 246 * @param {string} className 247 * @param {HTMLElement} element this can be omitted. 248 */ 249 Donald.byClass = function (className, element) { 250 return element ? 251 element.getElementsByClassName(className) : 252 document.getElementsByClassName(className); 253 } 254 255 /** 256 * Set cookie 257 * @param {string} name Cookie name 258 * @param {string} value Cookie value 259 * @param {number} exdays Expire period 260 */ 261 Donald.setCookie = function (name, value, exdays) { 262 var date = new Date(); 263 date.setTime(date.getTime() + (exdays * 24 * 60 * 60 * 1000)); 264 document.cookie = name + "=" + value + ";expires=" + date.toUTCString() + ";path=/;SameSite=None;Secure;Partitioned"; 265 } 266 267 /** 268 * Get cookie 269 * @param {string} name Cookie name 270 */ 271 Donald.getCookie = function (name) { 272 var n = name + "="; 273 var ca = document.cookie.split(';'); 274 for (var i = 0; i < ca.length; ++i) { 275 var c = ca[i]; 276 while (c.charAt(0) == ' ') { 277 c = c.substring(1); 278 } 279 if (c.indexOf(n) == 0) { 280 return c.substring(n.length, c.length); 281 } 282 } 283 return ""; 284 } 285 286 /** 287 * Parse options string to object 288 * @param {string} options 289 */ 290 Donald.parseOptions = function (options) { 291 return 'string' == typeof options ? 292 JSON.parse(options.replace(/'/g, '"').replace(';', '')) : 293 {}; 294 } 295 296 /** 297 * Parse html template with variables. 298 * @param {string} template 299 * @param {object} vars 300 */ 301 Donald.parseTemplate = function (template, vars) { 302 return template.replace(/\{\{(\w+)\}\}/g, function () { 303 return vars[arguments[1]]; 304 }); 305 } 306 307 /** 308 * @function isOnScreen 309 * @param {HTMLElement} el 310 * @param {number} dx 311 * @param {number} dy 312 */ 313 Donald.isOnScreen = function (el, dx, dy) { 314 var a = window.pageXOffset, 315 b = window.pageYOffset, 316 o = el.getBoundingClientRect(), 317 x = o.left + a, 318 y = o.top + b, 319 ax = typeof dx == 'undefined' ? 0 : dx, 320 ay = typeof dy == 'undefined' ? 0 : dy; 321 322 return y + o.height + ay >= b && 323 y <= b + window.innerHeight + ay && 324 x + o.width + ax >= a && 325 x <= a + window.innerWidth + ax; 326 } 327 328 /** 329 * @function appear 330 * 331 * @param {HTMLElement} el 332 * @param {function} fn 333 * @param {object} options 334 */ 335 Donald.appear = (function () { 336 var checks = [], 337 timerId = false, 338 one; 339 340 var checkAll = function () { 341 for (var i = checks.length; i--;) { 342 one = checks[i]; 343 344 if (Donald.isOnScreen(one.el, one.options.accX, one.options.accY)) { 345 typeof $(one.el).data('appear-callback') == 'function' && $(one.el).data('appear-callback').call(one.el, one.data); 346 one.fn && one.fn.call(one.el, one.data); 347 checks.splice(i, 1); 348 } 349 } 350 }; 351 352 window.addEventListener('scroll', checkAll, { passive: true });
353 window.addEventListener('resize', checkAll, { passive: true }); 354 $(window).on('appear.check', checkAll); 355 356 return function (el, fn, options) { 357 var settings = { 358 data: undefined, 359 accX: 0, 360 accY: 0 361 }; 362 363 if (options) { 364 options.data && (settings.data = options.data); 365 options.accX && (settings.accX = options.accX); 366 options.accY && (settings.accY = options.accY); 367 } 368 369 checks.push({ el: el, fn: fn, options: settings }); 370 if (!timerId) { 371 timerId = Donald.requestTimeout(checkAll, 100); 372 } 373 } 374 })(); 375 376 Donald.zoomImageObjects = []; 377 /** 378 * @function zoomImage 379 * 380 * @requires elevateZoom 381 * @param {string|jQuery} selector 382 */ 383 Donald.zoomImage = function (selector) { 384 if ($.fn.elevateZoom && selector) { 385 Donald.$(selector).find('img').each(function () { 386 var $this = $(this); 387 Donald.defaults.zoomImage.zoomContainer = $this.parent(); 388 $this.elevateZoom(Donald.defaults.zoomImage); 389 Donald.zoomImageObjects.push($this); 390 }); 391 } 392 } 393 394 /** 395 * @function initZoom 396 */ 397 Donald.initZoom = function () { 398 window.addEventListener('resize', function () { 399 Donald.zoomImageObjects.forEach(function ($img) { 400 $img.each(function () { 401 var elevateZoom = $(this).data('elevateZoom'); 402 elevateZoom && elevateZoom.refresh(); 403 }) 404 }); 405 }, { passive: true }); 406 } 407 408 /** 409 * @function countTo 410 * 411 * @requires jQuery.countTo 412 * @param {string} selector 413 */ 414 Donald.countTo = function (selector) { 415 if ($.fn.countTo) { 416 Donald.$(selector).each(function () { 417 Donald.appear(this, function () { 418 var $this = $(this); 419 setTimeout(function () { 420 $this.countTo({ 421 onComplete: function () { 422 $this.addClass('complete'); 423 } 424 }); 425 }, 300); 426 }) 427 }); 428 } 429 } 430 431 /** 432 * @function countdown 433 * 434 * @requires jquery-countdown 435 * @param {string} selector 436 */ 437 Donald.countdown = function (selector) { 438 if ($.fn.countdown) { 439 Donald.$(selector).each(function () { 440 var $this = $(this), 441 untilDate = $this.data('until'), 442 compact = $this.data('compact'), 443 dateFormat = (!$this.data('format')) ? 'DHMS' : $this.data('format'), 444 newLabels = (!$this.data('labels-short')) ? 445 ['Years', 'Months', 'Weeks', 'Days', 'Hours', 'Minutes', 'Seconds'] : 446 ['Years', 'Months', 'Weeks', 'Days', 'Hours', 'Mins', 'Secs'], 447 newLabels1 = (!$this.data('labels-short')) ? 448 ['Year', 'Month', 'Week', 'Day', 'Hour', 'Minute', 'Second'] : 449 ['Year', 'Month', 'Week', 'Day', 'Hour', 'Min', 'Sec']; 450 451 var newDate; 452 453 // Split and created again for ie and edge 454 if (!$this.data('relative')) { 455 var untilDateArr = untilDate.split(", "), // data-until 2019, 10, 8 - yy,mm,dd 456 newDate = new Date(untilDateArr[0], untilDateArr[1] - 1, untilDateArr[2]); 457 } else { 458 newDate = untilDate; 459 } 460 461 $this.countdown({ 462 until: newDate, 463 format: dateFormat, 464 padZeroes: true, 465 compact: compact, 466 compactLabels: [' y', ' m', ' w', ' days, '], 467 timeSeparator: ' : ', 468 labels: newLabels, 469 labels1: newLabels1 470 }); 471 }); 472 } 473 } 474 475 476 /** 477 * @function priceSlider 478 * 479 * @requires noUiSlider 480 * @param {string} selector 481 * @param {object} option 482 */ 483 Donald.priceSlider = function (selector, option) { 484 if (typeof noUiSlider === 'object') { 485 Donald.$(selector).each(function () { 486 var self = this; 487 488 noUiSlider.create(self, $.extend(true, { 489 start: [18, 35], 490 connect: true, 491 step: 1, 492 range: { 493 min: 18, 494 max: 35 495 } 496 }, option)); 497 498 // Update Price Range 499 self.noUiSlider.on('update', function (values, handle) { 500 var values = values.map(function (value) { 501 return '$' + parseInt(value); 502 }) 503 $(self).parent().find('.filter-price-range').text(values.join(' - ')); 504 }); 505 }); 506 } 507 } 508 509 Donald.lazyload = function (selector, force) { 510 function load() { 511 this.setAttribute('src', this.getAttribute('data-src')); 512 this.addEventListener('load', function () { 513 this.style['padding-top'] = ''; 514 this.classList.remove('lazy-img'); 515 }); 516 } 517 518 // Lazyload images 519 Donald.$(selector).find('.lazy-img').each(function () { 520 if ('undefined' != typeof force && force) { 521 load.call(this); 522 } else { 523 Donald.appear(this, load); 524 } 525 }) 526 } 527 528 /** 529 * @function isotopes 530 * 531 * @requires isotope,imagesLoaded 532 * @param {string} selector 533 * @param {object} options 534 */ 535 Donald.isotopes = function (selector, options) { 536 if (typeof imagesLoaded === 'function' && $.fn.isotope) { 537 var self = this; 538 539 Donald.$(selector).each(function () { 540 var $this = $(this), 541 settings = $.extend(true, {}, 542 Donald.defaults.isotope, 543 Donald.parseOptions($this.attr('data-grid-options')), 544 options ? options : {} 545 ); 546 547 Donald.lazyload($this); 548 $this.imagesLoaded(function () { 549 settings.customInitHeight && $this.height($this.height()); 550 settings.customDelay && Donald.call(function () { 551 $this.isotope(settings); 552 }, parseInt(settings.customDelay)); 553 554 $this.isotope(settings); 555 }) 556 }); 557 } 558 } 559 560 /** 561 * @function initNavFilter 562 * 563 * @requires isotope 564 * @param {string} selector 565 */ 566 Donald.initNavFilter = function (selector) { 567 if ($.fn.isotope) { 568 Donald.$(selector).on('click', function (e) { 569 var $this = $(this), 570 filterValue = $this.attr('data-filter'), 571 filterTarget = $this.parent().parent().attr('data-target'); 572 (filterTarget ? $(filterTarget) : $('.grid')) 573 .isotope({ filter: filterValue }) 574 .isotope('on', 'arrangeComplete', function () { 575 576 577 Donald.$window.trigger('appear.check'); 578 }); 579 $this.parent().siblings().children().removeClass('active'); 580 $this.addClass('active'); 581 e.preventDefault(); 582 }); 583 } 584 } 585 586 /** 587 * @function parallax
588 * Initialize Parallax Background 589 * @requires themePluginParallax 590 * @param {string} selector 591 */ 592 Donald.parallax = function (selector, options) { 593 if ($.fn.themePluginParallax) { 594 Donald.$(selector).each(function () { 595 var $this = $(this); 596 $this.themePluginParallax( 597 $.extend(true, Donald.parseOptions($this.attr('data-parallax-options')), options) 598 ); 599 }); 600 } 601 } 602 603 /** 604 * @function headerToggleSearch 605 * Init header toggle search. 606 * @param {string} selector 607 */ 608 609 Donald.headerToggleSearch = function (selector) { 610 var $search = Donald.$(selector); 611 $search.find('.form-control') 612 .on('focusin', function (e) { 613 $search.addClass('show'); 614 }) 615 .on('focusout', function (e) { 616 $search.removeClass('show'); 617 }); 618 } 619 620 /** 621 * @function stickyHeader 622 * Init sticky header 623 * @param {string} selector 624 */ 625 Donald.stickyHeader = function (selector) { 626 var $stickyHeader = Donald.$(selector); 627 if ($stickyHeader.length == 0) return; 628 629 var height, top, isWrapped = false; 630 631 // define wrap function 632 var stickyHeaderWrap = function () { 633 height = $stickyHeader[0].offsetHeight; 634 top = $stickyHeader.offset().top + height; 635 636 // if sticky header has category dropdown, increase top 637 if ($stickyHeader.hasClass('has-dropdown')) { 638 var $box = $stickyHeader.find('.category-dropdown .dropdown-box'); 639 640 if ($box.length) { 641 top += $stickyHeader.find('.category-dropdown .dropdown-box')[0].offsetHeight; 642 } 643 } 644 645 // wrap sticky header 646 if (!isWrapped && window.innerWidth >= Donald.defaults.stickyHeader.activeScreenWidth) { 647 isWrapped = true; 648 $stickyHeader.wrap('<div class="sticky-wrapper" style="height:' + height + 'px"></div>'); 649 } 650 651 Donald.$window.off('resize', stickyHeaderWrap); 652 }; 653 654 // define refresh function 655 var stickyHeaderRefresh = function () { 656 var isFixed = window.innerWidth >= Donald.defaults.stickyHeader.activeScreenWidth && window.pageYOffset >= top; 657 658 // fix or unfix 659 if (isFixed) { 660 $stickyHeader[0].classList.add('fixed'); 661 document.body.classList.add('sticky-header-active'); 662 } else { 663 $stickyHeader[0].classList.remove('fixed'); 664 document.body.classList.remove('sticky-header-active'); 665 } 666 }; 667 668 // register events 669 window.addEventListener('scroll', stickyHeaderRefresh, { passive: true }); 670 Donald.$window.on('resize', stickyHeaderWrap); 671 Donald.$window.on('resize', stickyHeaderRefresh); 672 673 // init 674 Donald.call(stickyHeaderWrap, 500); 675 Donald.call(stickyHeaderRefresh, 500); 676 } 677 678 /** 679 * @function stickyContent 680 * Init Sticky Content 681 * @param {string, Object} selector 682 * @param {Object} settings 683 */ 684 Donald.stickyContent = function (selector, settings) { 685 var $stickyContents = Donald.$(selector), 686 options = $.extend({}, Donald.defaults.stickyContent, settings), 687 scrollPos = window.pageYOffset; 688 689 if (0 == $stickyContents.length) return; 690 691 var setTopOffset = function ($item) { 692 var offset = 0, 693 index = 0; 694 $('.sticky-content.fixed.fix-top').each(function () { 695 offset += $(this)[0].offsetHeight; 696 index++; 697 }); 698 $item.data('offset-top', offset); 699 $item.data('z-index', options.max_index - index); 700 } 701 702 var setBottomOffset = function ($item) { 703 var offset = 0, 704 index = 0; 705 $('.sticky-content.fixed.fix-bottom').each(function () { 706 offset += $(this)[0].offsetHeight; 707 index++; 708 }); 709 $item.data('offset-bottom', offset); 710 $item.data('z-index', options.max_index - index); 711 } 712 713 var wrapStickyContent = function ($item, height) { 714 if (window.innerWidth >= options.minWidth && window.innerWidth <= options.maxWidth) { 715 $item.wrap('<div class="sticky-content-wrapper"></div>'); 716 // tyam header height 717 //$item.parent().css('height', height + 'px'); 718 $item.data('is-wrap', true); 719 } 720 } 721 722 var initStickyContent = function () { 723 $stickyContents.each(function (index) { 724 var $item = $(this); 725 if (!$item.data('is-wrap')) { 726 var height = $item.removeClass('fixed').outerHeight(true), top; 727 top = $item.offset().top + height; 728 729 // if sticky header has category dropdown, increase top 730 if ($item.hasClass('has-dropdown')) { 731 var $box = $item.find('.category-dropdown .dropdown-box'); 732 733 if ($box.length) { 734 top += $box[0].offsetHeight; 735 } 736 } 737 738 $item.data('top', top); 739 wrapStickyContent($item, height); 740 } else { 741 if (window.innerWidth < options.minWidth || window.innerWidth >= options.maxWidth) { 742 $item.unwrap('.sticky-content-wrapper'); 743 $item.data('is-wrap', false); 744 } 745 } 746 }); 747 } 748 749 var refreshStickyContent = function (e) { 750 751 if (e && !e.isTrusted) return; 752 $stickyContents.each(function (index) { 753 var $item = $(this), 754 showContent = true; 755 if (options.scrollMode) { 756 showContent = scrollPos > window.pageYOffset; 757 scrollPos = window.pageYOffset; 758 } 759 if (window.pageYOffset > (false == options.top ? $item.data('top') : options.top) && window.innerWidth >= options.minWidth && window.innerWidth <= options.maxWidth) { 760 if ($item.hasClass('fix-top')) { 761 if (undefined === $item.data('offset-top')) { 762 setTopOffset($item); 763 } 764 $item.css('margin-top', $item.data('offset-top') + 'px'); 765 } else if ($item.hasClass('fix-bottom')) { 766 if (undefined === $item.data('offset-bottom')) { 767 setBottomOffset($item); 768 } 769 $item.css('margin-bottom', $item.data('offset-bottom') + 'px'); 770 } 771 $item.css('z-index', $item.data('z-index')); 772 if (options.scrollMode) { 773 if ((showContent && $item.hasClass('fix-top')) || (!showContent && $item.hasClass('fix-bottom'))) { 774 $item.addClass('fixed'); 775 } else { 776 $item.removeClass('fixed'); 777 $item.css('margin', ''); 778 } 779 } else { 780 $item.addClass('fixed'); 781 } 782 options.hide && $item.parent('.sticky-content-wrapper').css('display', ''); 783 } else { 784 $item.removeClass('fixed'); 785 $item.css('margin-top', ''); 786 $item.css('margin-bottom', ''); 787 options.hide && $item.parent('.sticky-content-wrapper').css('display', 'none'); 788 } 789 }); 790 } 791 792 var resizeStickyContent = function (e) { 793 $stickyContents.removeData('offset-top') 794 .removeData('offset-bottom') 795 .removeClass('fixed') 796 .css('margin', '') 797 .css('z-index', ''); 798 799 Donald.call(function () { 800 initStickyContent(); 801 refreshStickyContent(); 802 }); 803 } 804 805 setTimeout(initStickyContent, 550); 806 setTimeout(refreshStickyContent, 600); 807 808 Donald.call(function () { 809 window.addEventListener('scroll', refreshStickyContent, { passive: true });
810 Donald.$window.on('resize', resizeStickyContent); 811 }, 700); 812 } 813 814 /** 815 * @function alert 816 * Register events for alert 817 * @param {string} selector 818 */ 819 Donald.initAlert = function (selector) { 820 Donald.$body.on('click', selector + ' .btn-close', function (e) { 821 $(this).closest(selector).fadeOut(function () { 822 $(this).remove(); 823 }); 824 }); 825 } 826 827 828 /** 829 * @function accordion 830 * Register events for accordion 831 * @param {string} selector 832 */ 833 Donald.initAccordion = function (selector) { 834 Donald.$body.on('click', selector, function (e) { 835 var $this = $(this), 836 $header = $this, 837 $body = $this.closest('.card').find($this.attr('href')), 838 $parent = $this.closest('.accordion'); 839 840 e.preventDefault(); 841 842 if (0 === $parent.find(".collapsing").length && 843 0 === $parent.find(".expanding").length) { 844 845 if ($body.hasClass('expanded')) { 846 if (!$parent.hasClass('radio-type')) 847 slideToggle($body); 848 849 } else if ($body.hasClass('collapsed')) { 850 851 if ($parent.find('.expanded').length > 0) { 852 if (Donald.isIE) { 853 slideToggle($parent.find('.expanded'), function () { 854 slideToggle($body); 855 }); 856 857 } else { 858 slideToggle($parent.find('.expanded')); 859 slideToggle($body); 860 } 861 } else { 862 slideToggle($body); 863 } 864 } 865 } 866 }); 867 868 // define slideToggle method 869 var slideToggle = function ($wrap, callback) { 870 var $header = $wrap.closest('.card').find(selector); 871 872 if ($wrap.hasClass("expanded")) { 873 $header 874 .removeClass("collapse") 875 .addClass("expand"); 876 $wrap 877 .addClass("collapsing") 878 .slideUp(300, function () { 879 $wrap.removeClass("expanded collapsing").addClass("collapsed"); 880 callback && callback(); 881 }) 882 883 } else if ($wrap.hasClass("collapsed")) { 884 $header 885 .removeClass("expand") 886 .addClass("collapse"); 887 $wrap 888 .addClass("expanding") 889 .slideDown(300, function () { 890 $wrap.removeClass("collapsed expanding").addClass("expanded"); 891 callback && callback(); 892 }) 893 } 894 }; 895 } 896 897 898 /** 899 * @function tab 900 * Register events for tab 901 * @param {string} selector 902 */ 903 Donald.initTab = function (selector) { 904 905 Donald.$body 906 // tab nav link 907 .on('click', '.tab .nav-link', function (e) { 908 var $this = $(this); 909 e.preventDefault(); 910 911 if (!$this.hasClass("active")) { 912 var $panel = $($this.attr('href')); 913 $panel.parent().find('.active').removeClass('in active'); 914 $panel.addClass('active in'); 915 916 $this.parent().parent().find('.active').removeClass('active'); 917 $this.addClass('active'); 918 } 919 }) 920 921 // link to tab 922 .on('click', '.link-to-tab', function (e) { 923 var selector = $(e.currentTarget).attr('href'), 924 $tab = $(selector), 925 $nav = $tab.parent().siblings('.nav'); 926 e.preventDefault(); 927 928 $tab.siblings().removeClass('active in'); 929 $tab.addClass('active in'); 930 $nav.find('.nav-link').removeClass('active'); 931 $nav.find('[href="' + selector + '"]').addClass('active'); 932 933 $('html').animate({ 934 scrollTop: $tab.offset().top - 150 935 }); 936 }); 937 } 938 939 /** 940 * @function playableVideo 941 * 942 * @param {string} selector 943 */ 944 Donald.playableVideo = function (selector) { 945 $(selector + ' .video-play').on('click', function (e) { 946 var $video = $(this).closest(selector); 947 if ($video.hasClass('playing')) { 948 $video.removeClass('playing') 949 .addClass('paused') 950 .find('video')[0].pause(); 951 } else { 952 $video.removeClass('paused') 953 .addClass('playing') 954 .find('video')[0].play(); 955 } 956 e.preventDefault(); 957 }); 958 $(selector + ' video').on('ended', function () { 959 $(this).closest(selector).removeClass('playing'); 960 }); 961 } 962 963 /** 964 * @function appearAnimate 965 * 966 * @param {string} selector 967 */ 968 Donald.appearAnimate = function (selector) { 969 Donald.$(selector).each(function () { 970 var el = this; 971 Donald.appear(el, function () { 972 if (el.classList.contains('appear-animate')) { 973 var settings = $.extend({}, Donald.defaults.animation, Donald.parseOptions(el.getAttribute('data-animation-options'))); 974 975 Donald.call(function () { 976 setTimeout( 977 function () { 978 el.style['animation-duration'] = settings.duration; 979 el.classList.add(settings.name); 980 el.classList.add('appear-animation-visible'); 981 }, 982 settings.delay ? Number(settings.delay.slice(0, -1)) * 1000 : 0 983 ); 984 }); 985 } 986 }); 987 }); 988 } 989 990 /** 991 * @function stickySidebar 992 * 993 * @requires themeSticky 994 * @param {string} selector 995 */ 996 Donald.stickySidebar = function (selector) { 997 if ($.fn.themeSticky) { 998 Donald.$(selector).each(function () { 999 var $this = $(this); 1000 $this.themeSticky($.extend(Donald.defaults.stickySidebar, Donald.parseOptions($this.attr('data-sticky-options')))); 1001 $this.trigger('recalc.pin'); 1002 }); 1003 } 1004 } 1005 /** 1006 * @function refreshSidebar 1007 * 1008 * @param {string} selector 1009 */ 1010 Donald.refreshSidebar = function (selector) { 1011 if ($.fn.themeSticky) { 1012 Donald.$(selector).each(function () { 1013 $(this).trigger('recalc.pin'); 1014 }); 1015 } 1016 } 1017 1018 /** 1019 * @function ratingTooltip 1020 * Find all .ratings-full from root, and initialize tooltip. 1021 * 1022 * @param {HTMLElement} root 1023 */ 1024 Donald.ratingTooltip = function (root) { 1025 var els = Donald.byClass('ratings-full', root ? root : document.body), 1026 len = els.length; 1027 1028 var ratingHandler = function () { 1029 var res = this.firstElementChild.clientWidth / this.clientWidth * 5; 1030 this.lastElementChild.innerText = res ? res.toFixed(2) : res; 1031 } 1032 for (var i = 0; i < len; ++i) { 1033 els[i].addEventListener('mouseover', ratingHandler); 1034 els[i].addEventListener('touchstart', ratingHandler); 1035 } 1036 } 1037 1038 /** 1039 * @function popup 1040 * @requires magnificPopup 1041 * @params {object} options 1042 * @params {string|undefined} preset 1043 */ 1044 Donald.popup = function (options, preset) { 1045 var mpInstance = $.magnificPopup.instance, 1046 opt = $.extend(true, {}, 1047 Donald.defaults.popup, 1048 ('undefined' != typeof preset) ? Donald.defaults.popupPresets[preset] : {}, 1049 options 1050 ); 1051 1052 // if something is already opened ( except login popup ) 1053 if (mpInstance.isOpen && mpInstance.content /*&& !mpInstance.content.hasClass('login-popup')*/) { 1054 mpInstance.close(); // close current 1055 setTimeout(function () { // and open new after a moment 1056 $.magnificPopup.open(opt); 1057 }, 500); 1058 } else { 1059 $.magnificPopup.open(opt); // if nothing is opened, open new 1060 } 1061 } 1062 1063 /** 1064 * @function initPopups 1065 */ 1066 Donald.initPopups = function () { 1067 1068 Donald.$body 1069 // Register Login Popup 1070 .on('click', 'a.login, .login-link', function (e) { 1071 //e.preventDefault(); 1072 debugger; 1073 var _popup = $(e.currentTarget).attr('data-popup'); 1074 if (_popup === 'true') { 1075 1076 e.preventDefault(); 1077 1078 Donald.popup({ 1079 items: { 1080 src: '/Account/LoginRegisterPartial' //$(e.currentTarget).attr('href') 1081 } 1082 , 1083 callbacks: { 1084 ajaxContentAdded: function () { 1085 1086 setNumeric(); 1087 setNumericCode(); 1088 1089 $.validator.unobtrusive.parse("#form-login"); 1090 $.validator.unobtrusive.parse("#form-verification"); 1091 $.validator.unobtrusive.parse("#form-password"); 1092 $.validator.unobtrusive.parse("#form-new-password"); 1093 1094 $('#form-login input[name=UserName]').focus(); 1095 } 1096 } 1097 }, 'login'); 1098 } 1099 }) 1100 1101 // Register "Register" Popup 1102 .on('click', '.register-link', function (e) { 1103 e.preventDefault(); 1104 Donald.popup({ 1105 items: { 1106 src: $(e.currentTarget).attr('href') 1107 }, 1108 callbacks: { 1109 ajaxContentAdded: function () { 1110 this.wrap.find('[href="#register"]').click(); 1111 } 1112 } 1113 }, 'login'); 1114 }) 1115 1116 // Register "Play Video" Popup 1117 .on('click', '.btn-iframe', function (e) { 1118 e.preventDefault(); 1119 Donald.popup({ 1120 items: { 1121 src: $(e.currentTarget).attr('href') 1122 } 1123 }, 'video'); 1124 }) 1125 1126 // .on('click', '.btn-Message-Pop', function (e) { 1127 // e.preventDefault(); 1128 // Donald.popup({ 1129 // items: { 1130 // src: $(e.currentTarget).attr('href') 1131 // } 1132 // }, 'msg'); 1133 //}); 1134 /******************************************* tyam newsLatter ********************************************/ 1135 // Open newsletter Popup after 7.5s in home pages 1136 //if (Donald.$body.hasClass('home') && Donald.getCookie('hideNewsletterPopup') !== 'true') { 1137 // setTimeout(function () { 1138 // Donald.popup({ 1139 // items: { 1140 // src: '/Home/Newsletter' 1141 // }, 1142 // type: 'ajax', 1143 // tLoading: '', 1144 // mainClass: 'mfp-newsletter mfp-flip-popup', 1145 // callbacks: { 1146 // beforeClose: function () { 1147 // // if "do not show" is checked 1148 // $('#hide-newsletter-popup')[0].checked && Donald.setCookie('hideNewsletterPopup', true, 7); 1149 // } 1150 // }, 1151 // }); 1152 // }, 7500); 1153 // /************** tyam newsLatter end ************/ 1154 //} 1155 } 1156 1157 /** 1158 * @function initPurchasedMinipopup 1159 */ 1160 1161 Donald.initPurchasedMinipopup = function () { 1162 if (Donald.byClass('product-single').length || Donald.byClass('main-content').length) { 1163 setInterval(function () { 1164 Donald.Minipopup.open({ 1165 message: 'Someone just purchased below.', 1166 productClass: ' product-list-sm', 1167 name: 'Daisy Bag Sonia by Sonia Rykiel', 1168 nameLink: 'ProductDetail', 1169 imageSrc: '../content/template1/images/cart/product-1.jpg', 1170 price: '$199', 1171 rating: 5 1172 }, function ($box) { 1173 Donald.ratingTooltip($box[0]); 1174 }); 1175 }, 60000); 1176 } 1177 } 1178 1179 /** 1180 * @function initScrollTopButton 1181 */ 1182 Donald.initScrollTopButton = function () { 1183 // register scroll top button 1184 1185 var domScrollTop = Donald.byId('scroll-top'); 1186 1187 if (domScrollTop) { 1188 domScrollTop.addEventListener('click', function (e) { 1189 $('html, body').animate({ scrollTop: 0 }, 600); 1190 e.preventDefault(); 1191 }); 1192 1193 var refreshScrollTop = function () { 1194 if (window.pageYOffset > 400) { 1195 domScrollTop.classList.add('show'); 1196 } else { 1197 domScrollTop.classList.remove('show'); 1198 } 1199 } 1200 1201 Donald.call(refreshScrollTop, 500); 1202 window.addEventListener('scroll', refreshScrollTop, { passive: true });
1203 } 1204 } 1205 1206 /** 1207 * @function requestTimeout 1208 * @param {function} fn 1209 * @param {number} delay 1210 */ 1211 Donald.requestTimeout = function (fn, delay) { 1212 var handler = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame; 1213 if (!handler) { 1214 return setTimeout(fn, delay); 1215 } 1216 var start, rt = new Object(); 1217 1218 function loop(timestamp) { 1219 if (!start) { 1220 start = timestamp; 1221 } 1222 var progress = timestamp - start; 1223 progress >= delay ? fn() : rt.val = handler(loop); 1224 }; 1225 1226 rt.val = handler(loop); 1227 return rt; 1228 } 1229 1230 /** 1231 * @function requestInterval 1232 * @param {function} fn 1233 * @param {number} step 1234 * @param {number} timeOut 1235 */ 1236 Donald.requestInterval = function (fn, step, timeOut) { 1237 var handler = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame; 1238 if (!handler) { 1239 if (!timeOut) 1240 return setTimeout(fn, timeOut); 1241 else 1242 return setInterval(fn, step); 1243 } 1244 var start, last, rt = new Object(); 1245 function loop(timestamp) { 1246 if (!start) { 1247 start = last = timestamp; 1248 } 1249 var progress = timestamp - start; 1250 var delta = timestamp - last; 1251 if (!timeOut || progress < timeOut) { 1252 if (delta > step) { 1253 fn(); 1254 rt.val = handler(loop); 1255 last = timestamp; 1256 } else { 1257 rt.val = handler(loop); 1258 } 1259 } else { 1260 fn(); 1261 } 1262 }; 1263 rt.val = handler(loop); 1264 return rt; 1265 } 1266 1267 /** 1268 * @function deleteTimeout 1269 * @param {number} timerID 1270 */ 1271 Donald.deleteTimeout = function (timerID) { 1272 if (!timerID) { 1273 return; 1274 } 1275 var handler = window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame; 1276 if (!handler) { 1277 return clearTimeout(timerID); 1278 } 1279 if (timerID.val) { 1280 return handler(timerID.val); 1281 } 1282 } 1283 1284 /** 1285 * @function sidebar 1286 */ 1287 Donald.sidebar = (function () { 1288 var is_mobile = window.innerWidth < Donald.minDesktopWidth; 1289 var onResizeNavigationStyle = function () { 1290 if (window.innerWidth < Donald.minDesktopWidth && !is_mobile) { 1291 this.$sidebar.find('.sidebar-content, .filter-clean').removeAttr('style'); 1292 this.$sidebar.find('.sidebar-content').attr('style', ''); 1293 this.$sidebar.siblings('.toolbox').children(':not(:first-child)').removeAttr('style'); 1294 } else if (window.innerWidth >= Donald.minDesktopWidth) { 1295 if (!this.$sidebar.hasClass('closed') && is_mobile) { 1296 this.$sidebar.addClass('closed') 1297 this.$sidebar.find('.sidebar-content').css('display', 'none'); 1298 } 1299 } 1300 is_mobile = window.innerWidth < Donald.minDesktopWidth; 1301 } 1302 1303 /** 1304 * @class Sidebar 1305 * Sidebar active class will be added to body tag : "sidebar class" + "-active" 1306 */ 1307 function Sidebar(name) { 1308 return this.init(name); 1309 } 1310 1311 Sidebar.prototype.init = function (name) { 1312 var self = this; 1313 1314 self.name = name; 1315 self.$sidebar = $('.' + name); 1316 self.isNavigation = false; 1317 1318 // If sidebar exists 1319 if (self.$sidebar.length) { 1320 1321 // check if navigation style 1322 self.isNavigation = self.$sidebar.hasClass('sidebar-fixed') && 1323 self.$sidebar.parent().hasClass('toolbox-wrap'); 1324 1325 if (self.isNavigation) { 1326 onResizeNavigationStyle = onResizeNavigationStyle.bind(this); 1327 Donald.$window.on('resize', onResizeNavigationStyle); 1328 } 1329 1330 Donald.$window.on('resize', function () { 1331 Donald.$body.removeClass(name + '-active'); 1332 }); 1333 1334 1335 /******************************************* tyam left sidebar ********************************************/ 1336 if ($('#isRtl').val() !== 'true') { 1337 //// Register toggle event 1338 self.$sidebar.find('.sidebar-toggle, .sidebar-toggle-btn') 1339 .add(name === 'sidebar' ? '.left-sidebar-toggle' : ('.' + name + '-toggle')) 1340 .on('click', function (e) {
1341 self.toggle(); 1342 $(this).blur(); 1343 $('.sticky-sidebar').trigger('recalc.pin.left', [400]); 1344 e.preventDefault(); 1345 }); 1346 1347 // Register close event 1348 self.$sidebar.find('.sidebar-overlay, .sidebar-close') 1349 .on('click', function (e) { 1350 Donald.$body.removeClass(name + '-active'); 1351 $('.sticky-sidebar').trigger('recalc.pin.left', [400]); 1352 e.preventDefault(); 1353 }); 1354 /********** end tyam left sidebar***********/ 1355 } 1356 else { 1357 /******************************************* tyam right sidebar ********************************************/ 1358 self.$sidebar.find('.sidebar-toggle, .sidebar-toggle-btn') 1359 .add(name === 'sidebar' ? '.right-sidebar-toggle' : ('.' + name + '-toggle')) 1360 .on('click', function (e) { 1361 var is_mobile = window.innerWidth < Donald.minDesktopWidth; 1362 self.toggle(); 1363 $(this).blur(); 1364 $('.sticky-sidebar').trigger('recalc.pin.right', [400]); 1365 if (is_mobile) { 1366 if ($('body').hasClass(name + '-active')) { 1367 $('body').css('position', 'fixed') 1368 } 1369 else { 1370 $('body').css('position', '') 1371 } 1372 } 1373 1374 e.preventDefault(); 1375 }); 1376 1377 // Register close event right 1378 self.$sidebar.find('.sidebar-overlay, .sidebar-close') 1379 .on('click', function (e) { 1380 var is_mobile = window.innerWidth < Donald.minDesktopWidth; 1381 Donald.$body.removeClass(name + '-active'); 1382 $('.sticky-sidebar').trigger('recalc.pin.right', [400]); 1383 if (is_mobile) { 1384 $('body').css('position', '') 1385 } 1386 e.preventDefault(); 1387 }); 1388 /********** end tyam right sidebar***********/ 1389 } 1390 1391 } 1392 return false; 1393 } 1394 1395 Sidebar.prototype.toggle = function () { 1396 var self = this; 1397 1398 // if fixed sidebar 1399 if (window.innerWidth >= Donald.minDesktopWidth && self.$sidebar.hasClass('sidebar-fixed')) { 1400 1401 // is closed ? 1402 var isClosed = self.$sidebar.hasClass('closed'); 1403 1404 // if navigation style's sidebar 1405 if (self.isNavigation) { 1406 1407 isClosed || self.$sidebar.find('.filter-clean').hide(); 1408 1409 self.$sidebar.siblings('.toolbox').children(':not(:first-child)').fadeToggle('fast'); 1410 1411 self.$sidebar 1412 .find('.sidebar-content') 1413 .stop() 1414 .animate( 1415 { 1416 'height': 'toggle', 1417 'margin-bottom': isClosed ? 'toggle' : -6 1418 }, function () { 1419 $(this).css('margin-bottom', ''); 1420 isClosed && self.$sidebar.find('.filter-clean').fadeIn('fast'); 1421 } 1422 ); 1423 } 1424 1425 // if shop sidebar 1426 if (self.$sidebar.hasClass('shop-sidebar')) { 1427 1428 // change columns 1429 var $wrapper = $('.main-content .product-wrapper'); 1430 if ($wrapper.length) { 1431 if ($wrapper.hasClass('product-lists')) { 1432 1433 // if list type, toggle 2 cols or 1 col 1434 $wrapper.toggleClass('row cols-xl-2', !isClosed); 1435 1436 } else { 1437 1438 // if grid type 1439 var colData = $wrapper.data('toggle-cols'), 1440 colsClasses = $wrapper.attr('class').match(/cols-\w*-*\d/g), 1441 // get max cols count 1442 maxColsCount = colsClasses ? 1443 Math.max.apply(null, colsClasses.map(function (cls) { 1444 return cls.match(/\d/)[0]; 1445 })) : 1446 0; 1447 1448 if (isClosed) { // when open 1449 4 === maxColsCount && 1450 3 == colData && 1451 $wrapper.removeClass('cols-md-4'); 1452 1453 } else { // when close 1454 if (3 === maxColsCount) { 1455 $wrapper.addClass('cols-md-4'); 1456 1457 if (!colData) { 1458 $wrapper.data('toggle-cols', 3); 1459 } 1460 } 1461 } 1462 } 1463 } 1464 } 1465 1466 // finally, toggle fixed sidebar 1467 self.$sidebar.toggleClass('closed'); 1468 1469 } else { 1470 1471 self.$sidebar.find('.sidebar-overlay .sidebar-close').css('margin-left', - (window.innerWidth - document.body.clientWidth)); 1472 1473 // activate sidebar 1474 Donald.$body 1475 .toggleClass(self.name + '-active') 1476 .removeClass('closed'); 1477 1478 // issue 1479 if (window.innerWidth >= 1200 && Donald.$body.hasClass('with-flex-container')) { 1480 $('.owl-carousel').trigger('refresh.owl.carousel'); 1481 } 1482 } 1483 } 1484 1485 return function (name) { 1486 return new Sidebar(name); 1487 } 1488 })(); 1489 1490 /** 1491 * @function initProductSingle 1492 * 1493 * @param {jQuery} $el 1494 * @param {object} options 1495 * 1496 * @requires OwlCarousel 1497 * @requires ImagesLoaded (only quickview needs) 1498 * @requires elevateZoom 1499 * @instance multiple 1500 */ 1501 1502 Donald.initProductSingle = (function () { 1503 /** 1504 * @class ProductSingle 1505 */ 1506 function ProductSingle($el) { 1507 return this.init($el); 1508 } 1509 1510 var thumbsInit = function (self) { 1511 // members for thumbnails 1512 self.$thumbs = self.$wrapper.find('.product-thumbs'); 1513 self.$thumbsWrap = self.$thumbs.parent(); 1514 self.$thumbUp = self.$thumbsWrap.find('.thumb-up'); 1515 self.$thumbDown = self.$thumbsWrap.find('.thumb-down'); 1516 self.$thumbsDots = self.$thumbs.children();
1517 self.thumbsCount = self.$thumbsDots.length; 1518 self.$productThumb = self.$thumbsDots.eq(0); 1519 self._isPgvertical = self.$thumbsWrap.parent().hasClass('pg-vertical'); 1520 self.thumbsIsVertical = self._isPgvertical && window.innerWidth >= Donald.minDesktopWidth; 1521 1522 // register events 1523 self.$thumbDown.on('click', function (e) { 1524 self.thumbsIsVertical && thumbsDown(self); 1525 }); 1526 1527 self.$thumbUp.on('click', function (e) { 1528 self.thumbsIsVertical && thumbsUp(self); 1529 }); 1530 1531 self.$thumbsDots.on('click', function () { 1532 var $this = $(this), 1533 index = ($this.parent().filter(self.$thumbs).length ? $this : $this.parent()).index(); 1534 self.$wrapper.find('.product-single-carousel').trigger('to.owl.carousel', index); 1535 }); 1536 1537 // refresh thumbs 1538 thumbsRefresh(self); 1539 Donald.$window.on('resize', function () { 1540 thumbsRefresh(self); 1541 }); 1542 } 1543 1544 var thumbsDown = function (self) { 1545 var maxBottom = self.$thumbsWrap.offset().top + self.$thumbsWrap[0].offsetHeight, 1546 curBottom = self.$thumbs.offset().top + self.thumbsHeight; 1547 1548 if (curBottom >= maxBottom + self.$productThumb[0].offsetHeight) { 1549 self.$thumbs.css('top', parseInt(self.$thumbs.css('top')) - self.$productThumb[0].offsetHeight); 1550 self.$thumbUp.removeClass('disabled'); 1551 } else if (curBottom > maxBottom) { 1552 self.$thumbs.css('top', parseInt(self.$thumbs.css('top')) - Math.ceil(curBottom - maxBottom)); 1553 self.$thumbUp.removeClass('disabled'); 1554 self.$thumbDown.addClass('disabled'); 1555 } else { 1556 self.$thumbDown.addClass('disabled'); 1557 } 1558 } 1559 1560 var thumbsUp = function (self) { 1561 var maxTop = self.$thumbsWrap.offset().top, 1562 curTop = self.$thumbs.offset().top; 1563 1564 if (curTop <= maxTop - self.$productThumb[0].offsetHeight) { 1565 self.$thumbs.css('top', parseInt(self.$thumbs.css('top')) + self.$productThumb[0].offsetHeight); 1566 self.$thumbDown.removeClass('disabled'); 1567 } else if (curTop < maxTop) { 1568 self.$thumbs.css('top', parseInt(self.$thumbs.css('top')) - Math.ceil(curTop - maxTop)); 1569 self.$thumbDown.removeClass('disabled'); 1570 self.$thumbUp.addClass('disabled'); 1571 } else { 1572 self.$thumbUp.addClass('disabled'); 1573 } 1574 } 1575 1576 var thumbsRefresh = function (self) { 1577 if (typeof self.$thumbs == 'undefined') { 1578 return; 1579 } 1580 1581 var oldIsVertical = 'undefined' == typeof self.thumbsIsVertical ? false : self.thumbsIsVertical; // is vertical? 1582 self.thumbsIsVertical = self._isPgvertical && window.innerWidth >= Donald.minDesktopWidth; 1583 1584 if (self.thumbsIsVertical) { // enable vertical product gallery thumbs. 1585 // disable thumbs carousel 1586 self.$thumbs.hasClass('owl-carousel') && 1587 self.$thumbs 1588 .trigger('destroy.owl.carousel') 1589 .removeClass('owl-carousel'); 1590 1591 // enable thumbs vertical nav 1592 self.thumbsHeight = self.$productThumb[0].offsetHeight * self.thumbsCount + parseInt(self.$productThumb.css('margin-bottom')) * (self.thumbsCount - 1); 1593 self.$thumbUp.addClass('disabled'); 1594 self.$thumbDown.toggleClass('disabled', self.thumbsHeight <= self.$thumbsWrap[0].offsetHeight); 1595 self.isQuickview && recalcDetailsHeight(); 1596 } else { 1597 // if not vertical, remove top property 1598 oldIsVertical && self.$thumbs.css('top', ''); 1599 1600 // enable thumbs carousel 1601 self.$thumbs.hasClass('owl-carousel') || self.$thumbs.addClass('owl-carousel').owlCarousel( 1602 $.extend( 1603 true, 1604 self.isQuickview ? {
1605 onInitialized: recalcDetailsHeight, 1606 onResized: recalcDetailsHeight 1607 } : {}, 1608 Donald.defaults.sliderThumbs 1609 )); 1610 } 1611 } 1612 1613 var initVariation = function (self) { 1614 self.$selects = self.$wrapper.find('.product-variations select'); 1615 self.$items = self.$wrapper.find('.product-variations'); 1616 self.$priceWrap = self.$wrapper.find('.product-variation-price'); 1617 self.$clean = self.$wrapper.find('.product-variation-clean'), 1618 self.$btnCart = self.$wrapper.find('.btn-cart'); 1619 1620 // check 1621 self.variationCheck(); 1622 self.$selects.on('change', function (e) { 1623 self.variationCheck(); 1624 }); 1625 self.$items.children('a').on('click', function (e) { 1626 1627 if ($(this).hasClass('color')) 1628 return; 1629 1630 $(this).toggleClass('active').siblings().removeClass('active'); 1631 e.preventDefault(); 1632 self.variationCheck(true); 1633 }); 1634 1635 // clean 1636 self.$clean.on('click', function (e) { 1637 e.preventDefault(); 1638 self.variationClean(true); 1639 }); 1640 } 1641 1642 var initCartAction = function (self) { 1643 1644 // Product Single's Add To Cart Button 1645 self.$wrapper.on('click', '.btn-cart', function (e) { 1646 e.preventDefault(); 1647 1648 var $product = self.$wrapper; 1649 1650 var pageType = $product.find('#ProductType').val(); 1651 1652 var proCode = $product.find('#ProductCode').val(); 1653 var proName = $product.find('.product-name').text(); 1654 1655 var labelPrice = $product.find('#label-price').attr('data-value'); 1656 var salePrice = $product.find('#sale-price').attr('data-value'); 1657 var salePriceToShow = $product.find('#sale-price').attr('data-priceshow'); 1658 1659 var imageLink = $product.find('.product-image img').eq(0).attr('src'); 1660 var quantity = $product.find('.quantity').val(); 1661 1662 addToShappingCart(pageType, proCode, proName, labelPrice, salePrice, salePriceToShow, quantity, imageLink); 1663 1664 /******************************************* tyam popup basket ********************************************/ 1665 // minipopup if only quickview or home pages 1666 //if ( $product.closest('.product-popup').length || document.body.classList.contains('home') ) { 1667 // Donald.Minipopup.open({ 1668 // message: 'Successfully added.<a href="cart.html" class="btn btn-link btn-sm btn-slide-right btn-infinite">View Cart<i class="d-icon-arrow-right"></i></a>', 1669 // productClass: ' product-cart', 1670 // name: $product.find('.product-name').text(), 1671 // nameLink: $product.find('.product-name > a').attr('href'), 1672 // imageSrc: $product.find('.product-image img').eq(0).attr('src'), 1673 // imageLink: $product.find('.product-name > a').attr('href'), 1674 // price: $product.find('.product-variation-price').children('span').html(), 1675 // count: $product.find('.quantity').val(), 1676 // }); 1677 //} 1678 /******************************************* tyam popup basket end ********************************************/ 1679 }); 1680 } 1681 1682 // For only Quickview 1683 var recalcDetailsHeight = function () { 1684 var self = this; 1685 self.$wrapper.find('.product-details').css( 1686 'height', 1687 window.innerWidth > 767 ? self.$wrapper.find('.product-gallery')[0].clientHeight : '' 1688 ); 1689 } 1690 1691 // Public Properties 1692 1693 ProductSingle.prototype.init = function ($el) { 1694 1695 var self = this, 1696 $slider = $el.find('.product-single-carousel'); 1697 1698 // members 1699 self.$wrapper = $el; 1700 self.isQuickview = !!$el.closest('.mfp-content').length; 1701 self._isPgvertical = false; 1702 1703 // bind 1704 if (self.isQuickview) { 1705 recalcDetailsHeight = recalcDetailsHeight.bind(this); 1706 Donald.ratingTooltip(); 1707 } 1708 1709 // init thumbs 1710 $slider.on('initialized.owl.carousel', function (e) { 1711 1712 // if not quickview, make full image toggle 1713 self.isQuickview || $slider.append('<a href="#" class="product-image-full"><i class="d-icon-zoom"></i></a>'); 1714 1715 // init thumbnails 1716 thumbsInit(self); 1717 1718 }).on('translate.owl.carousel', function (e) { 1719 var currentIndex = (e.item.index - $(e.currentTarget).find('.cloned').length / 2 + e.item.count) % e.item.count; 1720 self.thumbsSetActive(currentIndex); 1721 }); 1722 1723 // if this is created after document ready, init plugins
1724 if ('complete' === Donald.status) { 1725 Donald.slider($slider); 1726 Donald.quantityInput($el.find('.quantity')); 1727 } 1728 1729 initVariation(this); 1730 initCartAction(this); 1731 } 1732 1733 ProductSingle.prototype.thumbsSetActive = function (index) { 1734 var self = this, 1735 $curThumb = self.$thumbsDots.eq(index); 1736 1737 self.$thumbsDots.filter('.active').removeClass('active'); 1738 $curThumb.addClass('active'); 1739 1740 // show current thumb 1741 if (self.thumbsIsVertical) { // if vertical 1742 var offset = parseInt(self.$thumbs.css('top')) + index * self.thumbsHeight; 1743 1744 if (offset < 0) { 1745 // if above 1746 self.$thumbs.css('top', parseInt(self.$thumbs.css('top')) - offset); 1747 } else { 1748 offset = self.$thumbs.offset().top + self.$thumbs[0].offsetHeight - $curThumb.offset().top - $curThumb[0].offsetHeight; 1749 1750 if (offset < 0) { 1751 // if below 1752 self.$thumbs.css('top', parseInt(self.$thumbs.css('top')) + offset); 1753 } 1754 } 1755 } else { // if thumb carousel 1756 self.$thumbs.trigger('to.owl.carousel', index, 100); 1757 } 1758 } 1759 1760 ProductSingle.prototype.variationCheck = function () { 1761 var self = this, 1762 isAllSelected = true; 1763 1764 // check all select variations are selected 1765 self.$selects.each(function () { 1766 return this.value || (isAllSelected = false); 1767 }); 1768 1769 // check all item variations are selected 1770 self.$items.each(function () { 1771 var $this = $(this); 1772 if ($this.children('a:not(.size-guide)').length) { 1773 return $this.children('.active').length || (isAllSelected = false); 1774 } 1775 }); 1776 1777 isAllSelected ? 1778 self.variationMatch() : 1779 self.variationClean(); 1780 } 1781 1782 ProductSingle.prototype.variationMatch = function () { 1783 var self = this; 1784 self.$priceWrap.find('span').text('$' + (Math.round(Math.random() * 50) + 200) + '.00'); 1785 self.$priceWrap.slideDown(); 1786 self.$clean.slideDown(); 1787 //self.$btnCart.removeAttr('disabled'); 1788 } 1789 1790 ProductSingle.prototype.variationClean = function (reset) { 1791 reset && this.$selects.val(''); 1792 reset && this.$items.children('.active').removeClass('active'); 1793 this.$priceWrap.slideUp();
1794 this.$clean.css('display', 'none'); 1795 //this.$btnCart.attr('disabled', 'disabled'); 1796 } 1797 1798 return function ($el, options) { 1799 if ($el) { 1800 return new ProductSingle($el.eq(0), options); 1801 } 1802 return null; 1803 } 1804 })(); 1805 1806 /** 1807 * @function initProductSinglePage 1808 * 1809 * @requires Slider 1810 * @requires ProductSingle 1811 * @requires PhotoSwipe 1812 * @instance single 1813 */ 1814 Donald.initProductSinglePage = (function () { 1815 var $product; 1816 function alertCartAdded() { 1817 $(Donald.parseTemplate(Donald.defaults.templateCartAddedAlert, { 1818 name: $product.find('h1.product-name').text() 1819 })) 1820 .insertBefore($product).fadeIn(); 1821 $('.sticky-sidebar').trigger('recalc.pin'); 1822 } 1823 function openFullImage(e) { 1824 1825 e.preventDefault(); 1826 1827 var $this = $(e.currentTarget), 1828 $images, 1829 images; 1830 1831 if ($product.find('.product-single-carousel').length) { 1832 // single carousel 1833 $images = $product.find('.product-single-carousel .owl-item:not(.cloned) figure'); 1834 //$images = $product.find('.product-single-carousel .owl-item:not(.cloned) video'); 1835 1836 } else if ($product.find('.product-gallery-carousel').length) { 1837 // gallery carousel 1838 $images = $product.find('.product-gallery-carousel .owl-item:not(.cloned) img'); 1839 1840 } else { 1841 // simple gallery 1842 $images = $product.find('.product-gallery img'); 1843 console.log($images); 1844 } 1845 1846 // if images exist 1847 if ($images.length) { 1848 var images = $images.map(function () { 1849 var $this = $(this); 1850 var imgW = $('#ImageWidth').val(); 1851 var imgH = $('#ImageHeight').val(); 1852 if ($this.children(":first").attr('data-type') == "video") { 1853 return { 1854 html: "<video class='pswp__video' controls width='" + imgW + "' height='" + imgH + "' controlsList='nodownload'> <source src=" + $this.children(":first").attr('data-zoom-image') + " type='video/mp4' /></video>" 1855 }; 1856 } else { 1857 return { 1858 src: $this.children(":first").attr('data-zoom-image'), 1859 w: imgW, 1860 h: imgH, 1861 title: $this.children(":first").attr('alt') 1862 }; 1863 } 1864 1865 }).get(), 1866 1867 carousel = $product.find('.product-single-carousel, .product-gallery-carousel').data('owl.carousel'), 1868 currentIndex = carousel ? 1869 // Carousel Type 1870 ((carousel.current() - carousel.clones().length / 2 + images.length) % images.length) : 1871 1872 // Gallery Type 1873 ($product.find('.product-gallery > *').index()); 1874 1875 if (typeof PhotoSwipe !== 'undefined') { 1876 var pswpElement = $('.pswp')[0]; 1877 1878 var photoswipe = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, images, { 1879 index: currentIndex, 1880 closeOnScroll: false, 1881 1882 }); 1883 1884 photoswipe.init(); 1885 1886 Donald.photoswipe = photoswipe; 1887 } 1888 } 1889 } 1890 function ratingForm() { 1891 $('body').on('click', '.rating-form .rating-stars > a', function (e) { 1892 var $star = $(this); 1893 $star.addClass('active').siblings().removeClass('active'); 1894 $star.parent().addClass('selected'); 1895 $star.closest('.rating-form').find('select').val($star.text()); 1896 e.preventDefault(); 1897 }); 1898 } 1899 1900 // Public Properties 1901 return function () { 1902 $product = $('.product-single'); 1903 1904 1905 if ($product.length) { 1906 // if home page, init single products 1907 if (document.body.classList.contains('home')) { 1908 $product.each(function () { 1909 Donald.initProductSingle($(this)); 1910 }); 1911 1912 return null; 1913 1914 // else, init single product page 1915 } else { 1916 if (Donald.initProductSingle($product) === null) { 1917 return null; 1918 } 1919 } 1920 } else { 1921 // if no single product exists, return 1922 return null; 1923 } 1924 1925 // image zoom for grid type 1926 Donald.zoomImage('.product-gallery.row'); 1927 1928 // image full 1929 $product.on('click', '.product-image-full', openFullImage); 1930 1931 // cart added alert 1932 //$product.on('click', '.btn-cart:not(.disabled)', alertCartAdded); 1933 1934 // init rating from.(new) 1935 ratingForm(); 1936 } 1937 })(); 1938 1939 /** 1940 * @function slider 1941 * 1942 * @requires OwlCarousel 1943 */ 1944 Donald.slider = (function () { 1945 /** 1946 * @class Slider 1947 */ 1948 function Slider($el, options) { 1949 return this.init($el, options); 1950 } 1951 1952 var onInitialize = function (e) { 1953 var i, j, breaks = ['', '-xs', '-sm', '-md', '-lg', '-xl']; 1954 this.classList.remove('row'); 1955 for (i = 0; i < 6; ++i) { 1956 for (j = 1; j <= 12; ++j) { 1957 this.classList.remove('cols' + breaks[i] + '-' + j); 1958 } 1959 } 1960 this.classList.remove('gutter-no'); 1961 this.classList.remove('gutter-sm'); 1962 this.classList.remove('gutter-lg');
1963 if (this.classList.contains("animation-slider")) { 1964 var els = this.children, 1965 len = els.length; 1966 for (var i = 0; i < len; ++i) { 1967 els[i].setAttribute('data-index', i + 1); 1968 } 1969 } 1970 } 1971 var onInitialized = function (e) { 1972 var els = this.firstElementChild.firstElementChild.children, 1973 i, 1974 len = els.length; 1975 for (i = 0; i < len; ++i) { 1976 if (!els[i].classList.contains('active')) { 1977 var animates = Donald.byClass('appear-animate', els[i]), 1978 j; 1979 for (j = animates.length - 1; j >= 0; --j) { 1980 animates[j].classList.remove('appear-animate'); 1981 } 1982 } 1983 } 1984 1985 // Video 1986 var $el = $(e.currentTarget); 1987 $el.find('video').on('ended', function () { 1988 var $this = $(this); 1989 if ($this.closest('.owl-item').hasClass('active')) { 1990 if (true === $el.data('owl.carousel').options.autoplay) { 1991 if (false === $el.data('owl.carousel').options.loop && ($el.data().children - 1) === $el.find('.owl-item.active').index()) { 1992 this.loop = true; 1993 this.play(); 1994 } 1995 $el.trigger('next.owl.carousel'); 1996 $el.trigger('play.owl.autoplay'); 1997 } else { 1998 this.loop = true; 1999 this.play(); 2000 } 2001 } 2002 }); 2003 } 2004 var onTranslated = function (e) { 2005 $(window).trigger('appear.check'); 2006 2007 // Video Play 2008 var $el = $(e.currentTarget), 2009 $activeVideos = $el.find('.owl-item.active video'); 2010 2011 $el.find('.owl-item:not(.active) video').each(function () { 2012 if (!this.paused) { 2013 $el.trigger('play.owl.autoplay'); 2014 } 2015 this.pause(); 2016 this.currentTime = 0; 2017 }); 2018 2019 if ($activeVideos.length) { 2020 if (true === $el.data('owl.carousel').options.autoplay) { 2021 $el.trigger('stop.owl.autoplay'); 2022 } 2023 $activeVideos.each(function () { 2024 this.paused && this.play(); 2025 }); 2026 } 2027 } 2028 var onSliderInitialized = function (e) { 2029 var self = this, 2030 $el = $(e.currentTarget); 2031 2032 // carousel content animation 2033 2034 $el.find('.owl-item.active .slide-animate').each(function () { 2035 var $animation_item = $(this), 2036 settings = $.extend(true, {}, 2037 Donald.defaults.animation, 2038 Donald.parseOptions($animation_item.data('animation-options')) 2039 ), 2040 duration = settings.duration, 2041 delay = settings.delay, 2042 aniName = settings.name; 2043 2044 $animation_item.css('animation-duration', duration); 2045 2046 var temp = Donald.requestTimeout(function () { 2047 $animation_item.addClass(aniName); 2048 $animation_item.addClass('show-content'); 2049 }, (delay ? Number((delay).slice(0, -1)) * 1000 : 0)); 2050 2051 self.timers.push(temp); 2052 }); 2053 } 2054 2055 var onSliderResized = function (e) { 2056 $(e.currentTarget).find('.owl-item.active .slide-animate').each(function () { 2057 var $animation_item = $(this); 2058 $animation_item.addClass('show-content'); 2059 $animation_item.attr('style', ''); 2060 }); 2061 } 2062 2063 var onSliderTranslate = function (e) { 2064 var self = this, 2065 $el = $(e.currentTarget); 2066 self.translateFlag = 1; 2067 self.prev = self.next; 2068 $el.find('.owl-item .slide-animate').each(function () { 2069 var $animation_item = $(this), 2070 settings = $.extend(true, {}, Donald.defaults.animation, Donald.parseOptions($animation_item.data('animation-options'))); 2071 $animation_item.removeClass(settings.name); 2072 }); 2073 } 2074 2075 var onSliderTranslated = function (e) { 2076 var self = this, 2077 $el = $(e.currentTarget); 2078 if (1 == self.translateFlag) { 2079 self.next = $el.find('.owl-item').eq(e.item.index).children().attr('data-index'); 2080 $el.find('.show-content').removeClass('show-content'); 2081 if (self.prev != self.next) { 2082 $el.find('.show-content').removeClass('show-content'); 2083 /* clear all animations that are running. */
2084 if ($el.hasClass("animation-slider")) { 2085 for (var i = 0; i < self.timers.length; i++) { 2086 Donald.deleteTimeout(self.timers[i]); 2087 } 2088 self.timers = []; 2089 } 2090 $el.find('.owl-item.active .slide-animate').each(function () { 2091 var $animation_item = $(this), 2092 settings = $.extend(true, {}, Donald.defaults.animation, Donald.parseOptions($animation_item.data('animation-options'))), 2093 duration = settings.duration, 2094 delay = settings.delay, 2095 aniName = settings.name; 2096 2097 $animation_item.css('animation-duration', duration); 2098 $animation_item.css('animation-delay', delay); 2099 $animation_item.css('transition-property', 'visibility, opacity'); 2100 $animation_item.css('transition-delay', delay); 2101 $animation_item.css('transition-duration', duration); 2102 $animation_item.addClass(aniName); 2103 2104 duration = duration ? duration : '0.75s'; 2105 $animation_item.addClass('show-content'); 2106 var temp = Donald.requestTimeout(function () { 2107 $animation_item.css('transition-property', ''); 2108 $animation_item.css('transition-delay', ''); 2109 $animation_item.css('transition-duration', ''); 2110 self.timers.splice(self.timers.indexOf(temp), 1) 2111 }, (delay ? Number((delay).slice(0, -1)) * 1000 + Number((duration).slice(0, -1)) * 500 : Number((duration).slice(0, -1)) * 500)); 2112 self.timers.push(temp); 2113 }); 2114 } else { 2115 $el.find('.owl-item').eq(e.item.index).find('.slide-animate').addClass('show-content'); 2116 } 2117 self.translateFlag = 0; 2118 } 2119 } 2120 2121 // Public Properties 2122 2123 Slider.zoomImage = function () { 2124 Donald.zoomImage(this.$element); 2125 } 2126 2127 Slider.zoomImageRefresh = function () { 2128 this.$element.find('img').each(function () { 2129 var $this = $(this); 2130 2131 if ($.fn.elevateZoom) { 2132 var elevateZoom = $this.data('elevateZoom'); 2133 if (typeof elevateZoom !== 'undefined') { 2134 elevateZoom.refresh(); 2135 } else { 2136 Donald.defaults.zoomImage.zoomContainer = $this.parent(); 2137 $this.elevateZoom(Donald.defaults.zoomImage); 2138 } 2139 } 2140 }); 2141 } 2142 2143 if ($(window).width() > 768) { 2144 Donald.defaults.sliderPresets['product-single-carousel'].onInitialized = Donald.defaults.sliderPresets['product-gallery-carousel'].onInitialized = Slider.zoomImage; 2145 Donald.defaults.sliderPresets['product-single-carousel'].onRefreshed = Donald.defaults.sliderPresets['product-gallery-carousel'].onRefreshed = Slider.zoomImageRefresh; 2146 } 2147 2148 Slider.prototype.init = function ($el, options) { 2149 this.timers = []; 2150 this.translateFlag = 0; 2151 this.prev = 1; 2152 this.next = 1; 2153 2154 Donald.lazyload($el, true); 2155 2156 var classes = $el.attr('class').split(' '), 2157 settings = $.extend(true, {}, Donald.defaults.slider); 2158 2159 // extend preset options 2160 classes.forEach(function (className) { 2161 var preset = Donald.defaults.sliderPresets[className]; 2162 preset && $.extend(true, settings, preset); 2163 }); 2164 2165 var $videos = $el.find('video'); 2166 $videos.each(function () { 2167 this.loop = false; 2168 }); 2169 2170 // extend user options 2171 $.extend(true, settings, Donald.parseOptions($el.attr('data-owl-options')), options); 2172 2173 onSliderInitialized = onSliderInitialized.bind(this); 2174 onSliderTranslate = onSliderTranslate.bind(this); 2175 onSliderTranslated = onSliderTranslated.bind(this); 2176 2177 // init 2178 $el.on('initialize.owl.carousel', onInitialize) 2179 .on('initialized.owl.carousel', onInitialized) 2180 .on('translated.owl.carousel', onTranslated); 2181 2182 // if animation slider
2183 $el.hasClass('animation-slider') && 2184 $el.on('initialized.owl.carousel', onSliderInitialized) 2185 .on('resized.owl.carousel', onSliderResized) 2186 .on('translate.owl.carousel', onSliderTranslate) 2187 .on('translated.owl.carousel', onSliderTranslated); 2188 2189 $el.owlCarousel(settings); 2190 } 2191 2192 return function (selector, options) { 2193 Donald.$(selector).each(function () { 2194 var $this = $(this); 2195 2196 Donald.call(function () { 2197 new Slider($this, options); 2198 }); 2199 }); 2200 } 2201 })(); 2202 2203 /** 2204 * @function quantityInput 2205 */ 2206 Donald.quantityInput = (function () { 2207 /** 2208 * @class QuantityInput 2209 */ 2210 function QuantityInput($el) { 2211 return this.init($el); 2212 } 2213 QuantityInput.min = 1; 2214 QuantityInput.max = 1000000; 2215 QuantityInput.value = 1; 2216 QuantityInput.prototype.init = function ($el) { 2217 var self = this; 2218 2219 self.$minus = false; 2220 self.$plus = false; 2221 self.$value = false; 2222 self.value = false; 2223 2224 // Bind Events 2225 self.startIncrease = self.startIncrease.bind(self); 2226 self.startDecrease = self.startDecrease.bind(self); 2227 self.stop = self.stop.bind(self); 2228 2229 // Variables 2230 self.min = parseInt($el.attr('min')), 2231 self.max = parseInt($el.attr('max')); 2232 2233 self.min || ($el.attr('min', self.min = QuantityInput.min)) 2234 self.max || ($el.attr('max', self.max = QuantityInput.max)) 2235 2236 // Add DOM elements and event listeners 2237 self.$value = $el.val(self.value = QuantityInput.value); 2238 2239 self.$minus = $el.next() 2240 .on('mousedown', function (e) { 2241 e.preventDefault(); 2242 self.startDecrease(); 2243 }) 2244 .on('touchstart', function (e) { 2245 if (e.cancelable) { 2246 e.preventDefault(); 2247 } 2248 self.startDecrease(); 2249 }) 2250 .on('mouseup', self.stop); 2251 2252 self.$plus = $el.prev() 2253 .on('mousedown', function (e) { 2254 e.preventDefault(); 2255 self.startIncrease(); 2256 }) 2257 .on('touchstart', function (e) { 2258 if (e.cancelable) { 2259 e.preventDefault(); 2260 } 2261 self.startIncrease(); 2262 }) 2263 .on('mouseup', self.stop); 2264 2265 Donald.$body.on('mouseup', self.stop) 2266 .on('touchend', self.stop) 2267 .on('touchcancel', self.stop); 2268 } 2269 QuantityInput.prototype.startIncrease = function (e) { 2270 e && e.preventDefault(); 2271 var self = this; 2272 self.value = self.$value.val(); 2273 self.value < self.max && self.$value.val(++self.value); 2274 self.increaseTimer = Donald.requestTimeout(function () { 2275 self.speed = 1; 2276 self.increaseTimer = Donald.requestInterval(function () { 2277 self.$value.val(self.value = Math.min(self.value + Math.floor(self.speed *= 1.05), self.max)); 2278 }, 50); 2279 }, 400); 2280 } 2281 QuantityInput.prototype.stop = function (e) { 2282 Donald.deleteTimeout(this.increaseTimer); 2283 Donald.deleteTimeout(this.decreaseTimer); 2284 } 2285 QuantityInput.prototype.startDecrease = function () { 2286 var self = this; 2287 self.value = self.$value.val(); 2288 self.value > self.min && self.$value.val(--self.value); 2289 self.decreaseTimer = Donald.requestTimeout(function () { 2290 self.speed = 1; 2291 self.decreaseTimer = Donald.requestInterval(function () { 2292 self.$value.val(self.value = Math.max(self.value - Math.floor(self.speed *= 1.05), self.min)); 2293 }, 50); 2294 }, 400); 2295 } 2296 return function (selector) { 2297 Donald.$(selector).each(function () { 2298 var $this = $(this); 2299 // if not initialized 2300 $this.data('quantityInput') || 2301 $this.data('quantityInput', new QuantityInput($this)); 2302 }); 2303 } 2304 })(); 2305 2306 /** 2307 * @class Menu 2308 */ 2309 Donald.Menu = { 2310 init: function () { 2311 this.initMenu(); 2312 this.initMobileMenu(); 2313 this.initFilterMenu(); 2314 this.initCategoryMenu(); 2315 this.initCollapsibleWidget(); 2316 }, 2317 initMenu: function () { 2318 // setup menu 2319 $('.menu li').each(function () { 2320 if (this.lastElementChild && ( 2321 this.lastElementChild.tagName === 'UL' || 2322 this.lastElementChild.classList.contains('megamenu')) 2323 ) { 2324 this.classList.add('submenu'); 2325 } 2326 }); 2327 2328 // calc megamenu position 2329 Donald.$window.on('resize', function () { 2330 $('.main-nav .megamenu').each(function () { 2331 var $this = $(this), 2332 left = $this.offset().left, 2333 outerWidth = $this.outerWidth(), 2334 offset = (left + outerWidth) - (window.innerWidth - 20); 2335 if (offset > 0 && left > 20) { 2336 $this.css('margin-left', -offset); 2337 } 2338 }); 2339 }) 2340 }, 2341 initMobileMenu: function () { 2342 function showMobileMenu() { 2343 Donald.$body.addClass('mmenu-active'); 2344 $('body').css('position', 'fixed') 2345 }; 2346 function hideMobileMenu() { 2347 Donald.$body.removeClass('mmenu-active'); 2348 $('body').css('position', '') 2349 }; 2350 2351 $('.mobile-menu li, .toggle-menu li').each(function () { 2352 if (this.lastElementChild && ( 2353 this.lastElementChild.tagName === 'UL' || 2354 this.lastElementChild.classList.contains('megamenu')) 2355 ) { 2356 var span = document.createElement('span'); 2357 span.className = "toggle-btn"; 2358 this.firstElementChild.appendChild(span); 2359 } 2360 }); 2361 $('.mobile-menu-toggle').on('click', showMobileMenu); 2362 $('.mobile-menu-overlay').on('click', hideMobileMenu); 2363 $('.mobile-menu-close').on('click', hideMobileMenu); 2364 //Donald.$window.on('resize', hideMobileMenu); 2365 }, 2366 initFilterMenu: function () { 2367 $('.search-ul li').each(function () { 2368 if (this.lastElementChild && this.lastElementChild.tagName === 'UL') { 2369 var i = document.createElement('i'); 2370 i.className = "fas fa-chevron-down"; 2371 this.classList.add('with-ul'); 2372 this.firstElementChild.appendChild(i); 2373 } 2374 }); 2375 $('.toggle-btn').on('click', function (e) { 2376 if ($('#MobileMenuOnlyEndLevelClick').val() === "0") { 2377 $(this).parent().next().slideToggle(300).parent().toggleClass("show"); 2378 setTimeout(function () { 2379 $('.sticky-sidebar').trigger('recalc.pin'); 2380 }, 320); 2381 e.preventDefault(); 2382 } 2383 }); 2384 $('.with-ul > a i').on('click', function (e) { 2385 $(this).parent().next().slideToggle(300).parent().toggleClass("show"); 2386 setTimeout(function () { 2387 $('.sticky-sidebar').trigger('recalc.pin'); 2388 }, 320); 2389 e.preventDefault(); 2390 }); 2391 }, 2392 initCategoryMenu: function () { 2393 // cat dropdown 2394 var $menu = $('.category-dropdown'); 2395 if ($menu.length) { 2396 var $box = $menu.find('.dropdown-box'); 2397 if ($box.length) { 2398 var top = $('.main').offset().top + $box[0].offsetHeight; 2399 if (window.pageYOffset > top || window.innerWidth < Donald.minDesktopWidth) { 2400 $menu.removeClass('show'); 2401 } 2402 window.addEventListener('scroll', function () { 2403 if (window.pageYOffset <= top && window.innerWidth >= Donald.minDesktopWidth) { 2404 $menu.removeClass('show'); 2405 } 2406 }, { passive: true });
2407 $('.category-toggle').on("click", function (e) { 2408 e.preventDefault(); 2409 }) 2410 $menu.on("mouseover", function (e) { 2411 if (window.pageYOffset > top && window.innerWidth >= Donald.minDesktopWidth) { 2412 $menu.addClass('show'); 2413 } 2414 }) 2415 $menu.on("mouseleave", function (e) { 2416 if (window.pageYOffset > top && window.innerWidth >= Donald.minDesktopWidth) { 2417 $menu.removeClass('show'); 2418 } 2419 }) 2420 } 2421 if ($menu.hasClass('with-sidebar')) { 2422 var sidebar = Donald.byClass('sidebar'); 2423 if (sidebar.length) { 2424 $menu.find('.dropdown-box').css('width', sidebar[0].offsetWidth - 20); 2425 2426 // set category menu's width same as sidebar. 2427 Donald.$window.on('resize', function () { 2428 $menu.find('.dropdown-box').css('width', (sidebar[0].offsetWidth - 20)); 2429 }); 2430 } 2431 } 2432 } 2433 }, 2434 initCollapsibleWidget: function () { 2435 // generate toggle icon 2436 $('.widget-collapsible .widget-title').each(function () { 2437 var span = document.createElement('span'); 2438 span.className = 'toggle-btn'; 2439 this.appendChild(span); 2440 }); 2441 // slideToggle 2442 $('.widget-collapsible .widget-title').on('click', function (e) { 2443 var $this = $(this); 2444 if (!$this.hasClass('sliding')) { 2445 var $body = $this.siblings('.widget-body'); 2446 2447 $this.hasClass("collapsed") || $body.css('display', 'block'); 2448 2449 $this.addClass("sliding"); 2450 $body.slideToggle(300, function () { 2451 $this.removeClass("sliding"); 2452 }); 2453 2454 $this.toggleClass("collapsed"); 2455 setTimeout(function () { 2456 $('.sticky-sidebar').trigger('recalc.pin'); 2457 }, 320); 2458 } 2459 }); 2460 } 2461 }; 2462 2463 /** 2464 * @class MiniPopup 2465 */ 2466 Donald.Minipopup = (function () { 2467 var $area, 2468 offset = 0, 2469 boxes = [], 2470 isPaused = false, 2471 timers = [], 2472 timerId = false, 2473 timerInterval = 200, 2474 timerClock = function () { 2475 if (isPaused) { 2476 return; 2477 } 2478 for (var i = 0; i < timers.length; ++i) { 2479 (timers[i] -= timerInterval) <= 0 && this.close(i--); 2480 } 2481 } 2482 2483 return { 2484 init: function () { 2485 // init area 2486 var area = document.createElement('div'); 2487 area.className = "minipopup-area"; 2488 Donald.byClass('page-wrapper')[0].appendChild(area); 2489 2490 $area = $(area); 2491 $area.on('click', '.btn-close', function (e) { 2492 self.close($(this).closest('.minipopup-box').index()); 2493 }); 2494 2495 // bind methods 2496 this.close = this.close.bind(this); 2497 timerClock = timerClock.bind(this); 2498 }, 2499 2500 open: function (options, callback) { 2501 var self = this, 2502 settings = $.extend(true, {}, Donald.defaults.minipopup, options), 2503 $box; 2504 2505 settings.detailTemplate = Donald.parseTemplate( 2506 (null != settings.count ? settings.priceQuantityTemplate : settings.priceTemplate), 2507 settings 2508 ) 2509 if (null != settings.rating) { 2510 settings.detailTemplate += Donald.parseTemplate(sett
2510ings.ratingTemplate, settings); 2511 } 2512 $box = $(Donald.parseTemplate(settings.template, settings)); 2513 2514 self.space = settings.space; 2515 2516 // open 2517 $box 2518 .appendTo($area) 2519 .css('top', - offset) 2520 .find("img")[0] 2521 .onload = function () { 2522 offset += $box[0].offsetHeight + self.space; 2523 2524 $box.addClass('show'); 2525 if ($box.offset().top - window.pageYOffset < 0) { 2526 self.close(); 2527 $box.css('top', - offset + $box[0].offsetHeight + self.space); 2528 } 2529 $box.on('mouseenter', function () { self.pause() }) 2530 .on('mouseleave', function () { self.resume() }) 2531 .on('touchstart', function (e) { self.pause(); e.stopPropagation(); }) 2532 .on('mousedown', function () { 2533 $(this).addClass('focus'); 2534 }) 2535 .on('mouseup', function () { 2536 self.close($(this).index()); 2537 }); 2538 Donald.$body.on('touchstart', function () { 2539 self.resume(); 2540 }); 2541 2542 boxes.push($box); 2543 timers.push(settings.delay); 2544 2545 (timers.length > 1) || ( 2546 timerId = setInterval(timerClock, timerInterval) 2547 ) 2548 2549 callback && callback($box); 2550 }; 2551 }, 2552 2553 close: function (indexToClose) { 2554 var self = this, 2555 index = ('undefined' === typeof indexToClose) ? 0 : indexToClose, 2556 $box = boxes.splice(index, 1)[0]; 2557 2558 // remove timer 2559 timers.splice(index, 1)[0]; 2560 2561 // remove box 2562 offset -= $box[0].offsetHeight + self.space; 2563 $box.removeClass('show'); 2564 setTimeout(function () { 2565 $box.remove(); 2566 }, 300); 2567 2568 // slide down other boxes 2569 boxes.forEach(function ($box, i) { 2570 if (i >= index && $box.hasClass('show')) { 2571 $box.stop(true, true).animate({ 2572 top: parseInt($box.css('top')) + $box[0].offsetHeight + 20 2573 }, 600, 'easeOutQuint'); 2574 } 2575 }); 2576 2577 // clear timer 2578 boxes.length || clearTimeout(timerId); 2579 }, 2580 2581 pause: function () { 2582 isPaused = true; 2583 }, 2584 2585 resume: function () { 2586 isPaused = false; 2587 } 2588 } 2589 })(); 2590 2591 /** 2592 * @function floatSVG 2593 * @param {string|jQuery} selector 2594 * @param {object} options 2595 */ 2596 Donald.floatSVG = (function () { 2597 function FloatSVG(svg, options) { 2598 this.$el = $(svg); 2599 this.set(options); 2600 this.start(); 2601 } 2602 2603 FloatSVG.prototype.set = function (options) { 2604 this.options = $.extend({ 2605 delta: 15, 2606 speed: 10, 2607 size: 1, 2608 }, typeof options == 'string' ? Donald.parseOptions(options) : options); 2609 } 2610 2611 FloatSVG.prototype.getDeltaY = function (dx) { 2612 return Math.sin(2 * Math.PI * dx / this.width * this.options.size) * this.options.delta; 2613 } 2614 2615 FloatSVG.prototype.start = function () { 2616 this.update = this.update.bind(this); 2617 this.timeStart = Date.now() - parseInt(Math.random() * 100); 2618 this.$el.find('path').each(function () { 2619 $(this).data('original', this.getAttribute('d').replace(/([\d])\s*\-/g, '$1,-')); 2620 }); 2621 2622 window.addEventListener('resize', this.update, { passive: true });
2623 window.addEventListener('scroll', this.update, { passive: true }); 2624 Donald.$window.on('check_float_svg', this.update); 2625 this.update(); 2626 } 2627 2628 FloatSVG.prototype.update = function () { 2629 var self = this; 2630 2631 if (this.$el.length && Donald.isOnScreen(this.$el[0])) { // && $.contains(this.$el, document.body)) { 2632 Donald.requestTimeout(function () { 2633 self.draw(); 2634 }, 16); 2635 } 2636 } 2637 2638 FloatSVG.prototype.draw = function () { 2639 var self = this, 2640 _dx = (Date.now() - this.timeStart) * this.options.speed / 200; 2641 this.width = this.$el.width(); 2642 if (!this.width) { 2643 return; 2644 } 2645 this.$el.find('path').each(function () { 2646 var dx = _dx, dy = 0; 2647 this.setAttribute('d', $(this).data('original') 2648 .replace(/M([\d|\.]*),([\d|\.]*)/, function (match, p1, p2) { 2649 if (p1 && p2) { 2650 return 'M' + p1 + ',' + (parseFloat(p2) + (dy = self.getDeltaY(dx += parseFloat(p1)))).toFixed(3); 2651 } 2652 return match; 2653 }) 2654 .replace(/([c|C])[^A-Za-z]*/g, function (match, p1) { 2655 if (p1) { 2656 var v = match.slice(1).split(',').map(parseFloat); 2657 if (v.length == 6) { 2658 if ('C' == p1) { 2659 v[1] += self.getDeltaY(_dx + v[0]); 2660 v[3] += self.getDeltaY(_dx + v[2]); 2661 v[5] += self.getDeltaY(dx = _dx + v[4]); 2662 } else { 2663 v[1] += self.getDeltaY(dx + v[0]) - dy; 2664 v[3] += self.getDeltaY(dx + v[2]) - dy; 2665 v[5] += self.getDeltaY(dx += v[4]) - dy; 2666 } 2667 dy = self.getDeltaY(dx); 2668 2669 return p1 + v.map(function (v) { 2670 return v.toFixed(3); 2671 }).join(','); 2672 } 2673 } 2674 return match; 2675 }) 2676 ); 2677 }); 2678 2679 this.update(); 2680 } 2681 2682 return function (selector) { 2683 Donald.$(selector).each(function () { 2684 var $this = $(this), float; 2685 if (this.tagName == 'svg') { 2686 float = $this.data('float-svg'); 2687 if (float) { 2688 float.set($this.attr('data-float-options')); 2689 } else { 2690 $this.data('float-svg', new FloatSVG(this, $this.attr('data-float-options'))); 2691 } 2692 } 2693 }) 2694 }; 2695 })(); 2696 2697 /** 2698 * @class Shop 2699 * 2700 * @requires Minipopup 2701 * @requires noUiSlider 2702 * @instance single 2703 */ 2704 Donald.Shop = { 2705 init: function () { 2706 // Functions for products 2707 this.initProductsQuickview(); 2708 this.initProductsCartAction(); 2709 this.initProductsLoad(); 2710 //this.initProductsScrollLoad('.scroll-load'); 2711 this.initProductType('slideup'); 2712 this.initVariation(); 2713 //this.initWishlistButton('.product:not(.product-single) .btn-wishlist'); 2714 this.initWishlistButton('.product .btn-wishlist'); 2715 Donald.call(Donald.ratingTooltip, 500); 2716 2717 // Functions for shop page 2718 this.initSelectMenu('.select-menu'); 2719 //Donald.priceSlider('.filter-price-slider'); 2720 }, 2721 2722 initVariation: function (type) { 2723 $('.product:not(.product-single) .product-variations > a').on('click', function (e) { 2724 var $this = $(this), 2725 $image = $this.closest('.product').find('.product-media img'); 2726 2727 if (!$image.data('image-src')) 2728 $image.data('image-src', $image.attr('src')); 2729 2730 $this.toggleClass('active').siblings().removeClass('active'); 2731 2732 if ($this.hasClass('active')) { 2733 $image.attr('src', $this.data('src')) 2734 } else { 2735 $image.attr('src', $image.data('image-src')); 2736 $this.blur(); 2737 } 2738 //e.preventDefault(); 2739 }) 2740 }, 2741 2742 initProductType: function (type) { 2743 2744 // "slideup" type 2745 if (type === 'slideup') { 2746 $('.product-slideup-content .product-details').each(function (e) { 2747 var $this = $(this), 2748 hidden_height = $this.find('.product-hide-details').outerHeight(true); 2749 2750 $this.height($this.height() - hidden_height); 2751 }); 2752 2753 $(Donald.byClass('product-slideup-content')) 2754 .on('mouseenter touchstart', function (e) { 2755 var $this = $(this), 2756 hidden_height = $this.find('.product-hide-details').outerHeight(true); 2757 2758 $this.find('.product-details').css('transform', 'translateY(' + (-hidden_height) + 'px)'); 2759 $this.find('.product-hide-details').css('transform', 'translateY(' + (-hidden_height) + 'px)'); 2760 }) 2761 .on('mouseleave touchleave', function (e) { 2762 var $this = $(this), 2763 hidden_height = $this.find('.product-hide-details').outerHeight(true); 2764 2765 $this.find('.product-details').css('transform', 'translateY(0)'); 2766 $this.find('.product-hide-details').css('transform', 'translateY(0)'); 2767 }); 2768 } 2769 }, 2770 2771 initSelectMenu: function () { 2772 Donald.$body 2773 // open select menu 2774 .on('mousedown', '.select-menu', function (e) { 2775 var $selectMenu = $(e.currentTarget), 2776 $target = $(e.target), 2777 isOpened = $selectMenu.hasClass('opened'); 2778 2779 // close all select menu 2780 $('.select-menu').removeClass('opened'); 2781 2782 if ($selectMenu.is($target.parent())) { 2783 // if toggle is clicked 2784 isOpened || $selectMenu.addClass('opened'); 2785 e.stopPropagation(); 2786 } else { 2787 // if item is clicked 2788 $target.parent().toggleClass('active'); 2789 if ($target.parent().hasClass('active')) { // add select-item, and show 2790 $('.select-items').show(); 2791 $('<a href="#" class="select-item">' + $target.text() + '<i class="d-icon-times"></i></a>') 2792 .insertBefore('.select-items .filter-clean') 2793 .hide().fadeIn() 2794 .data('link', $target.parent()); // link to anchor's parent - li tag 2795 } else { // remove select-item 2796 $('.select-items > .select-item').filter(function (i, el) { 2797 return el.innerText == $target.text(); 2798 }).fadeOut(function () { 2799 $(this).remove(); 2800 // if only clean all button remains, // then hide select-items 2801 if ($('.select-items').children().length < 2) { 2802 $('.select-items').hide(); 2803 } 2804 }); 2805 } 2806 } 2807 }) 2808 // Close select menu 2809 .on('mousedown', function (e) { 2810 $('.select-menu').removeClass('opened'); 2811 }) 2812 .on('click', '.select-menu a', function (e) { 2813 e.preventDefault(); 2814 }) 2815 2816 // Remove all filters in navigation 2817 .on('click', '.select-items .filter-clean', function (e) { 2818 var $clean = $(this); 2819 $clean.siblings().each(function () { 2820 var $link = $(this).data('link'); 2821 $link && $link.removeClass('active'); 2822 }); 2823 $clean.parent().fadeOut(function () { 2824 $clean.siblings().remove(); 2825 }); 2826 e.preventDefault(); 2827 }) 2828 // Remove one filter in navigation 2829 .on('click', '.select-item i', function (e) { 2830 $(e.currentTarget).parent().fadeOut(function () { 2831 var $this = $(this), 2832 $link = $this.data('link'); 2833 $link && $link.toggleClass('active'); 2834 $this.remove(); 2835 2836 // if only clean all button remains, then hide select-items 2837 if ($('.select-items').children().length < 2) { 2838 $('.select-items').hide(); 2839 } 2840 }); 2841 e.preventDefault(); 2842 }) 2843 // Remove all filters 2844 .on('click', '.filter-clean', function (e) { 2845 $('.shop-sidebar .filter-items .active').removeClass('active'); 2846 e.preventDefault(); 2847 }) 2848 // Toggle filter 2849 .on('click', '.filter-items a', function (e) { 2850 var $ul = $(this).closest('.filter-items'); 2851 if (!$ul.hasClass('search-ul') && !$ul.parent().hasClass('select-menu')) { 2852 $(this).parent().toggleClass('active').trigger("change-class");; 2853 e.preventDefault(); 2854 } 2855 }) 2856 }, 2857 2858 /******************************************** tyam QuickView **********************************************/ 2859 initProductsQuickview: function () { 2860 Donald.$body.on('click', '.btn-quickview', function (e) { 2861 e.preventDefault(); 2862 2863 var _data = $(this).data(); 2864 2865 Donald.popup({ 2866 items: { 2867 src: "/Product/QuickView/" + _data.value 2868 }, 2869 callbacks: { 2870 ajaxContentAdded: function () { 2871 2872 this.wrap.imagesLoaded(function () { 2873 2874 Donald.initProductSingle($('.mfp-product .product-single'));
2875 setLikeToQuickView(); 2876 setNumeric(); 2877 }); 2878 } 2879 } 2880 }, 'quickview'); 2881 }); 2882 }, 2883 initProductsCartAction: function () { 2884 // Add to cart in products 2885 Donald.$body.on('click', '.btn-product-icon.btn-cart, .btn-product.btn-cart', function (e) { 2886 e.preventDefault(); 2887 2888 var $product = $(this).closest('.product'); 2889 2890 if ($product.hasClass('product-single')) { 2891 return; 2892 } 2893 2894 var proCode = $product.find('.product-action-vertical > a').attr('data-value'); 2895 var proName = $product.find('.product-name > a').html(); 2896 2897 var labelPrice = $product.find('.product-price > del').attr('data-value'); 2898 var salePrice = $product.find('.product-price').attr('data-value'); 2899 var salePriceToShow = $product.find('.product-price').attr('data-priceshow'); 2900 2901 var imageLink = $product.find('.product-media img').attr('src'); 2902 var quantity = 1; 2903 2904 addToShappingCart('fast', proCode, proName, labelPrice, salePrice, salePriceToShow, quantity, imageLink); 2905 2906 /******************************************* tyam popup basket ********************************************/ 2907 //// if not product single, then open minipopup 2908 //$product.hasClass('product-single') || 2909 //Donald.Minipopup.open({ 2910 // message: ' اضاÙ٠شد. <a href="cart.html" class="btn btn-link btn-sm btn-slide-right btn-infinite">Ù Ø´Ø§ÙØ¯Ù سبد <i class="d-icon-arrow-right"></i></a>', 2911 // productClass: ' product-cart', 2912 // name: $product.find('.product-name').text(), 2913 // nameLink: $product.find('.product-name > a').attr('href'), 2914 // imageSrc: $product.find('.product-media img').attr('src'), 2915 // imageLink: $product.find('.product-name > a').attr('href'), 2916 // price: $product.find('.product-price').html(), 2917 // count: $product.find('.quantity').val() 2918 //}); 2919 /******************************************* tyam popup basket end ********************************************/ 2920 }); 2921 2922 }, 2923 initProductsLoad: function () { 2924 $('.btn-load').on('click', function (e) { 2925 var $this = $(this), 2926 $wrapper = $($this.data('load-to')), 2927 loadText = $this.html(); 2928 2929 $this.text('Loading ...'); 2930 e.preventDefault(); 2931 2932 $.ajax({
2933 url: $this.attr('href'), 2934 success: function (result) { 2935 var $newItems = $(result); 2936 2937 setTimeout(function () { 2938 $wrapper.isotope('insert', $newItems); 2939 $this.html(loadText); 2940 2941 var loadCount = parseInt($this.data('load-count') ? $this.data('load-count') : 0); 2942 $this.data('load-count', ++loadCount); 2943 2944 // do not load more than 2 times 2945 loadCount >= 2 && $this.hide(); 2946 2947 Donald.Shop.initWishlistButton($newItems.find('.btn-wishlist')); 2948 }, 350); 2949 }, 2950 failure: function () { 2951 $this.text("Sorry something went wrong."); 2952 } 2953 }); 2954 }); 2955 }, 2956 initProductsScrollLoad: function ($obj) { 2957 var $wrapper = Donald.$($obj) 2958 , top; 2959 var loadProducts = function (e) { 2960 if (window.pageYOffset > top + $wrapper.outerHeight() - window.innerHeight - 150 && 'loading' != $wrapper.data('load-state')) { 2961 $.ajax({
2962 url: 'ajax/ajax-products.html', 2963 success: function (result) { 2964 var $newItems = $(result); 2965 $wrapper.data('load-state', 'loading'); 2966 if (!$wrapper.next().hasClass('load-more-overlay')) { 2967 $('<div class="mt-4 mb-4 load-more-overlay loading"></div>').insertAfter($wrapper); 2968 } else { 2969 $wrapper.next().addClass('loading'); 2970 } 2971 setTimeout(function () { 2972 $wrapper.next().removeClass('loading'); 2973 $wrapper.append($newItems); 2974 setTimeout(function () { 2975 $wrapper.find('.product-wrap.fade:not(.in)').addClass('in'); 2976 }, 200); 2977 $wrapper.data('load-state', 'loaded'); 2978 }, 500); 2979 var loadCount = parseInt($wrapper.data('load-count') ? $wrapper.data('load-count') : 0); 2980 $wrapper.data('load-count', ++loadCount); 2981 loadCount > 2 && window.removeEventListener('scroll', loadProducts, { passive: true }); 2982 }, 2983 failure: function () { 2984 $this.text("Sorry something went wrong."); 2985 } 2986 }); 2987 } 2988 } 2989 if ($wrapper.length > 0) { 2990 top = $wrapper.offset().top; 2991 window.addEventListener('scroll', loadProducts, { passive: true }); 2992 } 2993 }, 2994 initWishlistButton: function (selector) { 2995 Donald.$(selector).on('click', function (e) { 2996 2997 var $this = $(this); 2998 2999 var productCode = $(this).attr('data-value'); 3000 $this.toggleClass('added').addClass('load-more-overlay loading'); 3001 3002 setTimeout(function () { 3003
3004 likeProduct($this, productCode); 3005 3006 //$this.removeClass('load-more-overlay loading').find('i').toggleClass('d-icon-heart').toggleClass('d-icon-heart-full'); 3007 //if ($this.hasClass('added')) { 3008 // $this.attr('title', 'ØØ°Ù از ÙÛØ³Øª Ø¹ÙØ§ÙÙâÙ ÙØ¯Û ÙØ§'); 3009 //} else { 3010 // $this.attr('title', 'Ø§ÙØ²Ùد٠ب٠ÙÛØ³Øª Ø¹ÙØ§ÙÙâÙ ÙØ¯Û ÙØ§'); 3011 //} 3012 3013 }, 500); 3014 3015 e.preventDefault(); 3016 }) 3017 } 3018 } 3019 3020 /** 3021 * Donald Initializer 3022 */ 3023 3024 // Initialize Method while document is being loaded. 3025 Donald.prepare = function () { 3026 if (Donald.$body.hasClass('with-flex-container') && window.innerWidth >= 1200) { 3027 Donald.$body.addClass('sidebar-active'); 3028 } 3029 }; 3030 3031 // Initialize Method while document is interactive 3032 Donald.initLayout = function () { 3033 Donald.isotopes('.grid:not(.grid-float)'); 3034 Donald.stickySidebar('.sticky-sidebar'); 3035 } 3036 3037 // Initialize Method after document has been loaded 3038 Donald.init = function () { 3039 Donald.appearAnimate('.appear-animate'); // Runs appear animations 3040 Donald.Minipopup.init(); // Initialize minipopup 3041 Donald.Shop.init(); // Initialize shop 3042 Donald.initProductSinglePage(); // Initialize single product page 3043 Donald.slider('.owl-carousel'); // Initialize slider 3044 Donald.headerToggleSearch('.hs-toggle'); // Initialize header toggle search 3045 Donald.stickyContent('.product-sticky-content, .sticky-header'); // Initialize sticky content 3046 Donald.stickyContent('.sticky-footer', Donald.defaults.stickyFooter); // Initialize sticky footer 3047 Donald.stickyContent('.sticky-toolbox', Donald.defaults.stickyToolbox); // Initialize sticky toolbox 3048 Donald.sidebar('sidebar'); // Initialize left sidebar 3049 Donald.sidebar('right-sidebar'); // Initialize right sidebar 3050 Donald.quantityInput('.quantity'); // Initialize quantity input 3051 Donald.playableVideo('.post-video'); // Initialize playable video 3052 Donald.initAccordion('.card-header > a'); // Initialize accordion 3053 Donald.initTab('.nav-tabs'); // Initialize tab 3054 Donald.initAlert('.alert'); // Initialize alert 3055 Donald.parallax('.parallax'); // Initialize parallax 3056 Donald.countTo('.count-to'); // Initialize countTo 3057 Donald.countdown('.product-countdown, .countdown'); // Initialize countdown 3058 Donald.Menu.init(); // Initialize menus 3059 Donald.initZoom(); // Initialize zoom 3060 Donald.initNavFilter('.nav-filters .nav-filter'); // Initialize navigation filters for blog, products 3061 Donald.initPopups(); // Initialize popups: login, register, play video, newsletter popup 3062 /******************************************* tyam newsLatter ********************************************/ 3063 //Donald.initPurchasedMinipopup(); // Initialize minipopup for purchased event 3064 Donald.initScrollTopButton(); // Initialize scroll top button. 3065 Donald.floatSVG('.float-svg'); // Floating SVG 3066 Donald.lazyload('body', true); 3067 3068 Donald.status = 'complete'; 3069 } 3070 3071 /** 3072 * Setup Donald 3073 */ 3074 3075 // Prepare Donald Theme 3076 Donald.prepare(); 3077 3078 // Initialize Donald Theme 3079 Donald.status = 'loaded'; 3080 Donald.$body.addClass('loaded'); 3081 Donald.$window.trigger('donald_load'); 3082 3083 Donald.call(Donald.initLayout); 3084 Donald.call(Donald.init); 3085 Donald.$window.trigger('donald_complete'); 3086 Donald.refreshSidebar(); 3087 3088 //window.onload = function () { 3089 // Donald.status = 'loaded'; 3090 // Donald.$body.addClass('loaded'); 3091 // Donald.$window.trigger('donald_load'); 3092 3093 // Donald.call(Donald.initLayout); 3094 // Donald.call(Donald.init); 3095 // Donald.$window.trigger('donald_complete'); 3096 // Donald.refreshSidebar(); 3097 //} 3098})();
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.