1/* 2 _ _ _ _ 3 ___| (_) ___| | __ (_)___ 4/ __| | |/ __| |/ / | / __| 5\__ \ | | (__| < _ | \__ \ 6|___/_|_|\___|_|\_(_)/ |___/ 7 |__/ 8 9 Version: 1.8.0 10 Author: Ken Wheeler 11 Website: http://kenwheeler.github.io 12 Docs: http://kenwheeler.github.io/slick 13 Repo: http://github.com/kenwheeler/slick 14 Issues: http://github.com/kenwheeler/slick/issues 15 16 */ 17/* global window, document, define, jQuery, setInterval, clearInterval */ 18(function (factory) { 19 "use strict"; 20 if (typeof define === "function" && define.amd) { 21 define(["jquery"], factory); 22 } else if (typeof exports !== "undefined") { 23 module.exports = factory(require("jquery")); 24 } else { 25 factory(jQuery); 26 } 27})(function ($) { 28 "use strict"; 29 var Slick = window.Slick || {}; 30 31 Slick = (function () { 32 var instanceUid = 0; 33 34 function Slick(element, settings) { 35 var _ = this, 36 dataSettings; 37 38 _.defaults = { 39 accessibility: true, 40 adaptiveHeight: false, 41 appendArrows: $(element), 42 appendDots: $(element), 43 arrows: true, 44 asNavFor: null, 45 prevArrow: 46 '<button class="slick-prev" aria-label="Previous" type="button">Previous</button>', 47 nextArrow: 48 '<button class="slick-next" aria-label="Next" type="button">Next</button>', 49 autoplay: false, 50 autoplaySpeed: 3000, 51 centerMode: false, 52 centerPadding: "50px", 53 cssEase: "ease", 54 customPaging: function (slider, i) { 55 return $('<button type="button" />').text(i + 1); 56 }, 57 dots: false, 58 dotsClass: "slick-dots", 59 draggable: true, 60 easing: "linear", 61 edgeFriction: 0.35, 62 fade: false, 63 focusOnSelect: false, 64 focusOnChange: false, 65 infinite: true, 66 initialSlide: 0, 67 lazyLoad: "ondemand", 68 mobileFirst: false, 69 pauseOnHover: true, 70 pauseOnFocus: true, 71 pauseOnDotsHover: false, 72 respondTo: "window", 73 responsive: null, 74 rows: 1, 75 rtl: false, 76 slide: "", 77 slidesPerRow: 1, 78 slidesToShow: 1, 79 slidesToScroll: 1, 80 speed: 500, 81 swipe: true, 82 swipeToSlide: false, 83 touchMove: true, 84 touchThreshold: 5, 85 useCSS: true, 86 useTransform: true, 87 variableWidth: false, 88 vertical: false, 89 verticalSwiping: false, 90 waitForAnimate: true, 91 zIndex: 1000, 92 }; 93 94 _.initials = { 95 animating: false, 96 dragging: false, 97 autoPlayTimer: null, 98 currentDirection: 0, 99 currentLeft: null, 100 currentSlide: 0, 101 direction: 1, 102 $dots: null, 103 listWidth: null, 104 listHeight: null, 105 loadIndex: 0, 106 $nextArrow: null, 107 $prevArrow: null, 108 scrolling: false, 109 slideCount: null, 110 slideWidth: null, 111 $slideTrack: null, 112 $slides: null, 113 sliding: false, 114 slideOffset: 0, 115 swipeLeft: null, 116 swiping: false, 117 $list: null, 118 touchObject: {}, 119 transformsEnabled: false, 120 unslicked: false, 121 }; 122 123 $.extend(_, _.initials); 124 125 _.activeBreakpoint = null; 126 _.animType = null; 127 _.animProp = null; 128 _.breakpoints = []; 129 _.breakpointSettings = []; 130 _.cssTransitions = false; 131 _.focussed = false; 132 _.interrupted = false; 133 _.hidden = "hidden"; 134 _.paused = true; 135 _.positionProp = null; 136 _.respondTo = null; 137 _.rowCount = 1; 138 _.shouldClick = true; 139 _.$slider = $(element); 140 _.$slidesCache = null; 141 _.transformType = null; 142 _.transitionType = null; 143 _.visibilityChange = "visibilitychange"; 144 _.windowWidth = 0; 145 _.windowTimer = null; 146 147 dataSettings = $(element).data("slick") || {}; 148 149 _.options = $.extend({}, _.defaults, settings, dataSettings); 150 151 _.currentSlide = _.options.initialSlide; 152 153 _.originalSettings = _.options; 154 155 if (typeof document.mozHidden !== "undefined") { 156 _.hidden = "mozHidden"; 157 _.visibilityChange = "mozvisibilitychange"; 158 } else if (typeof document.webkitHidden !== "undefined") { 159 _.hidden = "webkitHidden"; 160 _.visibilityChange = "webkitvisibilitychange"; 161 } 162 163 _.autoPlay = $.proxy(_.autoPlay, _); 164 _.autoPlayClear = $.proxy(_.autoPlayClear, _); 165 _.autoPlayIterator = $.proxy(_.autoPlayIterator, _); 166 _.changeSlide = $.proxy(_.changeSlide, _); 167 _.clickHandler = $.proxy(_.clickHandler, _); 168 _.selectHandler = $.proxy(_.selectHandler, _); 169 _.setPosition = $.proxy(_.setPosition, _); 170 _.swipeHandler = $.proxy(_.swipeHandler, _); 171 _.dragHandler = $.proxy(_.dragHandler, _); 172 _.keyHandler = $.proxy(_.keyHandler, _); 173 174 _.instanceUid = instanceUid++; 175 176 // A simple way to check for HTML strings 177 // Strict HTML recognition (must start with <) 178 // Extracted from jQuery v1.11 source 179 _.htmlExpr = /^(?:\s*(<[\w\W]+>)[^>]*)$/; 180 181 _.registerBreakpoints(); 182 _.init(true); 183 } 184 185 return Slick; 186 })(); 187 188 Slick.prototype.activateADA = function () { 189 var _ = this; 190 191 _.$slideTrack 192 .find(".slick-active") 193 .attr({ 194 "aria-hidden": "false", 195 }) 196 .find("a, input, button, select") 197 .attr({ 198 tabindex: "0", 199 }); 200 }; 201 202 Slick.prototype.addSlide = Slick.prototype.slickAdd = function ( 203 markup, 204 index, 205 addBefore 206 ) { 207 var _ = this; 208 209 if (typeof index === "boolean") { 210 addBefore = index; 211 index = null; 212 } else if (index < 0 || index >= _.slideCount) { 213 return false;
vendor: 4,627 bytes, lines 214-399
214 } 215 216 _.unload(); 217 218 if (typeof index === "number") { 219 if (index === 0 && _.$slides.length === 0) { 220 $(markup).appendTo(_.$slideTrack); 221 } else if (addBefore) { 222 $(markup).insertBefore(_.$slides.eq(index)); 223 } else { 224 $(markup).insertAfter(_.$slides.eq(index)); 225 } 226 } else { 227 if (addBefore === true) { 228 $(markup).prependTo(_.$slideTrack); 229 } else { 230 $(markup).appendTo(_.$slideTrack); 231 } 232 } 233 234 _.$slides = _.$slideTrack.children(this.options.slide); 235 236 _.$slideTrack.children(this.options.slide).detach(); 237 238 _.$slideTrack.append(_.$slides); 239 240 _.$slides.each(function (index, element) { 241 $(element).attr("data-slick-index", index); 242 }); 243 244 _.$slidesCache = _.$slides; 245 246 _.reinit(); 247 }; 248 249 Slick.prototype.animateHeight = function () { 250 var _ = this; 251 if ( 252 _.options.slidesToShow === 1 && 253 _.options.adaptiveHeight === true && 254 _.options.vertical === false 255 ) { 256 var targetHeight = _.$slides.eq(_.currentSlide).outerHeight(true); 257 _.$list.animate( 258 { 259 height: targetHeight, 260 }, 261 _.options.speed 262 ); 263 } 264 }; 265 266 Slick.prototype.animateSlide = function (targetLeft, callback) { 267 var animProps = {}, 268 _ = this; 269 270 _.animateHeight(); 271 272 if (_.options.rtl === true && _.options.vertical === false) { 273 targetLeft = -targetLeft; 274 } 275 if (_.transformsEnabled === false) { 276 if (_.options.vertical === false) { 277 _.$slideTrack.animate( 278 { 279 left: targetLeft, 280 }, 281 _.options.speed, 282 _.options.easing, 283 callback 284 ); 285 } else { 286 _.$slideTrack.animate( 287 { 288 top: targetLeft, 289 }, 290 _.options.speed, 291 _.options.easing, 292 callback 293 ); 294 } 295 } else { 296 if (_.cssTransitions === false) { 297 if (_.options.rtl === true) { 298 _.currentLeft = -_.currentLeft; 299 } 300 $({ 301 animStart: _.currentLeft, 302 }).animate( 303 { 304 animStart: targetLeft, 305 }, 306 { 307 duration: _.options.speed, 308 easing: _.options.easing, 309 step: function (now) { 310 now = Math.ceil(now); 311 if (_.options.vertical === false) { 312 animProps[_.animType] = "translate(" + now + "px, 0px)"; 313 _.$slideTrack.css(animProps); 314 } else { 315 animProps[_.animType] = "translate(0px," + now + "px)"; 316 _.$slideTrack.css(animProps); 317 } 318 }, 319 complete: function () { 320 if (callback) { 321 callback.call(); 322 } 323 }, 324 } 325 ); 326 } else { 327 _.applyTransition(); 328 targetLeft = Math.ceil(targetLeft); 329 330 if (_.options.vertical === false) { 331 animProps[_.animType] = "translate3d(" + targetLeft + "px, 0px, 0px)"; 332 } else { 333 animProps[_.animType] = "translate3d(0px," + targetLeft + "px, 0px)"; 334 } 335 _.$slideTrack.css(animProps); 336 337 if (callback) { 338 setTimeout(function () { 339 _.disableTransition(); 340 341 callback.call(); 342 }, _.options.speed); 343 } 344 } 345 } 346 }; 347 348 Slick.prototype.getNavTarget = function () { 349 var _ = this, 350 asNavFor = _.options.asNavFor; 351 352 if (asNavFor && asNavFor !== null) { 353 asNavFor = $(asNavFor).not(_.$slider); 354 } 355 356 return asNavFor; 357 }; 358 359 Slick.prototype.asNavFor = function (index) { 360 var _ = this, 361 asNavFor = _.getNavTarget(); 362 363 if (asNavFor !== null && typeof asNavFor === "object") { 364 asNavFor.each(function () { 365 var target = $(this).slick("getSlick"); 366 if (!target.unslicked) { 367 target.slideHandler(index, true); 368 } 369 }); 370 } 371 }; 372 373 Slick.prototype.applyTransition = function (slide) { 374 var _ = this, 375 transition = {}; 376 377 if (_.options.fade === false) { 378 transition[_.transitionType] = 379 _.transformType + " " + _.options.speed + "ms " + _.options.cssEase; 380 } else { 381 transition[_.transitionType] = 382 "opacity " + _.options.speed + "ms " + _.options.cssEase; 383 } 384 385 if (_.options.fade === false) { 386 _.$slideTrack.css(transition); 387 } else { 388 _.$slides.eq(slide).css(transition); 389 } 390 }; 391 392 Slick.prototype.autoPlay = function () { 393 var _ = this; 394 395 _.autoPlayClear(); 396 397 if (_.slideCount > _.options.slidesToShow) { 398 _.autoPlayTimer = setInterval( 399 _.autoPlayIterator,
400 _.options.autoplaySpeed 401 ); 402 } 403 }; 404 405 Slick.prototype.autoPlayClear = function () { 406 var _ = this; 407 408 if (_.autoPlayTimer) { 409 clearInterval(_.autoPlayTimer); 410 } 411 }; 412 413 Slick.prototype.autoPlayIterator = function () { 414 var _ = this, 415 slideTo = _.currentSlide + _.options.slidesToScroll; 416 417 if (!_.paused && !_.interrupted && !_.focussed) { 418 if (_.options.infinite === false) { 419 if (_.direction === 1 && _.currentSlide + 1 === _.slideCount - 1) { 420 _.direction = 0; 421 } else if (_.direction === 0) { 422 slideTo = _.currentSlide - _.options.slidesToScroll; 423 424 if (_.currentSlide - 1 === 0) { 425 _.direction = 1; 426 } 427 } 428 } 429 430 _.slideHandler(slideTo); 431 } 432 }; 433 434 Slick.prototype.buildArrows = function () { 435 var _ = this; 436 437 if (_.options.arrows === true) { 438 _.$prevArrow = $(_.options.prevArrow).addClass("slick-arrow"); 439 _.$nextArrow = $(_.options.nextArrow).addClass("slick-arrow"); 440 441 if (_.slideCount > _.options.slidesToShow) { 442 _.$prevArrow 443 .removeClass("slick-hidden") 444 .removeAttr("aria-hidden tabindex"); 445 _.$nextArrow 446 .removeClass("slick-hidden") 447 .removeAttr("aria-hidden tabindex"); 448 449 if (_.htmlExpr.test(_.options.prevArrow)) { 450 _.$prevArrow.prependTo(_.options.appendArrows); 451 } 452 453 if (_.htmlExpr.test(_.options.nextArrow)) { 454 _.$nextArrow.appendTo(_.options.appendArrows); 455 } 456 457 if (_.options.infinite !== true) { 458 _.$prevArrow.addClass("slick-disabled").attr("aria-disabled", "true"); 459 } 460 } else { 461 _.$prevArrow 462 .add(_.$nextArrow) 463 464 .addClass("slick-hidden") 465 .attr({ 466 "aria-disabled": "true", 467 tabindex: "-1", 468 }); 469 } 470 } 471 }; 472 473 Slick.prototype.buildDots = function () { 474 var _ = this, 475 i, 476 dot; 477 478 if (_.options.dots === true && _.slideCount > _.options.slidesToShow) { 479 _.$slider.addClass("slick-dotted"); 480 481 dot = $("<ul />").addClass(_.options.dotsClass); 482 483 for (i = 0; i <= _.getDotCount(); i += 1) { 484 dot.append($("<li />").append(_.options.customPaging.call(this, _, i))); 485 } 486 487 _.$dots = dot.appendTo(_.options.appendDots); 488 489 _.$dots.find("li").first().addClass("slick-active"); 490 } 491 }; 492 493 Slick.prototype.buildOut = function () { 494 var _ = this; 495 496 _.$slides = _.$slider 497 .children(_.options.slide + ":not(.slick-cloned)") 498 .addClass("slick-slide"); 499 500 _.slideCount = _.$slides.length; 501 502 _.$slides.each(function (index, element) { 503 $(element) 504 .attr("data-slick-index", index) 505 .data("originalStyling", $(element).attr("style") || ""); 506 }); 507 508 _.$slider.addClass("slick-slider"); 509 510 _.$slideTrack = 511 _.slideCount === 0 512 ? $('<div class="slick-track"/>').appendTo(_.$slider) 513 : _.$slides.wrapAll('<div class="slick-track"/>').parent(); 514 515 _.$list = _.$slideTrack.wrap('<div class="slick-list"/>').parent(); 516 _.$slideTrack.css("opacity", 0); 517 518 if (_.options.centerMode === true || _.options.swipeToSlide === true) { 519 _.options.slidesToScroll = 1; 520 } 521 522 $("img[data-lazy]", _.$slider).not("[src]").addClass("slick-loading"); 523 524 _.setupInfinite(); 525 526 _.buildArrows(); 527 528 _.buildDots(); 529 530 _.updateDots(); 531 532 _.setSlideClasses(typeof _.currentSlide === "number" ? _.currentSlide : 0); 533 534 if (_.options.draggable === true) { 535 _.$list.addClass("draggable"); 536 } 537 }; 538 539 Slick.prototype.buildRows = function () { 540 var _ = this, 541 a, 542 b, 543 c, 544 newSlides, 545 numOfSlides, 546 originalSlides, 547 slidesPerSection; 548 549 newSlides = document.createDocumentFragment(); 550 originalSlides = _.$slider.children(); 551 552 if (_.options.rows > 0) { 553 slidesPerSection = _.options.slidesPerRow * _.options.rows; 554 numOfSlides = Math.ceil(originalSlides.length / slidesPerSection); 555 556 for (a = 0; a < numOfSlides; a++) { 557 var slide = document.createElement("div"); 558 for (b = 0; b < _.options.rows; b++) { 559 var row = document.createElement("div"); 560 for (c = 0; c < _.options.slidesPerRow; c++) { 561 var target = 562 a * slidesPerSection + (b * _.options.slidesPerRow + c); 563 if (originalSlides.get(target)) { 564 row.appendChild(originalSlides.get(target)); 565 } 566 } 567 slide.appendChild(row); 568 } 569 newSlides.appendChild(slide); 570 } 571 572 _.$slider.empty().append(newSlides); 573 _.$slider 574 .children() 575 .children() 576 .children() 577 .css({ 578 width: 100 / _.options.slidesPerRow + "%", 579 display: "inline-block", 580 }); 581 } 582 }; 583 584 Slick.prototype.checkResponsive = function (initial, forceUpdate) { 585 var _ = this, 586 breakpoint,
vendor: 13,676 bytes, lines 587-1093
587 targetBreakpoint, 588 respondToWidth, 589 triggerBreakpoint = false; 590 var sliderWidth = _.$slider.width(); 591 var windowWidth = window.innerWidth || $(window).width(); 592 593 if (_.respondTo === "window") { 594 respondToWidth = windowWidth; 595 } else if (_.respondTo === "slider") { 596 respondToWidth = sliderWidth; 597 } else if (_.respondTo === "min") { 598 respondToWidth = Math.min(windowWidth, sliderWidth); 599 } 600 601 if ( 602 _.options.responsive && 603 _.options.responsive.length && 604 _.options.responsive !== null 605 ) { 606 targetBreakpoint = null; 607 608 for (breakpoint in _.breakpoints) { 609 if (_.breakpoints.hasOwnProperty(breakpoint)) { 610 if (_.originalSettings.mobileFirst === false) { 611 if (respondToWidth < _.breakpoints[breakpoint]) { 612 targetBreakpoint = _.breakpoints[breakpoint]; 613 } 614 } else { 615 if (respondToWidth > _.breakpoints[breakpoint]) { 616 targetBreakpoint = _.breakpoints[breakpoint]; 617 } 618 } 619 } 620 } 621 622 if (targetBreakpoint !== null) { 623 if (_.activeBreakpoint !== null) { 624 if (targetBreakpoint !== _.activeBreakpoint || forceUpdate) { 625 _.activeBreakpoint = targetBreakpoint; 626 if (_.breakpointSettings[targetBreakpoint] === "unslick") { 627 _.unslick(targetBreakpoint); 628 } else { 629 _.options = $.extend( 630 {}, 631 _.originalSettings, 632 _.breakpointSettings[targetBreakpoint] 633 ); 634 if (initial === true) { 635 _.currentSlide = _.options.initialSlide; 636 } 637 _.refresh(initial); 638 } 639 triggerBreakpoint = targetBreakpoint; 640 } 641 } else { 642 _.activeBreakpoint = targetBreakpoint; 643 if (_.breakpointSettings[targetBreakpoint] === "unslick") { 644 _.unslick(targetBreakpoint); 645 } else { 646 _.options = $.extend( 647 {}, 648 _.originalSettings, 649 _.breakpointSettings[targetBreakpoint] 650 ); 651 if (initial === true) { 652 _.currentSlide = _.options.initialSlide; 653 } 654 _.refresh(initial); 655 } 656 triggerBreakpoint = targetBreakpoint; 657 } 658 } else { 659 if (_.activeBreakpoint !== null) { 660 _.activeBreakpoint = null; 661 _.options = _.originalSettings; 662 if (initial === true) { 663 _.currentSlide = _.options.initialSlide; 664 } 665 _.refresh(initial); 666 triggerBreakpoint = targetBreakpoint; 667 } 668 } 669 670 // only trigger breakpoints during an actual break. not on initialize. 671 if (!initial && triggerBreakpoint !== false) { 672 _.$slider.trigger("breakpoint", [_, triggerBreakpoint]); 673 } 674 } 675 }; 676 677 Slick.prototype.changeSlide = function (event, dontAnimate) { 678 var _ = this, 679 $target = $(event.currentTarget), 680 indexOffset, 681 slideOffset, 682 unevenOffset; 683 684 // If target is a link, prevent default action. 685 if ($target.is("a")) { 686 event.preventDefault(); 687 } 688 689 // If target is not the <li> element (ie: a child), find the <li>. 690 if (!$target.is("li")) { 691 $target = $target.closest("li"); 692 } 693 694 unevenOffset = _.slideCount % _.options.slidesToScroll !== 0; 695 indexOffset = unevenOffset 696 ? 0 697 : (_.slideCount - _.currentSlide) % _.options.slidesToScroll; 698 699 switch (event.data.message) { 700 case "previous": 701 slideOffset = 702 indexOffset === 0 703 ? _.options.slidesToScroll 704 : _.options.slidesToShow - indexOffset; 705 if (_.slideCount > _.options.slidesToShow) { 706 _.slideHandler(_.currentSlide - slideOffset, false, dontAnimate); 707 } 708 break; 709 710 case "next": 711 slideOffset = 712 indexOffset === 0 ? _.options.slidesToScroll : indexOffset; 713 if (_.slideCount > _.options.slidesToShow) { 714 _.slideHandler(_.currentSlide + slideOffset, false, dontAnimate); 715 } 716 break; 717 718 case "index": 719 var index = 720 event.data.index === 0 721 ? 0 722 : event.data.index || $target.index() * _.options.slidesToScroll; 723 724 _.slideHandler(_.checkNavigable(index), false, dontAnimate); 725 $target.children().trigger("focus"); 726 break; 727 728 default: 729 return; 730 } 731 }; 732 733 Slick.prototype.checkNavigable = function (index) { 734 var _ = this, 735 navigables, 736 prevNavigable; 737 738 navigables = _.getNavigableIndexes(); 739 prevNavigable = 0; 740 if (index > navigables[navigables.length - 1]) { 741 index = navigables[navigables.length - 1]; 742 } else { 743 for (var n in navigables) { 744 if (index < navigables[n]) { 745 index = prevNavigable; 746 break; 747 } 748 prevNavigable = navigables[n]; 749 } 750 } 751 752 return index; 753 }; 754 755 Slick.prototype.cleanUpEvents = function () { 756 var _ = this; 757 758 if (_.options.dots && _.$dots !== null) { 759 $("li", _.$dots) 760 .off("click.slick", _.changeSlide) 761 .off("mouseenter.slick", $.proxy(_.interrupt, _, true)) 762 .off("mouseleave.slick", $.proxy(_.interrupt, _, false)); 763 764 if (_.options.accessibility === true) { 765 _.$dots.off("keydown.slick", _.keyHandler); 766 } 767 } 768 769 _.$slider.off("focus.slick blur.slick"); 770 771 if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) { 772 _.$prevArrow && _.$prevArrow.off("click.slick", _.changeSlide); 773 _.$nextArrow && _.$nextArrow.off("click.slick", _.changeSlide); 774 775 if (_.options.accessibility === true) { 776 _.$prevArrow && _.$prevArrow.off("keydown.slick", _.keyHandler); 777 _.$nextArrow && _.$nextArrow.off("keydown.slick", _.keyHandler); 778 } 779 } 780 781 _.$list.off("touchstart.slick mousedown.slick", _.swipeHandler); 782 _.$list.off("touchmove.slick mousemove.slick", _.swipeHandler); 783 _.$list.off("touchend.slick mouseup.slick", _.swipeHandler); 784 _.$list.off("touchcancel.slick mouseleave.slick", _.swipeHandler); 785 786 _.$list.off("click.slick", _.clickHandler); 787 788 $(document).off(_.visibilityChange, _.visibility); 789 790 _.cleanUpSlideEvents(); 791 792 if (_.options.accessibility === true) { 793 _.$list.off("keydown.slick", _.keyHandler); 794 } 795 796 if (_.options.focusOnSelect === true) { 797 $(_.$slideTrack).children().off("click.slick", _.selectHandler); 798 } 799 800 $(window).off( 801 "orientationchange.slick.slick-" + _.instanceUid, 802 _.orientationChange 803 ); 804 805 $(window).off("resize.slick.slick-" + _.instanceUid, _.resize); 806 807 $("[draggable!=true]", _.$slideTrack).off("dragstart", _.preventDefault); 808 809 $(window).off("load.slick.slick-" + _.instanceUid, _.setPosition); 810 }; 811 812 Slick.prototype.cleanUpSlideEvents = function () { 813 var _ = this; 814 815 _.$list.off("mouseenter.slick", $.proxy(_.interrupt, _, true)); 816 _.$list.off("mouseleave.slick", $.proxy(_.interrupt, _, false)); 817 }; 818 819 Slick.prototype.cleanUpRows = function () { 820 var _ = this, 821 originalSlides; 822 823 if (_.options.rows > 0) { 824 originalSlides = _.$slides.children().children(); 825 originalSlides.removeAttr("style"); 826 _.$slider.empty().append(originalSlides); 827 } 828 }; 829 830 Slick.prototype.clickHandler = function (event) { 831 var _ = this; 832 833 if (_.shouldClick === false) { 834 event.stopImmediatePropagation(); 835 event.stopPropagation(); 836 event.preventDefault(); 837 } 838 }; 839 840 Slick.prototype.destroy = function (refresh) { 841 var _ = this; 842 843 _.autoPlayClear(); 844 845 _.touchObject = {}; 846 847 _.cleanUpEvents(); 848 849 $(".slick-cloned", _.$slider).detach(); 850 851 if (_.$dots) { 852 _.$dots.remove(); 853 } 854 855 if (_.$prevArrow && _.$prevArrow.length) { 856 _.$prevArrow 857 .removeClass("slick-disabled slick-arrow slick-hidden") 858 .removeAttr("aria-hidden aria-disabled tabindex") 859 .css("display", ""); 860 861 if (_.htmlExpr.test(_.options.prevArrow)) { 862 _.$prevArrow.remove(); 863 } 864 } 865 866 if (_.$nextArrow && _.$nextArrow.length) { 867 _.$nextArrow 868 .removeClass("slick-disabled slick-arrow slick-hidden") 869 .removeAttr("aria-hidden aria-disabled tabindex") 870 .css("display", ""); 871 872 if (_.htmlExpr.test(_.options.nextArrow)) { 873 _.$nextArrow.remove(); 874 } 875 } 876 877 if (_.$slides) { 878 _.$slides 879 .removeClass( 880 "slick-slide slick-active slick-center slick-visible slick-current" 881 ) 882 .removeAttr("aria-hidden") 883 .removeAttr("data-slick-index") 884 .each(function () { 885 $(this).attr("style", $(this).data("originalStyling")); 886 }); 887 888 _.$slideTrack.children(this.options.slide).detach(); 889 890 _.$slideTrack.detach(); 891 892 _.$list.detach(); 893 894 _.$slider.append(_.$slides); 895 } 896 897 _.cleanUpRows(); 898 899 _.$slider.removeClass("slick-slider"); 900 _.$slider.removeClass("slick-initialized"); 901 _.$slider.removeClass("slick-dotted"); 902 903 _.unslicked = true; 904 905 if (!refresh) { 906 _.$slider.trigger("destroy", [_]); 907 } 908 }; 909 910 Slick.prototype.disableTransition = function (slide) { 911 var _ = this, 912 transition = {}; 913 914 transition[_.transitionType] = ""; 915 916 if (_.options.fade === false) { 917 _.$slideTrack.css(transition); 918 } else { 919 _.$slides.eq(slide).css(transition); 920 } 921 }; 922 923 Slick.prototype.fadeSlide = function (slideIndex, callback) { 924 var _ = this; 925 926 if (_.cssTransitions === false) { 927 _.$slides.eq(slideIndex).css({ 928 zIndex: _.options.zIndex, 929 }); 930 931 _.$slides.eq(slideIndex).animate( 932 { 933 opacity: 1, 934 }, 935 _.options.speed, 936 _.options.easing, 937 callback 938 ); 939 } else { 940 _.applyTransition(slideIndex); 941 942 _.$slides.eq(slideIndex).css({ 943 opacity: 1, 944 zIndex: _.options.zIndex, 945 }); 946 947 if (callback) { 948 setTimeout(function () { 949 _.disableTransition(slideIndex); 950 951 callback.call(); 952 }, _.options.speed); 953 } 954 } 955 }; 956 957 Slick.prototype.fadeSlideOut = function (slideIndex) { 958 var _ = this; 959 960 if (_.cssTransitions === false) { 961 _.$slides.eq(slideIndex).animate( 962 { 963 opacity: 0, 964 zIndex: _.options.zIndex - 2, 965 }, 966 _.options.speed, 967 _.options.easing 968 ); 969 } else { 970 _.applyTransition(slideIndex); 971 972 _.$slides.eq(slideIndex).css({ 973 opacity: 0, 974 zIndex: _.options.zIndex - 2, 975 }); 976 } 977 }; 978 979 Slick.prototype.filterSlides = Slick.prototype.slickFilter = function ( 980 filter 981 ) { 982 var _ = this; 983 984 if (filter !== null) { 985 _.$slidesCache = _.$slides; 986 987 _.unload(); 988 989 _.$slideTrack.children(this.options.slide).detach(); 990 991 _.$slidesCache.filter(filter).appendTo(_.$slideTrack); 992 993 _.reinit(); 994 } 995 }; 996 997 Slick.prototype.focusHandler = function () { 998 var _ = this; 999 1000 _.$slider 1001 .off("focus.slick blur.slick") 1002 .on("focus.slick blur.slick", "*", function (event) { 1003 event.stopImmediatePropagation(); 1004 var $sf = $(this); 1005 1006 setTimeout(function () { 1007 if (_.options.pauseOnFocus) { 1008 _.focussed = $sf.is(":focus"); 1009 _.autoPlay(); 1010 } 1011 }, 0); 1012 }); 1013 }; 1014 1015 Slick.prototype.getCurrent = Slick.prototype.slickCurrentSlide = function () { 1016 var _ = this; 1017 return _.currentSlide; 1018 }; 1019 1020 Slick.prototype.getDotCount = function () { 1021 var _ = this; 1022 1023 var breakPoint = 0; 1024 var counter = 0; 1025 var pagerQty = 0; 1026 1027 if (_.options.infinite === true) { 1028 if (_.slideCount <= _.options.slidesToShow) { 1029 ++pagerQty; 1030 } else { 1031 while (breakPoint < _.slideCount) { 1032 ++pagerQty; 1033 breakPoint = counter + _.options.slidesToScroll; 1034 counter += 1035 _.options.slidesToScroll <= _.options.slidesToShow 1036 ? _.options.slidesToScroll 1037 : _.options.slidesToShow; 1038 } 1039 } 1040 } else if (_.options.centerMode === true) { 1041 pagerQty = _.slideCount; 1042 } else if (!_.options.asNavFor) { 1043 pagerQty = 1044 1 + 1045 Math.ceil( 1046 (_.slideCount - _.options.slidesToShow) / _.options.slidesToScroll 1047 ); 1048 } else { 1049 while (breakPoint < _.slideCount) { 1050 ++pagerQty; 1051 breakPoint = counter + _.options.slidesToScroll; 1052 counter += 1053 _.options.slidesToScroll <= _.options.slidesToShow 1054 ? _.options.slidesToScroll 1055 : _.options.slidesToShow; 1056 } 1057 } 1058 1059 return pagerQty - 1; 1060 }; 1061 1062 Slick.prototype.getLeft = function (slideIndex) { 1063 var _ = this, 1064 targetLeft, 1065 verticalHeight, 1066 verticalOffset = 0, 1067 targetSlide, 1068 coef; 1069 1070 _.slideOffset = 0; 1071 verticalHeight = _.$slides.first().outerHeight(true); 1072 1073 if (_.options.infinite === true) { 1074 if (_.slideCount > _.options.slidesToShow) { 1075 _.slideOffset = _.slideWidth * _.options.slidesToShow * -1; 1076 coef = -1; 1077 1078 if (_.options.vertical === true && _.options.centerMode === true) { 1079 if (_.options.slidesToShow === 2) { 1080 coef = -1.5; 1081 } else if (_.options.slidesToShow === 1) { 1082 coef = -2; 1083 } 1084 } 1085 verticalOffset = verticalHeight * _.options.slidesToShow * coef; 1086 } 1087 if (_.slideCount % _.options.slidesToScroll !== 0) { 1088 if ( 1089 slideIndex + _.options.slidesToScroll > _.slideCount && 1090 _.slideCount > _.options.slidesToShow 1091 ) { 1092 if (slideIndex > _.slideCount) { 1093 _.slideOffset =
1094 (_.options.slidesToShow - (slideIndex - _.slideCount)) * 1095 _.slideWidth * 1096 -1; 1097 verticalOffset = 1098 (_.options.slidesToShow - (slideIndex - _.slideCount)) * 1099 verticalHeight * 1100 -1; 1101 } else { 1102 _.slideOffset = 1103 (_.slideCount % _.options.slidesToScroll) * _.slideWidth * -1; 1104 verticalOffset = 1105 (_.slideCount % _.options.slidesToScroll) * verticalHeight * -1; 1106 } 1107 } 1108 } 1109 } else { 1110 if (slideIndex + _.options.slidesToShow > _.slideCount) { 1111 _.slideOffset = 1112 (slideIndex + _.options.slidesToShow - _.slideCount) * _.slideWidth; 1113 verticalOffset = 1114 (slideIndex + _.options.slidesToShow - _.slideCount) * verticalHeight; 1115 } 1116 } 1117 1118 if (_.slideCount <= _.options.slidesToShow) { 1119 _.slideOffset = 0; 1120 verticalOffset = 0; 1121 } 1122 1123 if ( 1124 _.options.centerMode === true && 1125 _.slideCount <= _.options.slidesToShow 1126 ) { 1127 _.slideOffset = 1128 (_.slideWidth * Math.floor(_.options.slidesToShow)) / 2 - 1129 (_.slideWidth * _.slideCount) / 2; 1130 } else if (_.options.centerMode === true && _.options.infinite === true) { 1131 _.slideOffset += 1132 _.slideWidth * Math.floor(_.options.slidesToShow / 2) - _.slideWidth; 1133 } else if (_.options.centerMode === true) { 1134 _.slideOffset = 0; 1135 _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2); 1136 } 1137 1138 if (_.options.vertical === false) { 1139 targetLeft = slideIndex * _.slideWidth * -1 + _.slideOffset; 1140 } else { 1141 targetLeft = slideIndex * verticalHeight * -1 + verticalOffset; 1142 } 1143 1144 if (_.options.variableWidth === true) { 1145 if ( 1146 _.slideCount <= _.options.slidesToShow || 1147 _.options.infinite === false 1148 ) { 1149 targetSlide = _.$slideTrack.children(".slick-slide").eq(slideIndex); 1150 } else { 1151 targetSlide = _.$slideTrack 1152 .children(".slick-slide") 1153 .eq(slideIndex + _.options.slidesToShow); 1154 } 1155 1156 if (_.options.rtl === true) { 1157 if (targetSlide[0]) { 1158 targetLeft = 1159 (_.$slideTrack.width() - 1160 targetSlide[0].offsetLeft - 1161 targetSlide.width()) * 1162 -1; 1163 } else { 1164 targetLeft = 0; 1165 } 1166 } else { 1167 targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0; 1168 } 1169 1170 if (_.options.centerMode === true) { 1171 if ( 1172 _.slideCount <= _.options.slidesToShow || 1173 _.options.infinite === false 1174 ) { 1175 targetSlide = _.$slideTrack.children(".slick-slide").eq(slideIndex); 1176 } else { 1177 targetSlide = _.$slideTrack 1178 .children(".slick-slide") 1179 .eq(slideIndex + _.options.slidesToShow + 1); 1180 } 1181 1182 if (_.options.rtl === true) { 1183 if (targetSlide[0]) { 1184 targetLeft = 1185 (_.$slideTrack.width() - 1186 targetSlide[0].offsetLeft - 1187 targetSlide.width()) * 1188 -1; 1189 } else { 1190 targetLeft = 0; 1191 } 1192 } else { 1193 targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0; 1194 } 1195 1196 targetLeft += (_.$list.width() - targetSlide.outerWidth()) / 2; 1197 } 1198 } 1199 1200 return targetLeft; 1201 }; 1202 1203 Slick.prototype.getOption = Slick.prototype.slickGetOption = function ( 1204 option 1205 ) { 1206 var _ = this; 1207 1208 return _.options[option]; 1209 }; 1210 1211 Slick.prototype.getNavigableIndexes = function () { 1212 var _ = this, 1213 breakPoint = 0, 1214 counter = 0, 1215 indexes = [], 1216 max; 1217 1218 if (_.options.infinite === false) { 1219 max = _.slideCount; 1220 } else { 1221 breakPoint = _.options.slidesToScroll * -1; 1222 counter = _.options.slidesToScroll * -1; 1223 max = _.slideCount * 2; 1224 } 1225 1226 while (breakPoint < max) { 1227 indexes.push(breakPoint); 1228 breakPoint = counter + _.options.slidesToScroll; 1229 counter += 1230 _.options.slidesToScroll <= _.options.slidesToShow
1231 ? _.options.slidesToScroll 1232 : _.options.slidesToShow; 1233 } 1234 1235 return indexes; 1236 }; 1237 1238 Slick.prototype.getSlick = function () { 1239 return this; 1240 }; 1241 1242 Slick.prototype.getSlideCount = function () { 1243 var _ = this, 1244 slidesTraversed, 1245 swipedSlide, 1246 centerOffset; 1247 1248 centerOffset = 1249 _.options.centerMode === true 1250 ? _.slideWidth * Math.floor(_.options.slidesToShow / 2) 1251 : 0; 1252 1253 if (_.options.swipeToSlide === true) { 1254 _.$slideTrack.find(".slick-slide").each(function (index, slide) { 1255 if ( 1256 slide.offsetLeft - centerOffset + $(slide).outerWidth() / 2 > 1257 _.swipeLeft * -1 1258 ) { 1259 swipedSlide = slide; 1260 return false; 1261 } 1262 }); 1263 1264 slidesTraversed = 1265 Math.abs($(swipedSlide).attr("data-slick-index") - _.currentSlide) || 1; 1266 1267 return slidesTraversed; 1268 } else { 1269 return _.options.slidesToScroll; 1270 } 1271 }; 1272 1273 Slick.prototype.goTo = Slick.prototype.slickGoTo = function ( 1274 slide, 1275 dontAnimate 1276 ) { 1277 var _ = this; 1278 1279 _.changeSlide( 1280 { 1281 data: { 1282 message: "index", 1283 index: parseInt(slide), 1284 }, 1285 }, 1286 dontAnimate 1287 ); 1288 }; 1289 1290 Slick.prototype.init = function (creation) { 1291 var _ = this; 1292 1293 if (!$(_.$slider).hasClass("slick-initialized")) { 1294 $(_.$slider).addClass("slick-initialized"); 1295 1296 _.buildRows(); 1297 _.buildOut(); 1298 _.setProps(); 1299 _.startLoad(); 1300 _.loadSlider(); 1301 _.initializeEvents(); 1302 _.updateArrows(); 1303 _.updateDots(); 1304 _.checkResponsive(true); 1305 _.focusHandler(); 1306 } 1307 1308 if (creation) { 1309 _.$slider.trigger("init", [_]); 1310 } 1311 1312 if (_.options.accessibility === true) { 1313 _.initADA(); 1314 } 1315 1316 if (_.options.autoplay) { 1317 _.paused = false; 1318 _.autoPlay(); 1319 } 1320 }; 1321 1322 Slick.prototype.initADA = function () { 1323 var _ = this, 1324 numDotGroups = Math.ceil(_.slideCount / _.options.slidesToShow), 1325 tabControlIndexes = _.getNavigableIndexes().filter(function (val) { 1326 return val >= 0 && val < _.slideCount; 1327 }); 1328 1329 _.$slides 1330 .add(_.$slideTrack.find(".slick-cloned")) 1331 .attr({ 1332 "aria-hidden": "true", 1333 tabindex: "-1", 1334 }) 1335 .find("a, input, button, select") 1336 .attr({ 1337 tabindex: "-1", 1338 }); 1339 1340 if (_.$dots !== null) { 1341 _.$slides.not(_.$slideTrack.find(".slick-cloned")).each(function (i) { 1342 var slideControlIndex = tabControlIndexes.indexOf(i); 1343 1344 $(this).attr({ 1345 role: "tabpanel", 1346 id: "slick-slide" + _.instanceUid + i, 1347 tabindex: -1, 1348 }); 1349 1350 if (slideControlIndex !== -1) { 1351 var ariaButtonControl = 1352 "slick-slide-control" + _.instanceUid + slideControlIndex; 1353 if ($("#" + ariaButtonControl).length) { 1354 $(this).attr({ 1355 "aria-describedby": ariaButtonControl, 1356 }); 1357 } 1358 } 1359 }); 1360 1361 _.$dots 1362 .attr("role", "tablist") 1363 .find("li") 1364 .each(function (i) { 1365 var mappedSlideIndex = tabControlIndexes[i]; 1366 1367 $(this).attr({ 1368 role: "presentation", 1369 }); 1370 1371 $(this) 1372 .find("button") 1373 .first() 1374 .attr({ 1375 role: "tab", 1376 id: "slick-slide-control" + _.instanceUid + i, 1377 "aria-controls": "slick-slide" + _.instanceUid + mappedSlideIndex, 1378 "aria-label": i + 1 + " of " + numDotGroups, 1379 "aria-selected": null, 1380 tabindex: "-1", 1381 }); 1382 }) 1383 .eq(_.currentSlide) 1384 .find("button") 1385 .attr({ 1386 "aria-selected": "true", 1387 tabindex: "0", 1388 }) 1389 .end(); 1390 } 1391 1392 for ( 1393 var i = _.currentSlide, max = i + _.options.slidesToShow; 1394 i < max; 1395 i++ 1396 ) { 1397 if (_.options.focusOnChange) { 1398 _.$slides.eq(i).attr({ tabindex: "0" }); 1399 } else { 1400 _.$slides.eq(i).removeAttr("tabindex"); 1401 } 1402 } 1403 1404 _.activateADA(); 1405 }; 1406 1407 Slick.prototype.initArrowEvents = function () { 1408 var _ = this; 1409 1410 if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) { 1411 _.$prevArrow.off("click.slick").on( 1412 "click.slick", 1413 { 1414 message: "previous", 1415 }, 1416 _.changeSlide 1417 ); 1418 _.$nextArrow.off("click.slick").on( 1419 "click.slick", 1420 { 1421 message: "next", 1422 }, 1423 _.changeSlide 1424 ); 1425 1426 if (_.options.accessibility === true) { 1427 _.$prevArrow.on("keydown.slick", _.keyHandler); 1428 _.$nextArrow.on("keydown.slick", _.keyHandler); 1429 } 1430 } 1431 }; 1432 1433 Slick.prototype.initDotEvents = function () { 1434 var _ = this; 1435 1436 if (_.options.dots === true && _.slideCount > _.options.slidesToShow) { 1437 $("li", _.$dots).on( 1438 "click.slick", 1439 { 1440 message: "index", 1441 }, 1442 _.changeSlide 1443 ); 1444 1445 if (_.options.accessibility === true) { 1446 _.$dots.on("keydown.slick", _.keyHandler); 1447 } 1448 } 1449 1450 if (
1451 _.options.dots === true && 1452 _.options.pauseOnDotsHover === true && 1453 _.slideCount > _.options.slidesToShow 1454 ) { 1455 $("li", _.$dots) 1456 .on("mouseenter.slick", $.proxy(_.interrupt, _, true)) 1457 .on("mouseleave.slick", $.proxy(_.interrupt, _, false)); 1458 } 1459 }; 1460 1461 Slick.prototype.initSlideEvents = function () { 1462 var _ = this; 1463 1464 if (_.options.pauseOnHover) { 1465 _.$list.on("mouseenter.slick", $.proxy(_.interrupt, _, true)); 1466 _.$list.on("mouseleave.slick", $.proxy(_.interrupt, _, false)); 1467 } 1468 }; 1469 1470 Slick.prototype.initializeEvents = function () { 1471 var _ = this; 1472 1473 _.initArrowEvents(); 1474 1475 _.initDotEvents(); 1476 _.initSlideEvents(); 1477 1478 _.$list.on( 1479 "touchstart.slick mousedown.slick", 1480 { 1481 action: "start", 1482 }, 1483 _.swipeHandler 1484 ); 1485 _.$list.on( 1486 "touchmove.slick mousemove.slick", 1487 { 1488 action: "move", 1489 }, 1490 _.swipeHandler 1491 ); 1492 _.$list.on( 1493 "touchend.slick mouseup.slick", 1494 { 1495 action: "end", 1496 }, 1497 _.swipeHandler 1498 ); 1499 _.$list.on(
vendor: 34,710 bytes, lines 1500-2815
1500 "touchcancel.slick mouseleave.slick", 1501 { 1502 action: "end", 1503 }, 1504 _.swipeHandler 1505 ); 1506 1507 _.$list.on("click.slick", _.clickHandler); 1508 1509 $(document).on(_.visibilityChange, $.proxy(_.visibility, _)); 1510 1511 if (_.options.accessibility === true) { 1512 _.$list.on("keydown.slick", _.keyHandler); 1513 } 1514 1515 if (_.options.focusOnSelect === true) { 1516 $(_.$slideTrack).children().on("click.slick", _.selectHandler); 1517 } 1518 1519 $(window).on( 1520 "orientationchange.slick.slick-" + _.instanceUid, 1521 $.proxy(_.orientationChange, _) 1522 ); 1523 1524 $(window).on("resize.slick.slick-" + _.instanceUid, $.proxy(_.resize, _)); 1525 1526 $("[draggable!=true]", _.$slideTrack).on("dragstart", _.preventDefault); 1527 1528 $(window).on("load.slick.slick-" + _.instanceUid, _.setPosition); 1529 $(_.setPosition); 1530 }; 1531 1532 Slick.prototype.initUI = function () { 1533 var _ = this; 1534 1535 if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) { 1536 _.$prevArrow.show(); 1537 _.$nextArrow.show(); 1538 } 1539 1540 if (_.options.dots === true && _.slideCount > _.options.slidesToShow) { 1541 _.$dots.show(); 1542 } 1543 }; 1544 1545 Slick.prototype.keyHandler = function (event) { 1546 var _ = this; 1547 //Dont slide if the cursor is inside the form fields and arrow keys are pressed 1548 if (!event.target.tagName.match("TEXTAREA|INPUT|SELECT")) { 1549 if (event.keyCode === 37 && _.options.accessibility === true) { 1550 _.changeSlide({ 1551 data: { 1552 message: _.options.rtl === true ? "next" : "previous", 1553 }, 1554 }); 1555 } else if (event.keyCode === 39 && _.options.accessibility === true) { 1556 _.changeSlide({ 1557 data: { 1558 message: _.options.rtl === true ? "previous" : "next", 1559 }, 1560 }); 1561 } 1562 } 1563 }; 1564 1565 Slick.prototype.lazyLoad = function () { 1566 var _ = this, 1567 loadRange, 1568 cloneRange, 1569 rangeStart, 1570 rangeEnd; 1571 1572 function loadImages(imagesScope) { 1573 $("img[data-lazy]", imagesScope).each(function () { 1574 var image = $(this), 1575 imageSource = $(this).attr("data-lazy"), 1576 imageSrcSet = $(this).attr("data-srcset"), 1577 imageSizes = 1578 $(this).attr("data-sizes") || _.$slider.attr("data-sizes"), 1579 imageToLoad = document.createElement("img"); 1580 1581 imageToLoad.onload = function () { 1582 image.animate({ opacity: 0 }, 100, function () { 1583 if (imageSrcSet) { 1584 image.attr("srcset", imageSrcSet); 1585 1586 if (imageSizes) { 1587 image.attr("sizes", imageSizes); 1588 } 1589 } 1590 1591 image 1592 .attr("src", imageSource) 1593 .animate({ opacity: 1 }, 200, function () { 1594 image 1595 .removeAttr("data-lazy data-srcset data-sizes") 1596 .removeClass("slick-loading"); 1597 }); 1598 _.$slider.trigger("lazyLoaded", [_, image, imageSource]); 1599 }); 1600 }; 1601 1602 imageToLoad.onerror = function () { 1603 image 1604 .removeAttr("data-lazy") 1605 .removeClass("slick-loading") 1606 .addClass("slick-lazyload-error"); 1607 1608 _.$slider.trigger("lazyLoadError", [_, image, imageSource]); 1609 }; 1610 1611 imageToLoad.src = imageSource; 1612 }); 1613 } 1614 1615 if (_.options.centerMode === true) { 1616 if (_.options.infinite === true) { 1617 rangeStart = _.currentSlide + (_.options.slidesToShow / 2 + 1); 1618 rangeEnd = rangeStart + _.options.slidesToShow + 2; 1619 } else { 1620 rangeStart = Math.max( 1621 0, 1622 _.currentSlide - (_.options.slidesToShow / 2 + 1) 1623 ); 1624 rangeEnd = 2 + (_.options.slidesToShow / 2 + 1) + _.currentSlide; 1625 } 1626 } else { 1627 rangeStart = _.options.infinite 1628 ? _.options.slidesToShow + _.currentSlide 1629 : _.currentSlide; 1630 rangeEnd = Math.ceil(rangeStart + _.options.slidesToShow); 1631 if (_.options.fade === true) { 1632 if (rangeStart > 0) rangeStart--; 1633 if (rangeEnd <= _.slideCount) rangeEnd++; 1634 } 1635 } 1636 1637 loadRange = _.$slider.find(".slick-slide").slice(rangeStart, rangeEnd); 1638 1639 if (_.options.lazyLoad === "anticipated") { 1640 var prevSlide = rangeStart - 1, 1641 nextSlide = rangeEnd, 1642 $slides = _.$slider.find(".slick-slide"); 1643 1644 for (var i = 0; i < _.options.slidesToScroll; i++) { 1645 if (prevSlide < 0) prevSlide = _.slideCount - 1; 1646 loadRange = loadRange.add($slides.eq(prevSlide)); 1647 loadRange = loadRange.add($slides.eq(nextSlide)); 1648 prevSlide--; 1649 nextSlide++; 1650 } 1651 } 1652 1653 loadImages(loadRange); 1654 1655 if (_.slideCount <= _.options.slidesToShow) { 1656 cloneRange = _.$slider.find(".slick-slide"); 1657 loadImages(cloneRange); 1658 } else if (_.currentSlide >= _.slideCount - _.options.slidesToShow) { 1659 cloneRange = _.$slider 1660 .find(".slick-cloned") 1661 .slice(0, _.options.slidesToShow); 1662 loadImages(cloneRange); 1663 } else if (_.currentSlide === 0) { 1664 cloneRange = _.$slider 1665 .find(".slick-cloned") 1666 .slice(_.options.slidesToShow * -1); 1667 loadImages(cloneRange); 1668 } 1669 }; 1670 1671 Slick.prototype.loadSlider = function () { 1672 var _ = this; 1673 1674 _.setPosition(); 1675 1676 _.$slideTrack.css({ 1677 opacity: 1, 1678 }); 1679 1680 _.$slider.removeClass("slick-loading"); 1681 1682 _.initUI(); 1683 1684 if (_.options.lazyLoad === "progressive") { 1685 _.progressiveLazyLoad(); 1686 } 1687 }; 1688 1689 Slick.prototype.next = Slick.prototype.slickNext = function () { 1690 var _ = this; 1691 1692 _.changeSlide({ 1693 data: { 1694 message: "next", 1695 }, 1696 }); 1697 }; 1698 1699 Slick.prototype.orientationChange = function () { 1700 var _ = this; 1701 1702 _.checkResponsive(); 1703 _.setPosition(); 1704 }; 1705 1706 Slick.prototype.pause = Slick.prototype.slickPause = function () { 1707 var _ = this; 1708 1709 _.autoPlayClear(); 1710 _.paused = true; 1711 }; 1712 1713 Slick.prototype.play = Slick.prototype.slickPlay = function () { 1714 var _ = this; 1715 1716 _.autoPlay(); 1717 _.options.autoplay = true; 1718 _.paused = false; 1719 _.focussed = false; 1720 _.interrupted = false; 1721 }; 1722 1723 Slick.prototype.postSlide = function (index) { 1724 var _ = this; 1725 1726 if (!_.unslicked) { 1727 _.$slider.trigger("afterChange", [_, index]); 1728 1729 _.animating = false; 1730 1731 if (_.slideCount > _.options.slidesToShow) { 1732 _.setPosition(); 1733 } 1734 1735 _.swipeLeft = null; 1736 1737 if (_.options.autoplay) { 1738 _.autoPlay(); 1739 } 1740 1741 if (_.options.accessibility === true) { 1742 _.initADA(); 1743 1744 if (_.options.focusOnChange) { 1745 var $currentSlide = $(_.$slides.get(_.currentSlide)); 1746 $currentSlide.attr("tabindex", 0).focus(); 1747 } 1748 } 1749 } 1750 }; 1751 1752 Slick.prototype.prev = Slick.prototype.slickPrev = function () { 1753 var _ = this; 1754 1755 _.changeSlide({ 1756 data: { 1757 message: "previous", 1758 }, 1759 }); 1760 }; 1761 1762 Slick.prototype.preventDefault = function (event) { 1763 event.preventDefault(); 1764 }; 1765 1766 Slick.prototype.progressiveLazyLoad = function (tryCount) { 1767 tryCount = tryCount || 1; 1768 1769 var _ = this, 1770 $imgsToLoad = $("img[data-lazy]", _.$slider), 1771 image, 1772 imageSource, 1773 imageSrcSet, 1774 imageSizes, 1775 imageToLoad; 1776 1777 if ($imgsToLoad.length) { 1778 image = $imgsToLoad.first(); 1779 imageSource = image.attr("data-lazy"); 1780 imageSrcSet = image.attr("data-srcset"); 1781 imageSizes = image.attr("data-sizes") || _.$slider.attr("data-sizes"); 1782 imageToLoad = document.createElement("img"); 1783 1784 imageToLoad.onload = function () { 1785 if (imageSrcSet) { 1786 image.attr("srcset", imageSrcSet); 1787 1788 if (imageSizes) { 1789 image.attr("sizes", imageSizes); 1790 } 1791 } 1792 1793 image 1794 .attr("src", imageSource) 1795 .removeAttr("data-lazy data-srcset data-sizes") 1796 .removeClass("slick-loading"); 1797 1798 if (_.options.adaptiveHeight === true) { 1799 _.setPosition(); 1800 } 1801 1802 _.$slider.trigger("lazyLoaded", [_, image, imageSource]); 1803 _.progressiveLazyLoad(); 1804 }; 1805 1806 imageToLoad.onerror = function () { 1807 if (tryCount < 3) { 1808 /** 1809 * try to load the image 3 times, 1810 * leave a slight delay so we don't get 1811 * servers blocking the request. 1812 */ 1813 setTimeout(function () { 1814 _.progressiveLazyLoad(tryCount + 1); 1815 }, 500); 1816 } else { 1817 image 1818 .removeAttr("data-lazy") 1819 .removeClass("slick-loading") 1820 .addClass("slick-lazyload-error"); 1821 1822 _.$slider.trigger("lazyLoadError", [_, image, imageSource]); 1823 1824 _.progressiveLazyLoad(); 1825 } 1826 }; 1827 1828 imageToLoad.src = imageSource; 1829 } else { 1830 _.$slider.trigger("allImagesLoaded", [_]); 1831 } 1832 }; 1833 1834 Slick.prototype.refresh = function (initializing) { 1835 var _ = this, 1836 currentSlide, 1837 lastVisibleIndex; 1838 1839 lastVisibleIndex = _.slideCount - _.options.slidesToShow; 1840 1841 // in non-infinite sliders, we don't want to go past the 1842 // last visible index. 1843 if (!_.options.infinite && _.currentSlide > lastVisibleIndex) { 1844 _.currentSlide = lastVisibleIndex; 1845 } 1846 1847 // if less slides than to show, go to start. 1848 if (_.slideCount <= _.options.slidesToShow) { 1849 _.currentSlide = 0; 1850 } 1851 1852 currentSlide = _.currentSlide; 1853 1854 _.destroy(true); 1855 1856 $.extend(_, _.initials, { currentSlide: currentSlide }); 1857 1858 _.init(); 1859 1860 if (!initializing) { 1861 _.changeSlide( 1862 { 1863 data: { 1864 message: "index", 1865 index: currentSlide, 1866 }, 1867 }, 1868 false 1869 ); 1870 } 1871 }; 1872 1873 Slick.prototype.registerBreakpoints = function () { 1874 var _ = this, 1875 breakpoint, 1876 currentBreakpoint, 1877 l, 1878 responsiveSettings = _.options.responsive || null; 1879 1880 if ($.type(responsiveSettings) === "array" && responsiveSettings.length) { 1881 _.respondTo = _.options.respondTo || "window"; 1882 1883 for (breakpoint in responsiveSettings) { 1884 l = _.breakpoints.length - 1; 1885 1886 if (responsiveSettings.hasOwnProperty(breakpoint)) { 1887 currentBreakpoint = responsiveSettings[breakpoint].breakpoint; 1888 1889 // loop through the breakpoints and cut out any existing 1890 // ones with the same breakpoint number, we don't want dupes. 1891 while (l >= 0) { 1892 if (_.breakpoints[l] && _.breakpoints[l] === currentBreakpoint) { 1893 _.breakpoints.splice(l, 1); 1894 } 1895 l--; 1896 } 1897 1898 _.breakpoints.push(currentBreakpoint); 1899 _.breakpointSettings[currentBreakpoint] = 1900 responsiveSettings[breakpoint].settings; 1901 } 1902 } 1903 1904 _.breakpoints.sort(function (a, b) { 1905 return _.options.mobileFirst ? a - b : b - a; 1906 }); 1907 } 1908 }; 1909 1910 Slick.prototype.reinit = function () { 1911 var _ = this; 1912 1913 _.$slides = _.$slideTrack.children(_.options.slide).addClass("slick-slide"); 1914 1915 _.slideCount = _.$slides.length; 1916 1917 if (_.currentSlide >= _.slideCount && _.currentSlide !== 0) { 1918 _.currentSlide = _.currentSlide - _.options.slidesToScroll; 1919 } 1920 1921 if (_.slideCount <= _.options.slidesToShow) { 1922 _.currentSlide = 0; 1923 } 1924 1925 _.registerBreakpoints(); 1926 1927 _.setProps(); 1928 _.setupInfinite(); 1929 _.buildArrows(); 1930 _.updateArrows(); 1931 _.initArrowEvents(); 1932 _.buildDots(); 1933 _.updateDots(); 1934 _.initDotEvents(); 1935 _.cleanUpSlideEvents(); 1936 _.initSlideEvents(); 1937 1938 _.checkResponsive(false, true); 1939 1940 if (_.options.focusOnSelect === true) { 1941 $(_.$slideTrack).children().on("click.slick", _.selectHandler); 1942 } 1943 1944 _.setSlideClasses(typeof _.currentSlide === "number" ? _.currentSlide : 0); 1945 1946 _.setPosition(); 1947 _.focusHandler(); 1948 1949 _.paused = !_.options.autoplay; 1950 _.autoPlay(); 1951 1952 _.$slider.trigger("reInit", [_]); 1953 }; 1954 1955 Slick.prototype.resize = function () { 1956 var _ = this; 1957 1958 if ($(window).width() !== _.windowWidth) { 1959 clearTimeout(_.windowDelay); 1960 _.windowDelay = window.setTimeout(function () { 1961 _.windowWidth = $(window).width(); 1962 _.checkResponsive(); 1963 if (!_.unslicked) { 1964 _.setPosition(); 1965 } 1966 }, 50); 1967 } 1968 }; 1969 1970 Slick.prototype.removeSlide = Slick.prototype.slickRemove = function ( 1971 index, 1972 removeBefore, 1973 removeAll 1974 ) { 1975 var _ = this; 1976 1977 if (typeof index === "boolean") { 1978 removeBefore = index; 1979 index = removeBefore === true ? 0 : _.slideCount - 1; 1980 } else { 1981 index = removeBefore === true ? --index : index; 1982 } 1983 1984 if (_.slideCount < 1 || index < 0 || index > _.slideCount - 1) { 1985 return false; 1986 } 1987 1988 _.unload(); 1989 1990 if (removeAll === true) { 1991 _.$slideTrack.children().remove(); 1992 } else { 1993 _.$slideTrack.children(this.options.slide).eq(index).remove(); 1994 } 1995 1996 _.$slides = _.$slideTrack.children(this.options.slide); 1997 1998 _.$slideTrack.children(this.options.slide).detach(); 1999 2000 _.$slideTrack.append(_.$slides); 2001 2002 _.$slidesCache = _.$slides; 2003 2004 _.reinit(); 2005 }; 2006 2007 Slick.prototype.setCSS = function (position) { 2008 var _ = this, 2009 positionProps = {}, 2010 x, 2011 y; 2012 2013 if (_.options.rtl === true) { 2014 position = -position; 2015 } 2016 x = _.positionProp == "left" ? Math.ceil(position) + "px" : "0px"; 2017 y = _.positionProp == "top" ? Math.ceil(position) + "px" : "0px"; 2018 2019 positionProps[_.positionProp] = position; 2020 2021 if (_.transformsEnabled === false) { 2022 _.$slideTrack.css(positionProps); 2023 } else { 2024 positionProps = {}; 2025 if (_.cssTransitions === false) { 2026 positionProps[_.animType] = "translate(" + x + ", " + y + ")"; 2027 _.$slideTrack.css(positionProps); 2028 } else { 2029 positionProps[_.animType] = "translate3d(" + x + ", " + y + ", 0px)"; 2030 _.$slideTrack.css(positionProps); 2031 } 2032 } 2033 }; 2034 2035 Slick.prototype.setDimensions = function () { 2036 var _ = this; 2037 2038 if (_.options.vertical === false) { 2039 if (_.options.centerMode === true) { 2040 _.$list.css({ 2041 padding: "0px " + _.options.centerPadding, 2042 }); 2043 } 2044 } else { 2045 _.$list.height( 2046 _.$slides.first().outerHeight(true) * _.options.slidesToShow 2047 ); 2048 if (_.options.centerMode === true) { 2049 _.$list.css({ 2050 padding: _.options.centerPadding + " 0px", 2051 }); 2052 } 2053 } 2054 2055 _.listWidth = _.$list.width(); 2056 _.listHeight = _.$list.height(); 2057 2058 if (_.options.vertical === false && _.options.variableWidth === false) { 2059 _.slideWidth = Math.ceil(_.listWidth / _.options.slidesToShow); 2060 _.$slideTrack.width( 2061 Math.ceil(_.slideWidth * _.$slideTrack.children(".slick-slide").length) 2062 ); 2063 } else if (_.options.variableWidth === true) { 2064 _.$slideTrack.width(5000 * _.slideCount); 2065 } else { 2066 _.slideWidth = Math.ceil(_.listWidth); 2067 _.$slideTrack.height( 2068 Math.ceil( 2069 _.$slides.first().outerHeight(true) * 2070 _.$slideTrack.children(".slick-slide").length 2071 ) 2072 ); 2073 } 2074 2075 var offset = _.$slides.first().outerWidth(true) - _.$slides.first().width(); 2076 if (_.options.variableWidth === false) 2077 _.$slideTrack.children(".slick-slide").width(_.slideWidth - offset); 2078 }; 2079 2080 Slick.prototype.setFade = function () { 2081 var _ = this, 2082 targetLeft; 2083 2084 _.$slides.each(function (index, element) { 2085 targetLeft = _.slideWidth * index * -1; 2086 if (_.options.rtl === true) { 2087 $(element).css({ 2088 position: "relative", 2089 right: targetLeft, 2090 top: 0, 2091 zIndex: _.options.zIndex - 2, 2092 opacity: 0, 2093 }); 2094 } else { 2095 $(element).css({ 2096 position: "relative", 2097 left: targetLeft, 2098 top: 0, 2099 zIndex: _.options.zIndex - 2, 2100 opacity: 0, 2101 }); 2102 } 2103 }); 2104 2105 _.$slides.eq(_.currentSlide).css({ 2106 zIndex: _.options.zIndex - 1, 2107 opacity: 1, 2108 }); 2109 }; 2110 2111 Slick.prototype.setHeight = function () { 2112 var _ = this; 2113 2114 if ( 2115 _.options.slidesToShow === 1 && 2116 _.options.adaptiveHeight === true && 2117 _.options.vertical === false 2118 ) { 2119 var targetHeight = _.$slides.eq(_.currentSlide).outerHeight(true); 2120 _.$list.css("height", targetHeight); 2121 } 2122 }; 2123 2124 Slick.prototype.setOption = Slick.prototype.slickSetOption = function () { 2125 /** 2126 * accepts arguments in format of: 2127 * 2128 * - for changing a single option's value: 2129 * .slick("setOption", option, value, refresh ) 2130 * 2131 * - for changing a set of responsive options: 2132 * .slick("setOption", 'responsive', [{}, ...], refresh ) 2133 * 2134 * - for updating multiple values at once (not responsive) 2135 * .slick("setOption", { 'option': value, ... }, refresh ) 2136 */ 2137 2138 var _ = this, 2139 l, 2140 item, 2141 option, 2142 value, 2143 refresh = false, 2144 type; 2145 2146 if ($.type(arguments[0]) === "object") { 2147 option = arguments[0]; 2148 refresh = arguments[1]; 2149 type = "multiple"; 2150 } else if ($.type(arguments[0]) === "string") { 2151 option = arguments[0]; 2152 value = arguments[1]; 2153 refresh = arguments[2]; 2154 2155 if (arguments[0] === "responsive" && $.type(arguments[1]) === "array") { 2156 type = "responsive"; 2157 } else if (typeof arguments[1] !== "undefined") { 2158 type = "single"; 2159 } 2160 } 2161 2162 if (type === "single") { 2163 _.options[option] = value; 2164 } else if (type === "multiple") { 2165 $.each(option, function (opt, val) { 2166 _.options[opt] = val; 2167 }); 2168 } else if (type === "responsive") { 2169 for (item in value) { 2170 if ($.type(_.options.responsive) !== "array") { 2171 _.options.responsive = [value[item]]; 2172 } else { 2173 l = _.options.responsive.length - 1; 2174 2175 // loop through the responsive object and splice out duplicates. 2176 while (l >= 0) { 2177 if (_.options.responsive[l].breakpoint === value[item].breakpoint) { 2178 _.options.responsive.splice(l, 1); 2179 } 2180 2181 l--; 2182 } 2183 2184 _.options.responsive.push(value[item]); 2185 } 2186 } 2187 } 2188 2189 if (refresh) { 2190 _.unload(); 2191 _.reinit(); 2192 } 2193 }; 2194 2195 Slick.prototype.setPosition = function () { 2196 var _ = this; 2197 2198 _.setDimensions(); 2199 2200 _.setHeight(); 2201 2202 if (_.options.fade === false) { 2203 _.setCSS(_.getLeft(_.currentSlide)); 2204 } else { 2205 _.setFade(); 2206 } 2207 2208 _.$slider.trigger("setPosition", [_]); 2209 }; 2210 2211 Slick.prototype.setProps = function () { 2212 var _ = this, 2213 bodyStyle = document.body.style; 2214 2215 _.positionProp = _.options.vertical === true ? "top" : "left"; 2216 2217 if (_.positionProp === "top") { 2218 _.$slider.addClass("slick-vertical"); 2219 } else { 2220 _.$slider.removeClass("slick-vertical"); 2221 } 2222 2223 if ( 2224 bodyStyle.WebkitTransition !== undefined || 2225 bodyStyle.MozTransition !== undefined || 2226 bodyStyle.msTransition !== undefined 2227 ) { 2228 if (_.options.useCSS === true) { 2229 _.cssTransitions = true; 2230 } 2231 } 2232 2233 if (_.options.fade) { 2234 if (typeof _.options.zIndex === "number") { 2235 if (_.options.zIndex < 3) { 2236 _.options.zIndex = 3; 2237 } 2238 } else { 2239 _.options.zIndex = _.defaults.zIndex; 2240 } 2241 } 2242 2243 if (bodyStyle.OTransform !== undefined) { 2244 _.animType = "OTransform"; 2245 _.transformType = "-o-transform"; 2246 _.transitionType = "OTransition"; 2247 if ( 2248 bodyStyle.perspectiveProperty === undefined && 2249 bodyStyle.webkitPerspective === undefined 2250 ) 2251 _.animType = false; 2252 } 2253 if (bodyStyle.MozTransform !== undefined) { 2254 _.animType = "MozTransform"; 2255 _.transformType = "-moz-transform"; 2256 _.transitionType = "MozTransition"; 2257 if ( 2258 bodyStyle.perspectiveProperty === undefined && 2259 bodyStyle.MozPerspective === undefined 2260 ) 2261 _.animType = false; 2262 } 2263 if (bodyStyle.webkitTransform !== undefined) { 2264 _.animType = "webkitTransform"; 2265 _.transformType = "-webkit-transform"; 2266 _.transitionType = "webkitTransition"; 2267 if ( 2268 bodyStyle.perspectiveProperty === undefined && 2269 bodyStyle.webkitPerspective === undefined 2270 ) 2271 _.animType = false; 2272 } 2273 if (bodyStyle.msTransform !== undefined) { 2274 _.animType = "msTransform"; 2275 _.transformType = "-ms-transform"; 2276 _.transitionType = "msTransition"; 2277 if (bodyStyle.msTransform === undefined) _.animType = false; 2278 } 2279 if (bodyStyle.transform !== undefined && _.animType !== false) { 2280 _.animType = "transform"; 2281 _.transformType = "transform"; 2282 _.transitionType = "transition"; 2283 } 2284 _.transformsEnabled = 2285 _.options.useTransform && _.animType !== null && _.animType !== false; 2286 }; 2287 2288 Slick.prototype.setSlideClasses = function (index) { 2289 var _ = this, 2290 centerOffset, 2291 allSlides, 2292 indexOffset, 2293 remainder; 2294 2295 allSlides = _.$slider 2296 .find(".slick-slide") 2297 .removeClass("slick-active slick-center slick-current") 2298 .attr("aria-hidden", "true"); 2299 2300 _.$slides.eq(index).addClass("slick-current"); 2301 2302 if (_.options.centerMode === true) { 2303 var evenCoef = _.options.slidesToShow % 2 === 0 ? 1 : 0; 2304 2305 centerOffset = Math.floor(_.options.slidesToShow / 2); 2306 2307 if (_.options.infinite === true) { 2308 if (index >= centerOffset && index <= _.slideCount - 1 - centerOffset) { 2309 _.$slides 2310 .slice(index - centerOffset + evenCoef, index + centerOffset + 1) 2311 .addClass("slick-active") 2312 .attr("aria-hidden", "false"); 2313 } else { 2314 indexOffset = _.options.slidesToShow + index; 2315 allSlides 2316 .slice( 2317 indexOffset - centerOffset + 1 + evenCoef, 2318 indexOffset + centerOffset + 2 2319 ) 2320 .addClass("slick-active") 2321 .attr("aria-hidden", "false"); 2322 } 2323 2324 if (index === 0) { 2325 allSlides 2326 .eq(allSlides.length - 1 - _.options.slidesToShow) 2327 .addClass("slick-center"); 2328 } else if (index === _.slideCount - 1) { 2329 allSlides.eq(_.options.slidesToShow).addClass("slick-center"); 2330 } 2331 } 2332 2333 _.$slides.eq(index).addClass("slick-center"); 2334 } else { 2335 if (index >= 0 && index <= _.slideCount - _.options.slidesToShow) { 2336 _.$slides 2337 .slice(index, index + _.options.slidesToShow) 2338 .addClass("slick-active") 2339 .attr("aria-hidden", "false"); 2340 } else if (allSlides.length <= _.options.slidesToShow) { 2341 allSlides.addClass("slick-active").attr("aria-hidden", "false"); 2342 } else { 2343 remainder = _.slideCount % _.options.slidesToShow; 2344 indexOffset = 2345 _.options.infinite === true ? _.options.slidesToShow + index : index; 2346 2347 if ( 2348 _.options.slidesToShow == _.options.slidesToScroll && 2349 _.slideCount - index < _.options.slidesToShow 2350 ) { 2351 allSlides 2352 .slice( 2353 indexOffset - (_.options.slidesToShow - remainder), 2354 indexOffset + remainder 2355 ) 2356 .addClass("slick-active") 2357 .attr("aria-hidden", "false"); 2358 } else { 2359 allSlides 2360 .slice(indexOffset, indexOffset + _.options.slidesToShow) 2361 .addClass("slick-active") 2362 .attr("aria-hidden", "false"); 2363 } 2364 } 2365 } 2366 2367 if ( 2368 _.options.lazyLoad === "ondemand" || 2369 _.options.lazyLoad === "anticipated" 2370 ) { 2371 _.lazyLoad(); 2372 } 2373 }; 2374 2375 Slick.prototype.setupInfinite = function () { 2376 var _ = this, 2377 i, 2378 slideIndex, 2379 infiniteCount; 2380 2381 if (_.options.fade === true) { 2382 _.options.centerMode = false; 2383 } 2384 2385 if (_.options.infinite === true && _.options.fade === false) { 2386 slideIndex = null; 2387 2388 if (_.slideCount > _.options.slidesToShow) { 2389 if (_.options.centerMode === true) { 2390 infiniteCount = _.options.slidesToShow + 1; 2391 } else { 2392 infiniteCount = _.options.slidesToShow; 2393 } 2394 2395 for (i = _.slideCount; i > _.slideCount - infiniteCount; i -= 1) { 2396 slideIndex = i - 1; 2397 $(_.$slides[slideIndex]) 2398 .clone(true) 2399 .attr("id", "") 2400 .attr("data-slick-index", slideIndex - _.slideCount) 2401 .prependTo(_.$slideTrack) 2402 .addClass("slick-cloned"); 2403 } 2404 for (i = 0; i < infiniteCount + _.slideCount; i += 1) { 2405 slideIndex = i; 2406 $(_.$slides[slideIndex]) 2407 .clone(true) 2408 .attr("id", "") 2409 .attr("data-slick-index", slideIndex + _.slideCount) 2410 .appendTo(_.$slideTrack) 2411 .addClass("slick-cloned"); 2412 } 2413 _.$slideTrack 2414 .find(".slick-cloned") 2415 .find("[id]") 2416 .each(function () { 2417 $(this).attr("id", ""); 2418 }); 2419 } 2420 } 2421 }; 2422 2423 Slick.prototype.interrupt = function (toggle) { 2424 var _ = this; 2425 2426 if (!toggle) { 2427 _.autoPlay(); 2428 } 2429 _.interrupted = toggle; 2430 }; 2431 2432 Slick.prototype.selectHandler = function (event) { 2433 var _ = this; 2434 2435 var targetElement = $(event.target).is(".slick-slide") 2436 ? $(event.target) 2437 : $(event.target).parents(".slick-slide"); 2438 2439 var index = parseInt(targetElement.attr("data-slick-index")); 2440 2441 if (!index) index = 0; 2442 2443 if (_.slideCount <= _.options.slidesToShow) { 2444 _.slideHandler(index, false, true); 2445 return; 2446 } 2447 2448 _.slideHandler(index); 2449 }; 2450 2451 Slick.prototype.slideHandler = function (index, sync, dontAnimate) { 2452 var targetSlide, 2453 animSlide, 2454 oldSlide, 2455 slideLeft, 2456 targetLeft = null, 2457 _ = this, 2458 navTarget; 2459 2460 sync = sync || false; 2461 2462 if (_.animating === true && _.options.waitForAnimate === true) { 2463 return; 2464 } 2465 2466 if (_.options.fade === true && _.currentSlide === index) { 2467 return; 2468 } 2469 2470 if (sync === false) { 2471 _.asNavFor(index); 2472 } 2473 2474 targetSlide = index; 2475 targetLeft = _.getLeft(targetSlide); 2476 slideLeft = _.getLeft(_.currentSlide); 2477 2478 _.currentLeft = _.swipeLeft === null ? slideLeft : _.swipeLeft; 2479 2480 if ( 2481 _.options.infinite === false && 2482 _.options.centerMode === false && 2483 (index < 0 || index > _.getDotCount() * _.options.slidesToScroll) 2484 ) { 2485 if (_.options.fade === false) { 2486 targetSlide = _.currentSlide; 2487 if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) { 2488 _.animateSlide(slideLeft, function () { 2489 _.postSlide(targetSlide); 2490 }); 2491 } else { 2492 _.postSlide(targetSlide); 2493 } 2494 } 2495 return; 2496 } else if ( 2497 _.options.infinite === false && 2498 _.options.centerMode === true && 2499 (index < 0 || index > _.slideCount - _.options.slidesToScroll) 2500 ) { 2501 if (_.options.fade === false) { 2502 targetSlide = _.currentSlide; 2503 if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) { 2504 _.animateSlide(slideLeft, function () { 2505 _.postSlide(targetSlide); 2506 }); 2507 } else { 2508 _.postSlide(targetSlide); 2509 } 2510 } 2511 return; 2512 } 2513 2514 if (_.options.autoplay) { 2515 clearInterval(_.autoPlayTimer); 2516 } 2517 2518 if (targetSlide < 0) { 2519 if (_.slideCount % _.options.slidesToScroll !== 0) { 2520 animSlide = _.slideCount - (_.slideCount % _.options.slidesToScroll); 2521 } else { 2522 animSlide = _.slideCount + targetSlide; 2523 } 2524 } else if (targetSlide >= _.slideCount) { 2525 if (_.slideCount % _.options.slidesToScroll !== 0) { 2526 animSlide = 0; 2527 } else { 2528 animSlide = targetSlide - _.slideCount; 2529 } 2530 } else { 2531 animSlide = targetSlide; 2532 } 2533 2534 _.animating = true; 2535 2536 _.$slider.trigger("beforeChange", [_, _.currentSlide, animSlide]); 2537 2538 oldSlide = _.currentSlide; 2539 _.currentSlide = animSlide; 2540 2541 _.setSlideClasses(_.currentSlide); 2542 2543 if (_.options.asNavFor) { 2544 navTarget = _.getNavTarget(); 2545 navTarget = navTarget.slick("getSlick"); 2546 2547 if (navTarget.slideCount <= navTarget.options.slidesToShow) { 2548 navTarget.setSlideClasses(_.currentSlide); 2549 } 2550 } 2551 2552 _.updateDots(); 2553 _.updateArrows(); 2554 2555 if (_.options.fade === true) { 2556 if (dontAnimate !== true) { 2557 _.fadeSlideOut(oldSlide); 2558 2559 _.fadeSlide(animSlide, function () { 2560 _.postSlide(animSlide); 2561 }); 2562 } else { 2563 _.postSlide(animSlide); 2564 } 2565 _.animateHeight(); 2566 return; 2567 } 2568 2569 if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) { 2570 _.animateSlide(targetLeft, function () { 2571 _.postSlide(animSlide); 2572 }); 2573 } else { 2574 _.postSlide(animSlide); 2575 } 2576 }; 2577 2578 Slick.prototype.startLoad = function () { 2579 var _ = this; 2580 2581 if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) { 2582 _.$prevArrow.hide(); 2583 _.$nextArrow.hide(); 2584 } 2585 2586 if (_.options.dots === true && _.slideCount > _.options.slidesToShow) { 2587 _.$dots.hide(); 2588 } 2589 2590 _.$slider.addClass("slick-loading"); 2591 }; 2592 2593 Slick.prototype.swipeDirection = function () { 2594 var xDist, 2595 yDist, 2596 r, 2597 swipeAngle, 2598 _ = this; 2599 2600 xDist = _.touchObject.startX - _.touchObject.curX; 2601 yDist = _.touchObject.startY - _.touchObject.curY; 2602 r = Math.atan2(yDist, xDist); 2603 2604 swipeAngle = Math.round((r * 180) / Math.PI); 2605 if (swipeAngle < 0) { 2606 swipeAngle = 360 - Math.abs(swipeAngle); 2607 } 2608 2609 if (swipeAngle <= 45 && swipeAngle >= 0) { 2610 return _.options.rtl === false ? "left" : "right"; 2611 } 2612 if (swipeAngle <= 360 && swipeAngle >= 315) { 2613 return _.options.rtl === false ? "left" : "right"; 2614 } 2615 if (swipeAngle >= 135 && swipeAngle <= 225) { 2616 return _.options.rtl === false ? "right" : "left"; 2617 } 2618 if (_.options.verticalSwiping === true) { 2619 if (swipeAngle >= 35 && swipeAngle <= 135) { 2620 return "down"; 2621 } else { 2622 return "up"; 2623 } 2624 } 2625 2626 return "vertical"; 2627 }; 2628 2629 Slick.prototype.swipeEnd = function (event) { 2630 var _ = this, 2631 slideCount, 2632 direction; 2633 2634 _.dragging = false; 2635 _.swiping = false; 2636 2637 if (_.scrolling) { 2638 _.scrolling = false; 2639 return false; 2640 } 2641 2642 _.interrupted = false; 2643 _.shouldClick = _.touchObject.swipeLength > 10 ? false : true; 2644 2645 if (_.touchObject.curX === undefined) { 2646 return false; 2647 } 2648 2649 if (_.touchObject.edgeHit === true) { 2650 _.$slider.trigger("edge", [_, _.swipeDirection()]); 2651 } 2652 2653 if (_.touchObject.swipeLength >= _.touchObject.minSwipe) { 2654 direction = _.swipeDirection(); 2655 2656 switch (direction) { 2657 case "left": 2658 case "down": 2659 slideCount = _.options.swipeToSlide 2660 ? _.checkNavigable(_.currentSlide + _.getSlideCount()) 2661 : _.currentSlide + _.getSlideCount(); 2662 2663 _.currentDirection = 0; 2664 2665 break; 2666 2667 case "right": 2668 case "up": 2669 slideCount = _.options.swipeToSlide 2670 ? _.checkNavigable(_.currentSlide - _.getSlideCount()) 2671 : _.currentSlide - _.getSlideCount(); 2672 2673 _.currentDirection = 1; 2674 2675 break; 2676 2677 default: 2678 } 2679 2680 if (direction != "vertical") { 2681 _.slideHandler(slideCount); 2682 _.touchObject = {}; 2683 _.$slider.trigger("swipe", [_, direction]); 2684 } 2685 } else { 2686 if (_.touchObject.startX !== _.touchObject.curX) { 2687 _.slideHandler(_.currentSlide); 2688 _.touchObject = {}; 2689 } 2690 } 2691 }; 2692 2693 Slick.prototype.swipeHandler = function (event) { 2694 var _ = this; 2695 2696 if ( 2697 _.options.swipe === false || 2698 ("ontouchend" in document && _.options.swipe === false) 2699 ) { 2700 return; 2701 } else if ( 2702 _.options.draggable === false && 2703 event.type.indexOf("mouse") !== -1 2704 ) { 2705 return; 2706 } 2707 2708 _.touchObject.fingerCount = 2709 event.originalEvent && event.originalEvent.touches !== undefined 2710 ? event.originalEvent.touches.length 2711 : 1; 2712 2713 _.touchObject.minSwipe = _.listWidth / _.options.touchThreshold; 2714 2715 if (_.options.verticalSwiping === true) { 2716 _.touchObject.minSwipe = _.listHeight / _.options.touchThreshold; 2717 } 2718 2719 switch (event.data.action) { 2720 case "start": 2721 _.swipeStart(event); 2722 break; 2723 2724 case "move": 2725 _.swipeMove(event); 2726 break; 2727 2728 case "end": 2729 _.swipeEnd(event); 2730 break; 2731 } 2732 }; 2733 2734 Slick.prototype.swipeMove = function (event) { 2735 var _ = this, 2736 edgeWasHit = false, 2737 curLeft, 2738 swipeDirection, 2739 swipeLength, 2740 positionOffset, 2741 touches, 2742 verticalSwipeLength; 2743 2744 touches = 2745 event.originalEvent !== undefined ? event.originalEvent.touches : null; 2746 2747 if (!_.dragging || _.scrolling || (touches && touches.length !== 1)) { 2748 return false; 2749 } 2750 2751 curLeft = _.getLeft(_.currentSlide); 2752 2753 _.touchObject.curX = 2754 touches !== undefined ? touches[0].pageX : event.clientX; 2755 _.touchObject.curY = 2756 touches !== undefined ? touches[0].pageY : event.clientY; 2757 2758 _.touchObject.swipeLength = Math.round( 2759 Math.sqrt(Math.pow(_.touchObject.curX - _.touchObject.startX, 2)) 2760 ); 2761 2762 verticalSwipeLength = Math.round( 2763 Math.sqrt(Math.pow(_.touchObject.curY - _.touchObject.startY, 2)) 2764 ); 2765 2766 if (!_.options.verticalSwiping && !_.swiping && verticalSwipeLength > 4) { 2767 _.scrolling = true; 2768 return false; 2769 } 2770 2771 if (_.options.verticalSwiping === true) { 2772 _.touchObject.swipeLength = verticalSwipeLength; 2773 } 2774 2775 swipeDirection = _.swipeDirection(); 2776 2777 if (event.originalEvent !== undefined && _.touchObject.swipeLength > 4) { 2778 _.swiping = true; 2779 event.preventDefault(); 2780 } 2781 2782 positionOffset = 2783 (_.options.rtl === false ? 1 : -1) * 2784 (_.touchObject.curX > _.touchObject.startX ? 1 : -1); 2785 if (_.options.verticalSwiping === true) { 2786 positionOffset = _.touchObject.curY > _.touchObject.startY ? 1 : -1; 2787 } 2788 2789 swipeLength = _.touchObject.swipeLength; 2790 2791 _.touchObject.edgeHit = false; 2792 2793 if (_.options.infinite === false) { 2794 if ( 2795 (_.currentSlide === 0 && swipeDirection === "right") || 2796 (_.currentSlide >= _.getDotCount() && swipeDirection === "left") 2797 ) { 2798 swipeLength = _.touchObject.swipeLength * _.options.edgeFriction; 2799 _.touchObject.edgeHit = true; 2800 } 2801 } 2802 2803 if (_.options.vertical === false) { 2804 _.swipeLeft = curLeft + swipeLength * positionOffset; 2805 } else { 2806 _.swipeLeft = 2807 curLeft + 2808 swipeLength * (_.$list.height() / _.listWidth) * positionOffset; 2809 } 2810 if (_.options.verticalSwiping === true) { 2811 _.swipeLeft = curLeft + swipeLength * positionOffset; 2812 } 2813 2814 if (_.options.fade === true || _.options.touchMove === false) { 2815 return false;
2816 } 2817 2818 if (_.animating === true) { 2819 _.swipeLeft = null; 2820 return false; 2821 } 2822 2823 _.setCSS(_.swipeLeft); 2824 }; 2825 2826 Slick.prototype.swipeStart = function (event) { 2827 var _ = this, 2828 touches; 2829 2830 _.interrupted = true; 2831 2832 if ( 2833 _.touchObject.fingerCount !== 1 || 2834 _.slideCount <= _.options.slidesToShow 2835 ) { 2836 _.touchObject = {}; 2837 return false; 2838 } 2839 2840 if ( 2841 event.originalEvent !== undefined && 2842 event.originalEvent.touches !== undefined 2843 ) { 2844 touches = event.originalEvent.touches[0]; 2845 } 2846 2847 _.touchObject.startX = _.touchObject.curX = 2848 touches !== undefined ? touches.pageX : event.clientX; 2849 _.touchObject.startY = _.touchObject.curY = 2850 touches !== undefined ? touches.pageY : event.clientY; 2851 2852 _.dragging = true; 2853 }; 2854 2855 Slick.prototype.unfilterSlides = Slick.prototype.slickUnfilter = function () { 2856 var _ = this; 2857 2858 if (_.$slidesCache !== null) { 2859 _.unload(); 2860 2861 _.$slideTrack.children(this.options.slide).detach(); 2862 2863 _.$slidesCache.appendTo(_.$slideTrack); 2864 2865 _.reinit(); 2866 } 2867 }; 2868 2869 Slick.prototype.unload = function () { 2870 var _ = this; 2871 2872 $(".slick-cloned", _.$slider).remove(); 2873 2874 if (_.$dots) { 2875 _.$dots.remove(); 2876 } 2877 2878 if (_.$prevArrow && _.htmlExpr.test(_.options.prevArrow)) { 2879 _.$prevArrow.remove(); 2880 } 2881 2882 if (_.$nextArrow && _.htmlExpr.test(_.options.nextArrow)) { 2883 _.$nextArrow.remove(); 2884 } 2885 2886 _.$slides 2887 .removeClass("slick-slide slick-active slick-visible slick-current") 2888 .attr("aria-hidden", "true") 2889 .css("width", ""); 2890 }; 2891 2892 Slick.prototype.unslick = function (fromBreakpoint) { 2893 var _ = this; 2894 _.$slider.trigger("unslick", [_, fromBreakpoint]); 2895 _.destroy(); 2896 }; 2897 2898 Slick.prototype.updateArrows = function () { 2899 var _ = this, 2900 centerOffset; 2901 2902 centerOffset = Math.floor(_.options.slidesToShow / 2); 2903 2904 if ( 2905 _.options.arrows === true && 2906 _.slideCount > _.options.slidesToShow && 2907 !_.options.infinite 2908 ) { 2909 _.$prevArrow.removeClass("slick-disabled").attr("aria-disabled", "false"); 2910 _.$nextArrow.removeClass("slick-disabled").attr("aria-disabled", "false"); 2911 2912 if (_.currentSlide === 0) { 2913 _.$prevArrow.addClass("slick-disabled").attr("aria-disabled", "true"); 2914 _.$nextArrow 2915 .removeClass("slick-disabled") 2916 .attr("aria-disabled", "false"); 2917 } else if ( 2918 _.currentSlide >= _.slideCount - _.options.slidesToShow && 2919 _.options.centerMode === false 2920 ) { 2921 _.$nextArrow.addClass("slick-disabled").attr("aria-disabled", "true"); 2922 _.$prevArrow 2923 .removeClass("slick-disabled") 2924 .attr("aria-disabled", "false"); 2925 } else if ( 2926 _.currentSlide >= _.slideCount - 1 && 2927 _.options.centerMode === true 2928 ) { 2929 _.$nextArrow.addClass("slick-disabled").attr("aria-disabled", "true"); 2930 _.$prevArrow 2931 .removeClass("slick-disabled") 2932 .attr("aria-disabled", "false"); 2933 } 2934 } 2935 }; 2936 2937 Slick.prototype.updateDots = function () { 2938 var _ = this; 2939 2940 if (_.$dots !== null) { 2941 _.$dots.find("li").removeClass("slick-active").end(); 2942 2943 _.$dots 2944 .find("li") 2945 .eq(Math.floor(_.currentSlide / _.options.slidesToScroll)) 2946 .addClass("slick-active"); 2947 } 2948 }; 2949 2950 Slick.prototype.visibility = function () { 2951 var _ = this; 2952 2953 if (_.options.autoplay) { 2954 if (document[_.hidden]) { 2955 _.interrupted = true; 2956 } else { 2957 _.interrupted = false; 2958 } 2959 } 2960 }; 2961 2962 $.fn.slick = function () { 2963 var _ = this, 2964 opt = arguments[0], 2965 args = Array.prototype.slice.call(arguments, 1), 2966 l = _.length, 2967 i, 2968 ret; 2969 for (i = 0; i < l; i++) { 2970 if (typeof opt == "object" || typeof opt == "undefined") 2971 _[i].slick = new Slick(_[i], opt); 2972 else ret = _[i].slick[opt].apply(_[i].slick, args); 2973 if (typeof ret != "undefined") return ret; 2974 } 2975 return _; 2976 }; 2977}); 2978 2979(function ($, window, document, undefined) { 2980 tpAjaxAddToCart = (function () { 2981 //Vars 2982 $addToCartButton = $(".add_to_cart_button"); 2983 2984 function initialize() { 2985 bindEvents(); 2986 window.wp = window.wp || {}; 2987 2988 $addToCartButton.removeClass("ajax_add_to_cart"); 2989 } 2990 2991 function bindEvents() { 2992 $(document.body).on( 2993 "click", 2994 ".button--ajax_add_cart, .single_add_to_cart_button:not(.wc-appointments-appointment-form-button), .woocommerce-variaition-add-to-cart", 2995 addProductToCart 2996 ); 2997 } 2998 2999 function addProductToCart(e) { 3000 e.preventDefault(); 3001 e.stopPropagation(); 3002 3003 let $cartButton = e.currentTarget, 3004 $cartForm = $($cartButton).closest("form.cart"), 3005 $variation_form = $(this).closest(".variations_form"), 3006 variations = $variation_form.find("select[name^=attribute]"), 3007 cartData = {}; 3008 3009 if ( 3010 $($cartButton).hasClass("loading") || 3011 $($cartButton).hasClass("disabled") 3012 ) { 3013 return false;
3014 } 3015 3016 // Clear previous cart errors. 3017 // clearNotices( $modal ); 3018 3019 if ($($cartForm).length == 0) { 3020 let id = $($cartButton).val() 3021 ? $($cartButton).val() 3022 : $($cartButton).data("product_id"); 3023 3024 //Need to tidy up this 3025 cartData.product_id = 3026 $cartForm.find("input[name=product_id]").val() || id; 3027 cartData.quantity = $cartForm.find("input[name=quantity]").val() || 1; 3028 cartData.variation_id = 3029 $cartForm.find("input[name=variation_id]").val() || 0; 3030 } else { 3031 // Validate the cart form. 3032 let formValidation = validateCart($cartForm); 3033 cartData = formValidation.cartData; 3034 3035 if (!formValidation.isValid) { 3036 // showCartError( $cartForm, formValidation.message ); 3037 console.error(formValidation.message); 3038 return false; 3039 } 3040 } 3041 3042 //Add in the ajax action 3043 cartData.action = "woocommerce_ajax_add_to_cart"; 3044 3045 // Trigger WooCommerce 'adding_to_cart' event. 3046 $(document.body).trigger("adding_to_cart", [$cartButton, cartData]); 3047 3048 $.ajax({ 3049 type: "post", 3050 url: wc_add_to_cart_params.ajax_url, 3051 data: cartData, 3052 dataType: "json", 3053 beforeSend: function (response) { 3054 $($cartButton).removeClass("added").addClass("loading"); 3055 }, 3056 complete: function (response) { 3057 console.log(response); 3058 $($cartButton).addClass("added").removeClass("loading"); 3059 }, 3060 success: function (response) { 3061 console.log(response); 3062 if (response.error == true) { 3063 if (response.notices) { 3064 $(".woocommerce-notices-wrapper").html(response.notices); 3065 } else { 3066 $(".woocommerce-notices-wrapper").html( 3067 "<p>An error has occured. Please contact an admin.</p>" 3068 ); 3069 } 3070 3071 $("html, body").animate( 3072 { 3073 scrollTop: 3074 $(".woocommerce-notices-wrapper").offset().top - 3075 $(".header").innerHeight() - 3076 30, 3077 }, 3078 500 3079 ); 3080 3081 return; 3082 } else { 3083 $(document.body).trigger("added_to_cart", [ 3084 response.fragments, 3085 response.cart_hash, 3086 $($cartButton), 3087 ]); 3088 3089 $(variations).val("").change(); 3090 $($variation_form).trigger("reset_data"); 3091 3092 //Update cart activity cookie 3093 document.cookie = `woocommerce_cart_last_activity=${Math.round( 3094 Date.now() / 1000 3095 )}; expires=${Math.round( 3096 Date.now() * ((24 * 60 * 60) / 1000) 3097 )}; path=/`; 3098 3099 // Reset addons. 3100 let $addons = $cartForm.find(".wc-pao-addon"); 3101 3102 if ($addons.length) { 3103 $addons.find("input").each(function () { 3104 let $type = $(this).attr("type"); 3105 3106 if ("checkbox" === $type || "radio" === $type) { 3107 $(this).prop("checked", false); 3108 } else { 3109 $(this).val(""); 3110 } 3111 $(this).change(); 3112 }); 3113 3114 $addons 3115 .find("select") 3116 .find("option:first") 3117 .prop("selected", true) 3118 .change(); 3119 $addons.find("textarea").val("").change(); 3120 } 3121 } 3122 }, 3123 error: function (xhr, ajaxOptions, thrownError) { 3124 console.error(xhr); 3125 console.error(xhr.responseJSON); 3126 console.error(ajaxOptions); 3127 console.error(thrownError); 3128 3129 $(".woocommerce-notices-wrapper").html( 3130 "<p>An error has occured. Please contact an admin.</p>" 3131 ); 3132 }, 3133 always: function () { 3134 $($cartButton).addClass("added").removeClass("loading"); 3135 }, 3136 }); 3137 3138 return false; 3139 } 3140 3141 function validateCart($cartForm) { 3142 let cartData = getCartData($cartForm), 3143 result = { 3144 isValid: false, 3145 message: false, 3146 cartData: null, 3147 }; 3148 3149 if ($.isEmptyObject(cartData) || !("product_id" in cartData)) { 3150 result.message = "Sorry, there was an error adding this product."; 3151 return result; 3152 } 3153 3154 if (!cartData.product_id) { 3155 result.message = "No product ID was found for this product."; 3156 return result; 3157 } 3158 3159 if (!cartData.quantity || 0 >= cartData.quantity) { 3160 result.message = "Please enter a quantity greater than 0."; 3161 return result; 3162 } 3163 3164 // Check variation has been selected. 3165 if ( 3166 "variation_id" in cartData && 3167 0 === parseInt(cartData.variation_id, 10) 3168 ) { 3169 result.message = "Please select all required options."; 3170 return result; 3171 } 3172 3173 // Validate required options/addons. 3174 $("select, input, textarea", $cartForm).each(function () { 3175 let name = $(this).prop("name"); 3176 3177 // Strip [] from input name if present, to match properties in formData. 3178 if (-1 !== name.indexOf("[]")) { 3179 name = name.replace("[]", ""); 3180 } 3181 3182 if ($(this).prop("required")) { 3183 if (!(name in cartData) || "" === cartData[name]) { 3184 result.message = "Please select all required options."; 3185 return result; 3186 } 3187 } 3188 }); 3189 3190 if (!result.message) { 3191 result.isValid = true; 3192 } 3193 3194 result.cartData = cartData; 3195 return result; 3196 } 3197 3198 function getCartData($cartForm) { 3199 let data = serializeForm($cartForm),
3200 productId = $cartForm.find('[name="add-to-cart"]').val(); 3201 3202 // Remove add-to-cart (if present) as we use product_id. 3203 delete data["add-to-cart"]; 3204 data.product_id = productId; 3205 3206 return data; 3207 } 3208 3209 /** 3210 * Serialize a form to an object, in this format: { input1: 'value', input2: 'some value', etc }. 3211 * 3212 * @param jQuery $form The form to parse 3213 * @returns Object The serialized form 3214 */ 3215 function serializeForm($form) { 3216 var data = {}; 3217 3218 $.each($form.serializeArray(), function (index, item) { 3219 if (-1 !== item.name.indexOf("[]")) { 3220 item.name = item.name.replace("[]", ""); 3221 data[item.name] = $.makeArray(data[item.name]); 3222 data[item.name].push(item.value); 3223 } else { 3224 data[item.name] = item.value; 3225 } 3226 }); 3227 3228 return data; 3229 } 3230 3231 $("body").on("added_to_cart", function () { 3232 $(".cart-notification").addClass("active"); 3233 3234 setTimeout(function () { 3235 $(".cart-notification").removeClass("active"); 3236 }, 2000); 3237 }); 3238 // Public API. 3239 return { 3240 initialize: initialize, 3241 }; 3242 })(); 3243 3244 // Expose API. 3245 window.tpAjaxAddToCart = tpAjaxAddToCart; 3246 3247 $(document).ready(function () { 3248 tpAjaxAddToCart.initialize(); 3249 }); 3250})(jQuery, window, document); 3251 3252/* ====================== Throttle Function ====================== */ 3253let timerId; 3254var throttleFunction = function (func, delay) { 3255 // If setTimeout is already scheduled, no need to do anything 3256 if (timerId) { 3257 return; 3258 } 3259 3260 // Schedule a setTimeout after delay seconds 3261 timerId = setTimeout(function () { 3262 func(); 3263 3264 // Once setTimeout function execution is finished, timerId = undefined so that in <br> 3265 // the next scroll event function execution can be scheduled by the setTimeout 3266 timerId = undefined; 3267 }, delay); 3268}; 3269 3270/* ====================== Debounce Function ====================== */ 3271let debounceTimer; 3272var debounceFunction = function (func, delay, args = null) { 3273 // Cancels the setTimeout method execution 3274 clearTimeout(debounceTimer); 3275 3276 if (args) { 3277 // Executes the func after delay time. 3278 debounceTimer = setTimeout(func.bind(null, args), delay); 3279 } else { 3280 // Executes the func after delay time. 3281 debounceTimer = setTimeout(func, delay); 3282 } 3283}; 3284jQuery(document).ready(function ($) { 3285 /* ====================== REMOVE EMPTY P TAG ====================== */ 3286 $("p").each(function () { 3287 var $this = $(this); 3288 //Stops CF7 breaking 3289 if ($(this).attr("role") == "status") return; 3290 3291 if ($this.html().replace(/\s| /g, "").length == 0) $this.remove(); 3292 }); 3293 3294 /* ====================== DROPDOWN HEIGHT CALC ====================== */ 3295 let dropdown = $(".dropdown__heading"); 3296 3297 $(dropdown).on("click", function () { 3298 $(this).parent(".dropdown").toggleClass("dropdown--active"); 3299 let dropdownContent = $(this).next(".dropdown__content"); 3300 3301 if (dropdownContent.innerHeight() > 0) { 3302 dropdownContent.css("max-height", 0); 3303 } else { 3304 dropdownContent.css("max-height", dropdownContent[0].scrollHeight + "px"); 3305 } 3306 }); 3307 3308 /* ====================== CF7 SENDING ====================== */ 3309 let $orgVal = ""; 3310 let $target = null; 3311 3312 $(".wpcf7-submit").on("click", function (e) { 3313 //Collect original text before changing it 3314 $orgVal = $(this).val(); 3315 $target = $(this); 3316 3317 $(this).val("Sending..."); 3318 $(this).addClass("disabled"); 3319 }); 3320 document.addEventListener( 3321 "wpcf7invalid", 3322 function (event) { 3323 $target.removeClass("disabled"); 3324 $target.val($orgVal); 3325 }, 3326 false 3327 ); 3328 document.addEventListener( 3329 "wpcf7mailsent", 3330 function (event) { 3331 $target.removeClass("disabled"); 3332 $target.val($orgVal); 3333 }, 3334 false 3335 ); 3336 3337 /* ====================== WINDOW REISZE FUNCTION ====================== */ 3338 $(window).resize(function () {}); 3339 /* ====================== SCROLLED HEADER CHECK ====================== */ 3340 let pageClasses = [ 3341 "error404", 3342 "login", 3343 "page-template-woocommerce-account", 3344 "page-template-woocommerce-checkout", 3345 "single-product", 3346 ]; 3347 3348 function checkBodyClass() { 3349 for (let i = 0; i <= pageClasses.length; i++) { 3350 if ($("body").hasClass(pageClasses[i])) { 3351 return true; 3352 } 3353 } 3354 3355 return false;
3356 } 3357 3358 if (checkBodyClass()) { 3359 $(".header").addClass("scrolled"); 3360 } 3361 3362 /* ====================== MASTHEAD PARALLAX ====================== */ 3363 function parallax() { 3364 let scroll = $(this).scrollTop(); 3365 let windowHeight = $(window).height(); 3366 let translate3d = scroll / 2; 3367 let $hero = $(".masthead__image"); 3368 3369 translate3d = translate3d < 0 ? 0 : translate3d; 3370 3371 if (scroll < windowHeight) { 3372 let effect = "translate3d(0px," + translate3d + "px, 0px)"; 3373 $hero.css({ 3374 transform: effect, 3375 "-webkit-transform": effect, 3376 "-ms-transform": effect, 3377 }); 3378 } 3379 3380 requestAnimationFrame(parallax); 3381 } 3382 3383 parallax(); 3384 3385 /* ====================== NAV TOGGLE ====================== */ 3386 $(".nav-toggle").on("click", function () { 3387 $("body").toggleClass("nav-open"); 3388 $("html").toggleClass("stop-scrolling"); 3389 $(".menu-item-has-children").removeClass("open"); 3390 // $(".menu-item-has-children .sub-menu").css('maxHeight', 0); 3391 $(".menu-item-has-children .sub-menu").hide(); 3392 }); 3393 3394 //Close nav if click is not on nav or it's children 3395 $(document).on("click", function (e) { 3396 e.stopPropagation(); 3397 // console.log(e.target) 3398 var nav = $(".navigation"); 3399 var navtoggle = $(".nav-toggle"); 3400 if ( 3401 !navtoggle.is(e.target) && 3402 navtoggle.has(e.target).length == 0 && 3403 !nav.is(e.target) && 3404 nav.has(e.target).length == 0 3405 ) { 3406 $("body").removeClass("nav-open"); 3407 $("html").removeClass("stop-scrolling"); 3408 } 3409 }); 3410 3411 /* ====================== NAV DROPDOWN TOGGLE ====================== */ 3412 3413 $(".menu-item-has-children > a").on("click", function (e) { 3414 var winWidth = $(window).width(); 3415 3416 if (winWidth < 1200) { 3417 $(this).parent().toggleClass("open"); 3418 var subMenu = $(this).next(".sub-menu"); 3419 subMenu.slideToggle(); 3420 } else if (winWidth > 1200) { 3421 if ($("body").hasClass("mobile-nav")) { 3422 $(this).parent().toggleClass("open"); 3423 var subMenu = $(this).next(".sub-menu"); 3424 subMenu.slideToggle(); 3425 } 3426 } 3427 }); 3428 3429 /* ====================== SLICK SETTINGS ====================== */ 3430 3431 let $mastheadSlider = $(".masthead__slider--slides"); 3432 3433 $mastheadSlider.slick({ 3434 infinite: true, 3435 slidesToShow: 1, 3436 slidesToScroll: 1, 3437 autoplay: true, 3438 autoplaySpeed: 6000, 3439 rows: 0, 3440 arrows: false, 3441 dots: true, 3442 fade: true, 3443 cssEase: "linear", 3444 speed: 1000, 3445 infinite: true, 3446 draggable: false, 3447 pauseOnHover: false, 3448 }); 3449 3450 let $locationsSlider = $(".locations-slider"); 3451 3452 $locationsSlider.slick({ 3453 infinite: true, 3454 slidesToShow: 3, 3455 slidesToScroll: 1, 3456 autoplay: true, 3457 autoplaySpeed: 4000, 3458 rows: 0, 3459 speed: 800, 3460 dots: false, 3461 arrows: true, 3462 prevArrow: $(".locations-slider__prev"), 3463 nextArrow: $(".locations-slider__next"), 3464 infinite: true, 3465 responsive: [ 3466 { 3467 breakpoint: 1024, 3468 settings: { 3469 slidesToShow: 3, 3470 }, 3471 }, 3472 { 3473 breakpoint: 992, 3474 settings: { 3475 slidesToShow: 2, 3476 }, 3477 }, 3478 { 3479 breakpoint: 480, 3480 settings: { 3481 slidesToShow: 1, 3482 }, 3483 }, 3484 ], 3485 }); 3486 3487 let $testimonialsSlider = $(".testimonials-slider"); 3488 // let $status = $('.paging'); 3489 3490 // $testimonialSlider.on('init reInit afterChange', function(event, slick, currentSlide, nextSlide){ 3491 // //currentSlide is undefined on init -- set it to 0 in this case (currentSlide is 0 based) 3492 // var i = (currentSlide ? currentSlide : 0) + 1; 3493 // $status.text(i + '/' + slick.slideCount); 3494 // }); 3495 3496 $testimonialsSlider.slick({ 3497 infinite: true, 3498 slidesToShow: 1, 3499 slidesToScroll: 1, 3500 dots: true, 3501 arrows: false, 3502 autoplay: true, 3503 autoplaySpeed: 7000, 3504 rows: 0, 3505 }); 3506 3507 let $productsSlider = $(".section__featured-products-block .products-slider"); 3508 3509 $productsSlider.slick({ 3510 infinite: true, 3511 slidesToShow: 2, 3512 slidesToScroll: 1, 3513 autoplay: false, 3514 rows: 0, 3515 speed: 800, 3516 dots: false, 3517 arrows: true, 3518 prevArrow: $(".section__featured-products-block .products-slider__prev"), 3519 nextArrow: $(".section__featured-products-block .products-slider__next"), 3520 infinite: true, 3521 responsive: [ 3522 { 3523 breakpoint: 1440, 3524 settings: { 3525 slidesToShow: 2, 3526 }, 3527 }, 3528 { 3529 breakpoint: 800, 3530 settings: { 3531 slidesToShow: 1, 3532 }, 3533 }, 3534 ], 3535 }); 3536 3537 $productsSlider.on( 3538 "beforeChange", 3539 function (event, slick, currentSlide, nextSlide) { 3540 let slidesLength = slick.$slides.length - 1, 3541 isCurrentFirstOrLast = 3542 currentSlide === 0 || currentSlide === slidesLength,
3543 isNextFirstOrLast = nextSlide === 0 || nextSlide === slidesLength; 3544 3545 if (isCurrentFirstOrLast && isNextFirstOrLast) { 3546 let firstClone = $(event.currentTarget).find( 3547 ".slick-cloned.slick-active" 3548 ); 3549 let nextClone = $(event.currentTarget).find( 3550 ".slick-cloned.slick-active + .slick-cloned" 3551 ); 3552 setTimeout(function () { 3553 firstClone.addClass("slick-active"); 3554 nextClone.addClass("slick-active"); 3555 }, 100); 3556 } 3557 } 3558 ); 3559 3560 let $productThumbnailSlider = $(".woocommerce-product-gallery__slider"); 3561 3562 $productThumbnailSlider.slick({ 3563 infinite: true, 3564 slidesToShow: 3, 3565 slidesToScroll: 1, 3566 dots: false, 3567 autoplay: true, 3568 rows: 0, 3569 autoplaySpeed: 4000, 3570 speed: 1000, 3571 prevArrow: $(".woocommerce-product-gallery__thumbnails__prev"), 3572 nextArrow: $(".woocommerce-product-gallery__thumbnails__next"), 3573 responsive: [ 3574 { 3575 breakpoint: 1200, 3576 settings: { 3577 arrows: true, 3578 slidesToShow: 3, 3579 }, 3580 }, 3581 { 3582 breakpoint: 1025, 3583 settings: { 3584 arrows: true, 3585 slidesToShow: 2, 3586 }, 3587 }, 3588 { 3589 breakpoint: 600, 3590 settings: { 3591 slidesToShow: 1, 3592 arrows: true, 3593 }, 3594 }, 3595 ], 3596 }); 3597 3598 let $relatedProductsSlider = $(".section__related-products .products"); 3599 3600 $relatedProductsSlider.slick({ 3601 infinite: true, 3602 slidesToShow: 3, 3603 slidesToScroll: 1, 3604 autoplay: false, 3605 arrows: false, 3606 rows: 0, 3607 responsive: [ 3608 { 3609 breakpoint: 1140, 3610 settings: { 3611 slidesToShow: 3, 3612 dots: true, 3613 }, 3614 }, 3615 { 3616 breakpoint: 992, 3617 settings: { 3618 slidesToShow: 2, 3619 dots: true, 3620 }, 3621 }, 3622 { 3623 breakpoint: 767, 3624 settings: { 3625 slidesToShow: 1, 3626 dots: true, 3627 }, 3628 }, 3629 ], 3630 }); 3631 let $upSellsSlider = $(".section__upsells .products"); 3632 3633 $upSellsSlider.slick({ 3634 infinite: true, 3635 slidesToShow: 3, 3636 slidesToScroll: 1, 3637 autoplay: false, 3638 arrows: false, 3639 rows: 0, 3640 responsive: [ 3641 { 3642 breakpoint: 1140, 3643 settings: { 3644 slidesToShow: 3, 3645 dots: true, 3646 }, 3647 }, 3648 { 3649 breakpoint: 992, 3650 settings: { 3651 slidesToShow: 2, 3652 dots: true, 3653 }, 3654 }, 3655 { 3656 breakpoint: 767, 3657 settings: { 3658 slidesToShow: 1, 3659 dots: true, 3660 }, 3661 }, 3662 ], 3663 }); 3664 3665 let $videosSlider = $(".videos-slider"); 3666 3667 $videosSlider.slick({ 3668 infinite: true, 3669 slidesToShow: 3670 $(".video-thumbnail").length > 5 ? 5 : $(".video-thumbnail").length, 3671 slidesToScroll: 1, 3672 autoplay: true, 3673 autoplaySpeed: 4000, 3674 rows: 0, 3675 speed: 800, 3676 dots: false, 3677 arrows: true, 3678 prevArrow: $(".videos-slider__prev"), 3679 nextArrow: $(".videos-slider__next"), 3680 infinite: true, 3681 responsive: [ 3682 { 3683 breakpoint: 1024, 3684 settings: { 3685 slidesToShow: 3686 $(".video-thumbnail").length > 5 ? 5 : $(".video-thumbnail").length, 3687 }, 3688 }, 3689 { 3690 breakpoint: 992, 3691 settings: { 3692 slidesToShow: 2, 3693 }, 3694 }, 3695 { 3696 breakpoint: 480, 3697 settings: { 3698 slidesToShow: 1, 3699 }, 3700 }, 3701 ], 3702 }); 3703 3704 let $galleryImagesSlider = $(".gallery-images--slider"); 3705 3706 $galleryImagesSlider.slick({ 3707 infinite: true, 3708 slidesToShow: 3, 3709 slidesToScroll: 1, 3710 autoplay: true, 3711 autoplaySpeed: 4000, 3712 rows: 0, 3713 speed: 800, 3714 dots: false, 3715 arrows: true, 3716 prevArrow: $(".gallery-images--slider__prev"), 3717 nextArrow: $(".gallery-images--slider__next"), 3718 infinite: true, 3719 responsive: [ 3720 { 3721 breakpoint: 1024, 3722 settings: { 3723 slidesToShow: 3, 3724 }, 3725 }, 3726 { 3727 breakpoint: 992, 3728 settings: { 3729 slidesToShow: 2, 3730 }, 3731 }, 3732 { 3733 breakpoint: 480, 3734 settings: { 3735 slidesToShow: 1, 3736 }, 3737 }, 3738 ], 3739 }); 3740 3741 /* ====================== PRODUCT GALLERY SWITCH ====================== */ 3742 $(".woocommerce-product-gallery__slider .thumbnail").on("click", function () { 3743 let imgSrc = $(this).find("img").data("preview"); 3744 let imgFull = $(this).find("img").data("preview"); 3745 $(".woocommerce-product-gallery__featured img").attr("src", imgSrc); 3746 $(".woocommerce-product-gallery__featured img").data("full", imgFull); 3747 }); 3748 3749 /* ====================== IMAGE ZOOM BOX ====================== */ 3750 let zoomBox = $("#zoomBox"); 3751 let zoomLink = $(".zoom-link"); 3752 let zoomLinkClose = $(".zoom-link-close"); 3753 3754 zoomLink.on("click", function () { 3755 let imgFull = $(".woocommerce-product-gallery__featured img").data("full"); 3756 zoomBox.toggleClass("active"); 3757 zoomBox.find("img").attr("src", imgFull); 3758 }); 3759 3760 zoomLinkClose.on("click", function () { 3761 zoomBox.removeClass("active"); 3762 }); 3763 3764 /* ====================== QTY BUTTON INCREMENTS ====================== */ 3765 $(".input-notice").hide(); 3766 $(document).on("click", "button.plus, button.minus", function () { 3767 // Get current quantity values 3768 var qty = $(this).closest("form.cart").find(".qty"); 3769 var val = parseFloat(qty.val()); 3770 var max = parseFloat(qty.attr("max")); 3771 var min = parseFloat(qty.attr("min")); 3772 var step = parseFloat(qty.attr("step")); 3773 var notice = $(this).closest("form.cart").find(".input-notice"); 3774 3775 // Change the value if plus or minus 3776 if ($(this).is(".plus")) { 3777 if (max && max <= val) { 3778 qty.val(max); 3779 $(notice).show(); 3780 $(notice).text("Maximum Quantity Reached"); 3781 } else { 3782 qty.val(val + step); 3783 } 3784 } else { 3785 if (min && min >= val) { 3786 qty.val(min); 3787 } else if (val > 1) { 3788 qty.val(val - step); 3789 $(notice).hide(); 3790 } 3791 } 3792 }); 3793 3794 $(".input-notice").hide(); 3795 let checkoutFlag = false;
3796 $("form.woocommerce-cart-form").on( 3797 "click", 3798 "button.plus, button.minus", 3799 function () { 3800 // Get current quantity values 3801 var qty = $(this).parent(".qty-btns").find(".qty"); 3802 var val = parseFloat(qty.val()); 3803 var max = parseFloat(qty.attr("max")); 3804 var min = parseFloat(qty.attr("min")); 3805 var step = parseFloat(qty.attr("step")); 3806 var notice = $(this).parents(".quantity").find(".input-notice"); 3807 3808 //Set checkoutFlag 3809 3810 // Change the value if plus or minus 3811 if ($(this).is(".plus")) { 3812 if (max && max <= val) { 3813 qty.val(max); 3814 $(notice).show(); 3815 $(notice).text("Maximum Quantity Reached"); 3816 } else { 3817 qty.val(val + step); 3818 debounceFunction(triggerUpdate, 500); 3819 } 3820 } else { 3821 if (min && min >= val) { 3822 qty.val(min); 3823 } else if (val > 1) { 3824 qty.val(val - step); 3825 $(notice).hide(); 3826 debounceFunction(triggerUpdate, 500); 3827 } 3828 } 3829 } 3830 ); 3831 3832 function triggerUpdate() { 3833 $('[name="update_cart"]').prop("disabled", false); 3834 $("[name='update_cart']").trigger("click"); 3835 } 3836 3837 /* ====================== CHANGE PRICE ON VARIATION CHANGE ====================== */ 3838 let variationsFormPrefix = $(".product-price__prefix"); 3839 3840 if ($(".cart.variations_form").length > 0) { 3841 let resetVariations = $(".reset_variations"); 3842 let minVal = $(".product-price__value").text(); 3843 // minVal = minVal.replace("£", ""); 3844 3845 $(".variations_form").on("show_variation", function () { 3846 let price = $(".woocommerce-variation-price .woocommerce-Price-amount"); 3847 // price = price.replace("£",''); 3848 if (price.length > 0) { 3849 //Variation is on sale 3850 if (price.length > 1) { 3851 let fullPrice = $(price[0]).text().replace("£", ""); 3852 let salePrice = $(price[1]).text().replace("£", ""); 3853 3854 let percentage = ((fullPrice - salePrice) / fullPrice) * 100; 3855 percentage = percentage.toFixed(0); 3856 price = 3857 "<del class='sale'>" + 3858 $(price[0]).text() + 3859 "</del>" + 3860 $(price[1]).text() + 3861 '<span class="product-discount"> Save ' + 3862 percentage + 3863 "%</span>"; 3864 } else { 3865 price = $(price).text(); 3866 } 3867 3868 $(".product-price__value").html(price); 3869 //hide prefix 3870 variationsFormPrefix.hide(); 3871 } 3872 }); 3873 3874 $(resetVariations).on("click", function () { 3875 variationsFormPrefix.show(); 3876 3877 if (minVal !== "") { 3878 $(".product-price__value").text(minVal); 3879 } 3880 }); 3881 } 3882 3883 /* ====================== LOCATION TABS ====================== */ 3884 let contentArea = $(".single-locations .content-area"); 3885 let locationSidebarLink = $(".single-locations .sidebar__link:not(.no-tab)"); 3886 3887 $(locationSidebarLink).on("click", function (e) { 3888 e.preventDefault(); 3889 let anchor = $(this).attr("href"); 3890 let target = $(contentArea).find("div#" + anchor); 3891 3892 loadLocationTab(anchor, target); 3893 }); 3894 3895 function loadLocationTab(anchor, target) { 3896 let locationTabs = $(".single-locations .tab"); 3897 let sidebarLink = $("a[href$=" + anchor + "]"); 3898 3899 if (target.length == 1) { 3900 locationSidebarLink.removeClass("sidebar__link--active"); 3901 sidebarLink.addClass("sidebar__link--active"); 3902 3903 locationTabs.removeClass("tab--active"); 3904 target.addClass("tab--active"); 3905 } 3906 } 3907 3908 function locationBookingTab() { 3909 let params = window.location.search.substr(1).split("="); 3910 //Bail if doesn't exist 3911 if (params == "") return; 3912 let param = params[0].charAt(0).toUpperCase() + params[0].slice(1); 3913 let tabContent = $(contentArea).find("div#" + param); 3914 let headerHeight = $(".header").innerHeight() + 30; 3915 3916 loadLocationTab(param, tabContent); 3917 3918 if (tabContent.length > 0) { 3919 //If on mobile scroll sidebar links to right 3920 if ($(window).width() < 768) { 3921 let sidebar = $(".sidebar__links"); 3922 3923 sidebar.scrollLeft(sidebar.width()); 3924 } 3925 3926 //scroll to item 3927 $("html,body") 3928 .stop() 3929 .animate( 3930 { 3931 scrollTop: tabContent.offset().top - headerHeight, //offsets for fixed header 3932 }, 3933 "linear" 3934 ); 3935 } 3936 } 3937 3938 $(window).on("load", function () { 3939 if ($("body").hasClass("single-locations")) { 3940 locationBookingTab(); 3941 } 3942 }); 3943 3944 /* ====================== GALLERY IMAGE BOX ====================== */ 3945 let galleryZoomBox = $("#galleryImageBox"); 3946 let galleryZoomLink = $(".gallery-images__link"); 3947 let galleryZoomClose = $(".gallery-images__close"); 3948 3949 galleryZoomLink.on("click", function () { 3950 let imgFull = $(this).parent().data("full"); 3951 galleryZoomBox.toggleClass("active"); 3952 galleryZoomBox.find("img").attr("src", imgFull); 3953 }); 3954 3955 galleryZoomClose.on("click", function () { 3956 galleryZoomBox.removeClass("active"); 3957 }); 3958 3959 /* ====================== LOCATION IMAGE BOX ====================== */ 3960 let locationZoomBox = $("#locationImageBox"); 3961 let locationZoomLink = $(".location-gallery__link"); 3962 let locationZoomClose = $(".location-gallery__close"); 3963 3964 locationZoomLink.on("click", function () { 3965 let imgFull = $(this).parent().data("full"); 3966 locationZoomBox.toggleClass("active"); 3967 locationZoomBox.find("img").attr("src", imgFull); 3968 }); 3969 3970 locationZoomClose.on("click", function () { 3971 locationZoomBox.removeClass("active"); 3972 }); 3973 3974 /* ====================== GRID SIDEBAR CODE ====================== */ 3975 let catsWithChildren = $(".category-sidebar__link--has-children"); 3976 $(".category-sidebar__sub-list").hide(); 3977 3978 catsWithChildren.on("click", function (event) { 3979 if ($(event.target).hasClass("fa-chevron-down")) { 3980 event.preventDefault(); 3981 $(this).toggleClass("category-sidebar__link--open"); 3982 $(this).next(".category-sidebar__sub-list").slideToggle("fast"); 3983 } 3984 }); 3985 3986 /* ====================== DOCUSIGN IFRAME ====================== */ 3987 let docusign = $(".docusign-modal"); 3988 let localDocusign = window.localStorage.getItem("docusign"); 3989 3990 if (docusign.length > 0) { 3991 let docusignIframe = $("#docusign-box"); 3992 $("#order_review").addClass("disable"); 3993 3994 docusignIframe.on("load", function (e) { 3995 docusign.removeClass("loading"); 3996 }); 3997 } 3998 3999 //Welcome.php event handler 4000 window.onmessage = function (e) { 4001 if (e.data == "docsign") { 4002 // window.localStorage.setItem('docusign', 'signed'); 4003 let checkoutData = {}; 4004 checkoutData.action = "woocommerce_ajax_add_to_cart"; 4005 4006 $("#order_review").removeClass("disable"); 4007 docusign.parent().removeClass("active"); 4008 $("html, body").css({ overflow: "auto", height: "auto" }); 4009 } 4010 }; 4011 4012 /* ====================== DATEPICKER FIX ====================== */ 4013 // $(document).on('click', '.datepicker--cell', function() { 4014 // let selectedDate = $('.datepicker--cell.has-time-slot.-selected-'); 4015 // let formattedDate = $('#b_date').attr('data-date-i18n'); 4016 4017 // if( formattedDate.includes('ddS') ) { 4018 // let day = selectedDate.attr('data-date'); 4019 // // let month = +selectedDate.attr('data-month') + +1; //Months are 0 based! 4020 // let month = selectedDate.attr('data-month'); 4021 // let year = selectedDate.attr('data-year'); 4022 4023 // // let format= (d,a=d.toString().split` `)=>
4023 a[2]+" "+d.toLocaleString('default', { month: 'long' })+" "+a[3]; 4024 // // let d = new Date(day + '-' + month + '-' + year); 4025 // // d = format(d); 4026 4027 // let date = new Date(year, month, day); // 2009-11-10 4028 // let longMonth = date.toLocaleString('default', { month: 'long' }); 4029 // let prettyDate = day.toString() + ' ' + longMonth.toString() + ' ' + year.toString(); 4030 4031 // setTimeout(function() { 4032 // $('#b_date').attr('data-date-i18n',prettyDate); 4033 // },200) 4034 // } 4035 // }) 4036 4037 /* ====================== AUTO EXPAND COUPON AREA ON CHECKOUT ====================== */ 4038 if ($(".checkout_coupon").length > 0) { 4039 $(".checkout_coupon").show(); 4040 $(".woocommerce-form-coupon-toggle").hide(); 4041 } 4042 4043 (function ($) { 4044 // Populates a select drop-down with options in a list 4045 $.fn.populate = function (list) { 4046 return this.append(list); 4047 }; 4048 })(jQuery); 4049 4050 function generateOptions(list) { 4051 let newList = list.map((item) => { 4052 // console.log("Item", item); 4053 let name = item.name; 4054 let itemVal = item.pdf ? item.pdf : name.replace(" ", "_").toLowerCase(); 4055 4056 return $("<option>", { 4057 text: name, 4058 value: itemVal, 4059 }); 4060 }); 4061 4062 return newList; 4063 } 4064 4065 function maybeAddLocationDataToContactForm() { 4066 let theForm = $(".wpcf7-form"); 4067 if ($(".wpcf7-form").length > 0) { 4068 if (theForm.find('select[name="location_enquiry_type"]')) { 4069 addLocationDataToForm(theForm); 4070 } 4071 } 4072 } 4073 4074 function addLocationDataToForm(theForm) { 4075 let hidden_field = theForm.find('input[name="_locations_data"]'); 4076 let location_select = theForm.find('select[name="location"]'); 4077 let activity_select = theForm.find('select[name="location_enquiry_type"]'); 4078 let originalOptions = activity_select.find("option"); 4079 4080 activity_select.attr("disabled", true); 4081 4082 let hidden_data = JSON.parse(hidden_field.val()); 4083 // console.log("Hidden Data:", hidden_data); 4084 // console.log("Selected location:", location_select); 4085 // console.log("Original Options:", originalOptions); 4086 4087 location_select.on("change", (e) => { 4088 let failFlag = false; 4089 var valueSelected = location_select.val(); 4090 // console.log(valueSelected); 4091 4092 //Catch no values so form can still be submitted 4093 activity_select.attr("disabled", false); 4094 if (!valueSelected) { 4095 failFlag = true; 4096 } else { 4097 let locationData = hidden_data[valueSelected.toLowerCase()]; 4098 4099 if (locationData) { 4100 console.log("Location Data:", locationData); 4101 let locationActivities = locationData["activities"]; 4102 if (locationActivities.length > 0) { 4103 console.log("Location Activities:", locationActivities); 4104 let optionList = [ 4105 originalOptions, 4106 ...generateOptions(locationActivities), 4107 ]; 4108 4109 // console.log("Option list", optionList); 4110 4111 activity_select.empty().populate(optionList); 4112 activity_select.val(""); //Clears field ready for user selection 4113 } else { 4114 failFlag = true; 4115 } 4116 } else { 4117 failFlag = true; 4118 } 4119 } 4120 4121 if (failFlag === true) { 4122 activity_select.empty().populate(originalOptions); 4123 activity_select.val("General"); 4124 } 4125 }); 4126 } 4127 4128 maybeAddLocationDataToContactForm(); 4129 4130 var wpcf7Elm = document.querySelector(".wpcf7"); 4131 4132 if (wpcf7Elm) { 4133 wpcf7Elm.addEventListener( 4134 "wpcf7submit", 4135 function (e) { 4136 let activity_select = document.querySelector( 4137 'select[name="location_enquiry_type"]' 4138 ); 4139 4140 if (activity_select) { 4141 $(activity_select).attr("disabled", true); 4142 } 4143 }, 4144 false 4145 ); 4146 } 4147});
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.