From 0defcee26f38a2dc9c3d6ad3ca6e8fe57d92f6ba Mon Sep 17 00:00:00 2001 From: Jay Guo Date: Thu, 26 Feb 2026 10:47:59 -0500 Subject: [PATCH 1/2] Update slick.js --- ckanext/showcase/assets/js/slick.js | 1028 ++++++++++++----- .../home/snippets/showcase_list.html | 1 + 2 files changed, 710 insertions(+), 319 deletions(-) diff --git a/ckanext/showcase/assets/js/slick.js b/ckanext/showcase/assets/js/slick.js index f1fe2590..4d75b93b 100644 --- a/ckanext/showcase/assets/js/slick.js +++ b/ckanext/showcase/assets/js/slick.js @@ -1,21 +1,3 @@ -/* -Please note: -This lib is modified for web accessibility -Each media item used to have an "aria-describedby" attribute -However, there were no corresponding descriptions, which violates web accessibility -To fix the issue, the "aria-describedby" attribute is modified to "aria-labelledby" -And each h3 label is assigned an corresponding id -For future maintaince, please note that: -If the DOM structure is changed, the following code should be changed accordingly - -$(this).find("h3").arrt({ - 'id': 'slick-slide' + _.instanceUid + i + '' -}) -$(this).find("a").first().attr({ - 'aria-labelledby': 'slick-slide' + _.instanceUid + i + '' -}) - -*/ /* _ _ _ _ ___| (_) ___| | __ (_)___ @@ -24,7 +6,7 @@ $(this).find("a").first().attr({ |___/_|_|\___|_|\_(_)/ |___/ |__/ - Version: 1.5.6 + Version: 1.8.1 Author: Ken Wheeler Website: http://kenwheeler.github.io Docs: http://kenwheeler.github.io/slick @@ -33,12 +15,23 @@ $(this).find("a").first().attr({ */ /* global window, document, define, jQuery, setInterval, clearInterval */ -(function(factory) { +;(function(factory) { 'use strict'; if (typeof define === 'function' && define.amd) { define(['jquery'], factory); - } else if (typeof exports !== 'undefined') { - module.exports = factory(require('jquery')); + } else if (typeof module === 'object' && module.exports) { + module.exports = function( root, jQuery ) { + if ( jQuery === undefined ) { + if ( typeof window !== 'undefined' ) { + jQuery = require('jquery'); + } + else { + jQuery = require('jquery')(root); + } + } + factory(jQuery); + return jQuery; + }; } else { factory(jQuery); } @@ -62,15 +55,15 @@ $(this).find("a").first().attr({ appendDots: $(element), arrows: true, asNavFor: null, - prevArrow: '', - nextArrow: '', + prevArrow: '', + nextArrow: '', autoplay: false, autoplaySpeed: 3000, centerMode: false, centerPadding: '50px', cssEase: 'ease', customPaging: function(slider, i) { - return ''; + return $('').text(i + 1); }, dots: false, dotsClass: 'slick-dots', @@ -79,11 +72,13 @@ $(this).find("a").first().attr({ edgeFriction: 0.35, fade: false, focusOnSelect: false, + focusOnChange: false, infinite: true, initialSlide: 0, lazyLoad: 'ondemand', mobileFirst: false, pauseOnHover: true, + pauseOnFocus: true, pauseOnDotsHover: false, respondTo: 'window', responsive: null, @@ -99,6 +94,7 @@ $(this).find("a").first().attr({ touchMove: true, touchThreshold: 5, useCSS: true, + useTransform: true, variableWidth: false, vertical: false, verticalSwiping: false, @@ -120,6 +116,7 @@ $(this).find("a").first().attr({ loadIndex: 0, $nextArrow: null, $prevArrow: null, + scrolling: false, slideCount: null, slideWidth: null, $slideTrack: null, @@ -127,6 +124,7 @@ $(this).find("a").first().attr({ sliding: false, slideOffset: 0, swipeLeft: null, + swiping: false, $list: null, touchObject: {}, transformsEnabled: false, @@ -141,8 +139,10 @@ $(this).find("a").first().attr({ _.breakpoints = []; _.breakpointSettings = []; _.cssTransitions = false; + _.focussed = false; + _.interrupted = false; _.hidden = 'hidden'; - _.paused = false; + _.paused = true; _.positionProp = null; _.respondTo = null; _.rowCount = 1; @@ -157,22 +157,15 @@ $(this).find("a").first().attr({ dataSettings = $(element).data('slick') || {}; - _.options = $.extend({}, _.defaults, dataSettings, settings); + _.options = $.extend({}, _.defaults, settings, dataSettings); _.currentSlide = _.options.initialSlide; _.originalSettings = _.options; - if (typeof document.mozHidden !== 'undefined') { - _.hidden = 'mozHidden'; - _.visibilityChange = 'mozvisibilitychange'; - } else if (typeof document.webkitHidden !== 'undefined') { - _.hidden = 'webkitHidden'; - _.visibilityChange = 'webkitvisibilitychange'; - } - _.autoPlay = $.proxy(_.autoPlay, _); _.autoPlayClear = $.proxy(_.autoPlayClear, _); + _.autoPlayIterator = $.proxy(_.autoPlayIterator, _); _.changeSlide = $.proxy(_.changeSlide, _); _.clickHandler = $.proxy(_.clickHandler, _); _.selectHandler = $.proxy(_.selectHandler, _); @@ -180,7 +173,6 @@ $(this).find("a").first().attr({ _.swipeHandler = $.proxy(_.swipeHandler, _); _.dragHandler = $.proxy(_.dragHandler, _); _.keyHandler = $.proxy(_.keyHandler, _); - _.autoPlayIterator = $.proxy(_.autoPlayIterator, _); _.instanceUid = instanceUid++; @@ -192,7 +184,6 @@ $(this).find("a").first().attr({ _.registerBreakpoints(); _.init(true); - _.checkResponsive(true); } @@ -200,6 +191,18 @@ $(this).find("a").first().attr({ }()); + Slick.prototype.activateADA = function() { + var _ = this; + + _.$slideTrack.find('.slick-active').attr({ + 'aria-hidden': 'false', + 'tabindex': '0' + }).find('a, input, button, select').attr({ + 'tabindex': '0' + }); + + }; + Slick.prototype.addSlide = Slick.prototype.slickAdd = function(markup, index, addBefore) { var _ = this; @@ -335,7 +338,7 @@ $(this).find("a").first().attr({ }; - Slick.prototype.asNavFor = function(index) { + Slick.prototype.getNavTarget = function() { var _ = this, asNavFor = _.options.asNavFor; @@ -344,6 +347,15 @@ $(this).find("a").first().attr({ asNavFor = $(asNavFor).not(_.$slider); } + return asNavFor; + + }; + + Slick.prototype.asNavFor = function(index) { + + var _ = this, + asNavFor = _.getNavTarget(); + if ( asNavFor !== null && typeof asNavFor === 'object' ) { asNavFor.each(function() { var target = $(this).slick('getSlick'); @@ -378,13 +390,10 @@ $(this).find("a").first().attr({ var _ = this; - if (_.autoPlayTimer) { - clearInterval(_.autoPlayTimer); - } + _.autoPlayClear(); - if (_.slideCount > _.options.slidesToShow && _.paused !== true) { - _.autoPlayTimer = setInterval(_.autoPlayIterator, - _.options.autoplaySpeed); + if ( _.slideCount > _.options.slidesToShow ) { + _.autoPlayTimer = setInterval( _.autoPlayIterator, _.options.autoplaySpeed ); } }; @@ -392,6 +401,7 @@ $(this).find("a").first().attr({ Slick.prototype.autoPlayClear = function() { var _ = this; + if (_.autoPlayTimer) { clearInterval(_.autoPlayTimer); } @@ -400,34 +410,30 @@ $(this).find("a").first().attr({ Slick.prototype.autoPlayIterator = function() { - var _ = this; + var _ = this, + slideTo = _.currentSlide + _.options.slidesToScroll; - if (_.options.infinite === false) { + if ( !_.paused && !_.interrupted && !_.focussed ) { - if (_.direction === 1) { + if ( _.options.infinite === false ) { - if ((_.currentSlide + 1) === _.slideCount - - 1) { + if ( _.direction === 1 && ( _.currentSlide + 1 ) === ( _.slideCount - 1 )) { _.direction = 0; } - _.slideHandler(_.currentSlide + _.options.slidesToScroll); + else if ( _.direction === 0 ) { - } else { + slideTo = _.currentSlide - _.options.slidesToScroll; - if ((_.currentSlide - 1 === 0)) { - - _.direction = 1; + if ( _.currentSlide - 1 === 0 ) { + _.direction = 1; + } } - _.slideHandler(_.currentSlide - _.options.slidesToScroll); - } - } else { - - _.slideHandler(_.currentSlide + _.options.slidesToScroll); + _.slideHandler( slideTo ); } @@ -480,22 +486,21 @@ $(this).find("a").first().attr({ Slick.prototype.buildDots = function() { var _ = this, - i, dotString; + i, dot; if (_.options.dots === true && _.slideCount > _.options.slidesToShow) { - dotString = ''; + _.$dots = dot.appendTo(_.options.appendDots); - _.$dots = $(dotString).appendTo( - _.options.appendDots); - - _.$dots.find('li').first().addClass('slick-active').attr('aria-hidden', 'false'); + _.$dots.find('li').first().addClass('slick-active'); } @@ -518,16 +523,14 @@ $(this).find("a").first().attr({ .data('originalStyling', $(element).attr('style') || ''); }); - _.$slidesCache = _.$slides; - _.$slider.addClass('slick-slider'); _.$slideTrack = (_.slideCount === 0) ? - $('
').appendTo(_.$slider) : - _.$slides.wrapAll('
').parent(); + $('
').appendTo(_.$slider) : + _.$slides.wrapAll('
').parent(); _.$list = _.$slideTrack.wrap( - '
').parent(); + '
').parent(); _.$slideTrack.css('opacity', 0); if (_.options.centerMode === true || _.options.swipeToSlide === true) { @@ -560,7 +563,7 @@ $(this).find("a").first().attr({ newSlides = document.createDocumentFragment(); originalSlides = _.$slider.children(); - if(_.options.rows > 1) { + if(_.options.rows > 0) { slidesPerSection = _.options.slidesPerRow * _.options.rows; numOfSlides = Math.ceil( @@ -582,7 +585,7 @@ $(this).find("a").first().attr({ newSlides.appendChild(slide); } - _.$slider.html(newSlides); + _.$slider.empty().append(newSlides); _.$slider.children().children().children() .css({ 'width':(100 / _.options.slidesPerRow) + '%', @@ -684,7 +687,7 @@ $(this).find("a").first().attr({ Slick.prototype.changeSlide = function(event, dontAnimate) { var _ = this, - $target = $(event.target), + $target = $(event.currentTarget), indexOffset, slideOffset, unevenOffset; // If target is a link, prevent default action. @@ -758,21 +761,26 @@ $(this).find("a").first().attr({ if (_.options.dots && _.$dots !== null) { - $('li', _.$dots).off('click.slick', _.changeSlide); - - if (_.options.pauseOnDotsHover === true && _.options.autoplay === true) { - - $('li', _.$dots) - .off('mouseenter.slick', $.proxy(_.setPaused, _, true)) - .off('mouseleave.slick', $.proxy(_.setPaused, _, false)); + $('li', _.$dots) + .off('click.slick', _.changeSlide) + .off('mouseenter.slick', $.proxy(_.interrupt, _, true)) + .off('mouseleave.slick', $.proxy(_.interrupt, _, false)); + if (_.options.accessibility === true) { + _.$dots.off('keydown.slick', _.keyHandler); } - } + _.$slider.off('focus.slick blur.slick'); + if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) { _.$prevArrow && _.$prevArrow.off('click.slick', _.changeSlide); _.$nextArrow && _.$nextArrow.off('click.slick', _.changeSlide); + + if (_.options.accessibility === true) { + _.$prevArrow && _.$prevArrow.off('keydown.slick', _.keyHandler); + _.$nextArrow && _.$nextArrow.off('keydown.slick', _.keyHandler); + } } _.$list.off('touchstart.slick mousedown.slick', _.swipeHandler); @@ -784,8 +792,7 @@ $(this).find("a").first().attr({ $(document).off(_.visibilityChange, _.visibility); - _.$list.off('mouseenter.slick', $.proxy(_.setPaused, _, true)); - _.$list.off('mouseleave.slick', $.proxy(_.setPaused, _, false)); + _.cleanUpSlideEvents(); if (_.options.accessibility === true) { _.$list.off('keydown.slick', _.keyHandler); @@ -802,17 +809,26 @@ $(this).find("a").first().attr({ $('[draggable!=true]', _.$slideTrack).off('dragstart', _.preventDefault); $(window).off('load.slick.slick-' + _.instanceUid, _.setPosition); - $(document).off('ready.slick.slick-' + _.instanceUid, _.setPosition); + + }; + + Slick.prototype.cleanUpSlideEvents = function() { + + var _ = this; + + _.$list.off('mouseenter.slick', $.proxy(_.interrupt, _, true)); + _.$list.off('mouseleave.slick', $.proxy(_.interrupt, _, false)); + }; Slick.prototype.cleanUpRows = function() { var _ = this, originalSlides; - if(_.options.rows > 1) { + if(_.options.rows > 0) { originalSlides = _.$slides.children().children(); originalSlides.removeAttr('style'); - _.$slider.html(originalSlides); + _.$slider.empty().append(originalSlides); } }; @@ -845,30 +861,31 @@ $(this).find("a").first().attr({ _.$dots.remove(); } - if ( _.$prevArrow.length ) { + if ( _.$prevArrow && _.$prevArrow.length ) { _.$prevArrow .removeClass('slick-disabled slick-arrow slick-hidden') .removeAttr('aria-hidden aria-disabled tabindex') - .css("display",""); + .css('display',''); if ( _.htmlExpr.test( _.options.prevArrow )) { _.$prevArrow.remove(); } } - if ( _.$nextArrow.length ) { + if ( _.$nextArrow && _.$nextArrow.length ) { _.$nextArrow .removeClass('slick-disabled slick-arrow slick-hidden') .removeAttr('aria-hidden aria-disabled tabindex') - .css("display",""); + .css('display',''); if ( _.htmlExpr.test( _.options.nextArrow )) { _.$nextArrow.remove(); } } + if (_.$slides) { _.$slides @@ -892,6 +909,7 @@ $(this).find("a").first().attr({ _.$slider.removeClass('slick-slider'); _.$slider.removeClass('slick-initialized'); + _.$slider.removeClass('slick-dotted'); _.unslicked = true; @@ -982,6 +1000,8 @@ $(this).find("a").first().attr({ if (filter !== null) { + _.$slidesCache = _.$slides; + _.unload(); _.$slideTrack.children(this.options.slide).detach(); @@ -994,6 +1014,43 @@ $(this).find("a").first().attr({ }; + Slick.prototype.focusHandler = function() { + + var _ = this; + + // If any child element receives focus within the slider we need to pause the autoplay + _.$slider + .off('focus.slick blur.slick') + .on( + 'focus.slick', + '*', + function(event) { + var $sf = $(this); + + setTimeout(function() { + if( _.options.pauseOnFocus ) { + if ($sf.is(':focus')) { + _.focussed = true; + _.autoPlay(); + } + } + }, 0); + } + ).on( + 'blur.slick', + '*', + function(event) { + var $sf = $(this); + + // When a blur occurs on any elements within the slider we become unfocused + if( _.options.pauseOnFocus ) { + _.focussed = false; + _.autoPlay(); + } + } + ); + }; + Slick.prototype.getCurrent = Slick.prototype.slickCurrentSlide = function() { var _ = this; @@ -1010,17 +1067,23 @@ $(this).find("a").first().attr({ var pagerQty = 0; if (_.options.infinite === true) { - while (breakPoint < _.slideCount) { - ++pagerQty; - breakPoint = counter + _.options.slidesToShow; - counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow; + if (_.slideCount <= _.options.slidesToShow) { + ++pagerQty; + } else { + while (breakPoint < _.slideCount) { + ++pagerQty; + breakPoint = counter + _.options.slidesToScroll; + counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow; + } } } else if (_.options.centerMode === true) { pagerQty = _.slideCount; - } else { + } else if(!_.options.asNavFor) { + pagerQty = 1 + Math.ceil((_.slideCount - _.options.slidesToShow) / _.options.slidesToScroll); + }else { while (breakPoint < _.slideCount) { ++pagerQty; - breakPoint = counter + _.options.slidesToShow; + breakPoint = counter + _.options.slidesToScroll; counter += _.options.slidesToScroll <= _.options.slidesToShow ? _.options.slidesToScroll : _.options.slidesToShow; } } @@ -1035,7 +1098,8 @@ $(this).find("a").first().attr({ targetLeft, verticalHeight, verticalOffset = 0, - targetSlide; + targetSlide, + coef; _.slideOffset = 0; verticalHeight = _.$slides.first().outerHeight(true); @@ -1043,7 +1107,16 @@ $(this).find("a").first().attr({ if (_.options.infinite === true) { if (_.slideCount > _.options.slidesToShow) { _.slideOffset = (_.slideWidth * _.options.slidesToShow) * -1; - verticalOffset = (verticalHeight * _.options.slidesToShow) * -1; + coef = -1; + + if (_.options.vertical === true && _.options.centerMode === true) { + if (_.options.slidesToShow === 2) { + coef = -1.5; + } else if (_.options.slidesToShow === 1) { + coef = -2; + } + } + verticalOffset = (verticalHeight * _.options.slidesToShow) * coef; } if (_.slideCount % _.options.slidesToScroll !== 0) { if (slideIndex + _.options.slidesToScroll > _.slideCount && _.slideCount > _.options.slidesToShow) { @@ -1068,7 +1141,9 @@ $(this).find("a").first().attr({ verticalOffset = 0; } - if (_.options.centerMode === true && _.options.infinite === true) { + if (_.options.centerMode === true && _.slideCount <= _.options.slidesToShow) { + _.slideOffset = ((_.slideWidth * Math.floor(_.options.slidesToShow)) / 2) - ((_.slideWidth * _.slideCount) / 2); + } else if (_.options.centerMode === true && _.options.infinite === true) { _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2) - _.slideWidth; } else if (_.options.centerMode === true) { _.slideOffset = 0; @@ -1089,15 +1164,33 @@ $(this).find("a").first().attr({ targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex + _.options.slidesToShow); } - targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0; + if (_.options.rtl === true) { + if (targetSlide[0]) { + targetLeft = (_.$slideTrack.width() - targetSlide[0].offsetLeft - targetSlide.width()) * -1; + } else { + targetLeft = 0; + } + } else { + targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0; + } if (_.options.centerMode === true) { - if (_.options.infinite === false) { + if (_.slideCount <= _.options.slidesToShow || _.options.infinite === false) { targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex); } else { targetSlide = _.$slideTrack.children('.slick-slide').eq(slideIndex + _.options.slidesToShow + 1); } - targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0; + + if (_.options.rtl === true) { + if (targetSlide[0]) { + targetLeft = (_.$slideTrack.width() - targetSlide[0].offsetLeft - targetSlide.width()) * -1; + } else { + targetLeft = 0; + } + } else { + targetLeft = targetSlide[0] ? targetSlide[0].offsetLeft * -1 : 0; + } + targetLeft += (_.$list.width() - targetSlide.outerWidth()) / 2; } } @@ -1149,13 +1242,25 @@ $(this).find("a").first().attr({ Slick.prototype.getSlideCount = function() { var _ = this, - slidesTraversed, swipedSlide, centerOffset; + slidesTraversed, swipedSlide, swipeTarget, centerOffset; - centerOffset = _.options.centerMode === true ? _.slideWidth * Math.floor(_.options.slidesToShow / 2) : 0; + centerOffset = _.options.centerMode === true ? Math.floor(_.$list.width() / 2) : 0; + swipeTarget = (_.swipeLeft * -1) + centerOffset; if (_.options.swipeToSlide === true) { + _.$slideTrack.find('.slick-slide').each(function(index, slide) { - if (slide.offsetLeft - centerOffset + ($(slide).outerWidth() / 2) > (_.swipeLeft * -1)) { + + var slideOuterWidth, slideOffset, slideRightBoundary; + slideOuterWidth = $(slide).outerWidth(); + slideOffset = slide.offsetLeft; + if (_.options.centerMode !== true) { + slideOffset += (slideOuterWidth / 2); + } + + slideRightBoundary = slideOffset + (slideOuterWidth); + + if (swipeTarget < slideRightBoundary) { swipedSlide = slide; return false; } @@ -1200,6 +1305,8 @@ $(this).find("a").first().attr({ _.initializeEvents(); _.updateArrows(); _.updateDots(); + _.checkResponsive(true); + _.focusHandler(); } @@ -1211,6 +1318,81 @@ $(this).find("a").first().attr({ _.initADA(); } + if ( _.options.autoplay ) { + + _.paused = false; + _.autoPlay(); + + } + + }; + + Slick.prototype.initADA = function() { + var _ = this, + numDotGroups = Math.ceil(_.slideCount / _.options.slidesToScroll), + tabControlIndexes = _.getNavigableIndexes().filter(function(val) { + return (val >= 0) && (val < _.slideCount); + }); + + _.$slides.add(_.$slideTrack.find('.slick-cloned')).attr({ + 'aria-hidden': 'true', + 'tabindex': '-1' + }).find('a, input, button, select').attr({ + 'tabindex': '-1' + }); + + if (_.$dots !== null) { + _.$slides.not(_.$slideTrack.find('.slick-cloned')).each(function(i) { + var slideControlIndex = tabControlIndexes.indexOf(i); + + $(this).attr({ + 'role': 'tabpanel', + 'id': 'slick-slide' + _.instanceUid + i, + 'tabindex': -1 + }); + + if (slideControlIndex !== -1) { + var ariaButtonControl = 'slick-slide-control' + _.instanceUid + slideControlIndex; + if ($('#' + ariaButtonControl).length) { + $(this).attr({ + 'aria-describedby': ariaButtonControl + }); + } + } + }); + + _.$dots.attr('role', 'tablist').find('li').each(function(i) { + var mappedSlideIndex = tabControlIndexes[i]; + + $(this).attr({ + 'role': 'presentation' + }); + + $(this).find('button').first().attr({ + 'role': 'tab', + 'id': 'slick-slide-control' + _.instanceUid + i, + 'aria-controls': 'slick-slide' + _.instanceUid + mappedSlideIndex, + 'aria-label': (i + 1) + ' / ' + numDotGroups, + 'aria-selected': null, + 'tabindex': '-1' + }); + + }).eq(_.currentSlide).find('button').attr({ + 'aria-selected': 'true', + 'tabindex': '0' + }).end(); + } + + for (var i=_.currentSlide, max=i+_.options.slidesToShow; i < max; i++) { + if (_.options.focusOnChange) { + _.$slides.eq(i).attr({'tabindex': '0'}); + } else { + _.$slides.eq(i).removeAttr('tabindex'); + } + } + + _.activateADA(); + }; Slick.prototype.initArrowEvents = function() { @@ -1218,12 +1400,21 @@ $(this).find("a").first().attr({ var _ = this; if (_.options.arrows === true && _.slideCount > _.options.slidesToShow) { - _.$prevArrow.on('click.slick', { - message: 'previous' - }, _.changeSlide); - _.$nextArrow.on('click.slick', { - message: 'next' - }, _.changeSlide); + _.$prevArrow + .off('click.slick') + .on('click.slick', { + message: 'previous' + }, _.changeSlide); + _.$nextArrow + .off('click.slick') + .on('click.slick', { + message: 'next' + }, _.changeSlide); + + if (_.options.accessibility === true) { + _.$prevArrow.on('keydown.slick', _.keyHandler); + _.$nextArrow.on('keydown.slick', _.keyHandler); + } } }; @@ -1236,12 +1427,31 @@ $(this).find("a").first().attr({ $('li', _.$dots).on('click.slick', { message: 'index' }, _.changeSlide); + + if (_.options.accessibility === true) { + _.$dots.on('keydown.slick', _.keyHandler); + } } - if (_.options.dots === true && _.options.pauseOnDotsHover === true && _.options.autoplay === true) { + if (_.options.dots === true && _.options.pauseOnDotsHover === true && _.slideCount > _.options.slidesToShow) { + $('li', _.$dots) - .on('mouseenter.slick', $.proxy(_.setPaused, _, true)) - .on('mouseleave.slick', $.proxy(_.setPaused, _, false)); + .on('mouseenter.slick', $.proxy(_.interrupt, _, true)) + .on('mouseleave.slick', $.proxy(_.interrupt, _, false)); + + } + + }; + + Slick.prototype.initSlideEvents = function() { + + var _ = this; + + if ( _.options.pauseOnHover ) { + + _.$list.on('mouseenter.slick', $.proxy(_.interrupt, _, true)); + _.$list.on('mouseleave.slick', $.proxy(_.interrupt, _, false)); + } }; @@ -1253,6 +1463,7 @@ $(this).find("a").first().attr({ _.initArrowEvents(); _.initDotEvents(); + _.initSlideEvents(); _.$list.on('touchstart.slick mousedown.slick', { action: 'start' @@ -1271,9 +1482,6 @@ $(this).find("a").first().attr({ $(document).on(_.visibilityChange, $.proxy(_.visibility, _)); - _.$list.on('mouseenter.slick', $.proxy(_.setPaused, _, true)); - _.$list.on('mouseleave.slick', $.proxy(_.setPaused, _, false)); - if (_.options.accessibility === true) { _.$list.on('keydown.slick', _.keyHandler); } @@ -1289,7 +1497,7 @@ $(this).find("a").first().attr({ $('[draggable!=true]', _.$slideTrack).on('dragstart', _.preventDefault); $(window).on('load.slick.slick-' + _.instanceUid, _.setPosition); - $(document).on('ready.slick.slick-' + _.instanceUid, _.setPosition); + $(_.setPosition); }; @@ -1310,12 +1518,6 @@ $(this).find("a").first().attr({ } - if (_.options.autoplay === true) { - - _.autoPlay(); - - } - }; Slick.prototype.keyHandler = function(event) { @@ -1326,13 +1528,13 @@ $(this).find("a").first().attr({ if (event.keyCode === 37 && _.options.accessibility === true) { _.changeSlide({ data: { - message: 'previous' + message: _.options.rtl === true ? 'next' : 'previous' } }); } else if (event.keyCode === 39 && _.options.accessibility === true) { _.changeSlide({ data: { - message: 'next' + message: _.options.rtl === true ? 'previous' : 'next' } }); } @@ -1346,28 +1548,57 @@ $(this).find("a").first().attr({ loadRange, cloneRange, rangeStart, rangeEnd; function loadImages(imagesScope) { + $('img[data-lazy]', imagesScope).each(function() { var image = $(this), imageSource = $(this).attr('data-lazy'), + imageSrcSet = $(this).attr('data-srcset'), + imageSizes = $(this).attr('data-sizes') || _.$slider.attr('data-sizes'), imageToLoad = document.createElement('img'); imageToLoad.onload = function() { + image .animate({ opacity: 0 }, 100, function() { + + if (imageSrcSet) { + image + .attr('srcset', imageSrcSet ); + + if (imageSizes) { + image + .attr('sizes', imageSizes ); + } + } + image .attr('src', imageSource) .animate({ opacity: 1 }, 200, function() { image - .removeAttr('data-lazy') + .removeAttr('data-lazy data-srcset data-sizes') .removeClass('slick-loading'); }); + _.$slider.trigger('lazyLoaded', [_, image, imageSource]); }); + + }; + + imageToLoad.onerror = function() { + + image + .removeAttr( 'data-lazy' ) + .removeClass( 'slick-loading' ) + .addClass( 'slick-lazyload-error' ); + + _.$slider.trigger('lazyLoadError', [ _, image, imageSource ]); + }; imageToLoad.src = imageSource; }); + } if (_.options.centerMode === true) { @@ -1380,7 +1611,7 @@ $(this).find("a").first().attr({ } } else { rangeStart = _.options.infinite ? _.options.slidesToShow + _.currentSlide : _.currentSlide; - rangeEnd = rangeStart + _.options.slidesToShow; + rangeEnd = Math.ceil(rangeStart + _.options.slidesToShow); if (_.options.fade === true) { if (rangeStart > 0) rangeStart--; if (rangeEnd <= _.slideCount) rangeEnd++; @@ -1388,6 +1619,21 @@ $(this).find("a").first().attr({ } loadRange = _.$slider.find('.slick-slide').slice(rangeStart, rangeEnd); + + if (_.options.lazyLoad === 'anticipated') { + var prevSlide = rangeStart - 1, + nextSlide = rangeEnd, + $slides = _.$slider.find('.slick-slide'); + + for (var i = 0; i < _.options.slidesToScroll; i++) { + if (prevSlide < 0) prevSlide = _.slideCount - 1; + loadRange = loadRange.add($slides.eq(prevSlide)); + loadRange = loadRange.add($slides.eq(nextSlide)); + prevSlide--; + nextSlide++; + } + } + loadImages(loadRange); if (_.slideCount <= _.options.slidesToShow) { @@ -1411,7 +1657,7 @@ $(this).find("a").first().attr({ _.setPosition(); _.$slideTrack.css({ - opacity: 1 + opacity: '1' }); _.$slider.removeClass('slick-loading'); @@ -1458,8 +1704,11 @@ $(this).find("a").first().attr({ var _ = this; - _.paused = false; _.autoPlay(); + _.options.autoplay = true; + _.paused = false; + _.focussed = false; + _.interrupted = false; }; @@ -1467,19 +1716,31 @@ $(this).find("a").first().attr({ var _ = this; - _.$slider.trigger('afterChange', [_, index]); + if( !_.unslicked ) { - _.animating = false; + _.$slider.trigger('afterChange', [_, index]); - _.setPosition(); + _.animating = false; - _.swipeLeft = null; + if (_.slideCount > _.options.slidesToShow) { + _.setPosition(); + } + + _.swipeLeft = null; + + if ( _.options.autoplay ) { + _.autoPlay(); + } + + if (_.options.accessibility === true) { + _.initADA(); + + if (_.options.focusOnChange) { + var $currentSlide = $(_.$slides.get(_.currentSlide)); + $currentSlide.attr('tabindex', 0).trigger('focus'); + } + } - if (_.options.autoplay === true && _.paused === false) { - _.autoPlay(); - } - if (_.options.accessibility === true) { - _.initADA(); } }; @@ -1496,39 +1757,115 @@ $(this).find("a").first().attr({ }; - Slick.prototype.preventDefault = function(e) { - e.preventDefault(); + Slick.prototype.preventDefault = function(event) { + + event.preventDefault(); + }; - Slick.prototype.progressiveLazyLoad = function() { + Slick.prototype.progressiveLazyLoad = function( tryCount ) { + + tryCount = tryCount || 1; var _ = this, - imgCount, targetImage; + $imgsToLoad = $( 'img[data-lazy]', _.$slider ), + image, + imageSource, + imageSrcSet, + imageSizes, + imageToLoad; - imgCount = $('img[data-lazy]', _.$slider).length; + if ( $imgsToLoad.length ) { - if (imgCount > 0) { - targetImage = $('img[data-lazy]', _.$slider).first(); - targetImage.attr('src', targetImage.attr('data-lazy')).removeClass('slick-loading').load(function() { - targetImage.removeAttr('data-lazy'); - _.progressiveLazyLoad(); + image = $imgsToLoad.first(); + imageSource = image.attr('data-lazy'); + imageSrcSet = image.attr('data-srcset'); + imageSizes = image.attr('data-sizes') || _.$slider.attr('data-sizes'); + imageToLoad = document.createElement('img'); + + imageToLoad.onload = function() { - if (_.options.adaptiveHeight === true) { - _.setPosition(); + if (imageSrcSet) { + image + .attr('srcset', imageSrcSet ); + + if (imageSizes) { + image + .attr('sizes', imageSizes ); } - }) - .error(function() { - targetImage.removeAttr('data-lazy'); + } + + image + .attr( 'src', imageSource ) + .removeAttr('data-lazy data-srcset data-sizes') + .removeClass('slick-loading'); + + if ( _.options.adaptiveHeight === true ) { + _.setPosition(); + } + + _.$slider.trigger('lazyLoaded', [ _, image, imageSource ]); + _.progressiveLazyLoad(); + + }; + + imageToLoad.onerror = function() { + + if ( tryCount < 3 ) { + + /** + * try to load the image 3 times, + * leave a slight delay so we don't get + * servers blocking the request. + */ + setTimeout( function() { + _.progressiveLazyLoad( tryCount + 1 ); + }, 500 ); + + } else { + + image + .removeAttr( 'data-lazy' ) + .removeClass( 'slick-loading' ) + .addClass( 'slick-lazyload-error' ); + + _.$slider.trigger('lazyLoadError', [ _, image, imageSource ]); + _.progressiveLazyLoad(); - }); + + } + + }; + + imageToLoad.src = imageSource; + + } else { + + _.$slider.trigger('allImagesLoaded', [ _ ]); + } }; Slick.prototype.refresh = function( initializing ) { - var _ = this, - currentSlide = _.currentSlide; + var _ = this, currentSlide, lastVisibleIndex; + + lastVisibleIndex = _.slideCount - _.options.slidesToShow; + + // in non-infinite sliders, we don't want to go past the + // last visible index. + if( !_.options.infinite && ( _.currentSlide > lastVisibleIndex )) { + _.currentSlide = lastVisibleIndex; + } + + // if less slides than to show, go to start. + if ( _.slideCount <= _.options.slidesToShow ) { + _.currentSlide = 0; + + } + + currentSlide = _.currentSlide; _.destroy(true); @@ -1554,16 +1891,16 @@ $(this).find("a").first().attr({ var _ = this, breakpoint, currentBreakpoint, l, responsiveSettings = _.options.responsive || null; - if ( $.type(responsiveSettings) === "array" && responsiveSettings.length ) { + if ( Array.isArray(responsiveSettings) && responsiveSettings.length ) { _.respondTo = _.options.respondTo || 'window'; for ( breakpoint in responsiveSettings ) { l = _.breakpoints.length-1; - currentBreakpoint = responsiveSettings[breakpoint].breakpoint; if (responsiveSettings.hasOwnProperty(breakpoint)) { + currentBreakpoint = responsiveSettings[breakpoint].breakpoint; // loop through the breakpoints and cut out any existing // ones with the same breakpoint number, we don't want dupes. @@ -1618,6 +1955,8 @@ $(this).find("a").first().attr({ _.buildDots(); _.updateDots(); _.initDotEvents(); + _.cleanUpSlideEvents(); + _.initSlideEvents(); _.checkResponsive(false, true); @@ -1625,15 +1964,15 @@ $(this).find("a").first().attr({ $(_.$slideTrack).children().on('click.slick', _.selectHandler); } - _.setSlideClasses(0); + _.setSlideClasses(typeof _.currentSlide === 'number' ? _.currentSlide : 0); _.setPosition(); + _.focusHandler(); - _.$slider.trigger('reInit', [_]); + _.paused = !_.options.autoplay; + _.autoPlay(); - if (_.options.autoplay === true) { - _.focusHandler(); - } + _.$slider.trigger('reInit', [_]); }; @@ -1765,24 +2104,24 @@ $(this).find("a").first().attr({ $(element).css({ position: 'relative', right: targetLeft, - top: 0, + top: '0', zIndex: _.options.zIndex - 2, - opacity: 0 + opacity: '0' }); } else { $(element).css({ position: 'relative', left: targetLeft, - top: 0, + top: '0', zIndex: _.options.zIndex - 2, - opacity: 0 + opacity: '0' }); } }); _.$slides.eq(_.currentSlide).css({ zIndex: _.options.zIndex - 1, - opacity: 1 + opacity: '1' }); }; @@ -1793,38 +2132,105 @@ $(this).find("a").first().attr({ if (_.options.slidesToShow === 1 && _.options.adaptiveHeight === true && _.options.vertical === false) { var targetHeight = _.$slides.eq(_.currentSlide).outerHeight(true); - _.$list.css('height', targetHeight); + _.$list.css('height', targetHeight + 'px'); } }; - Slick.prototype.setOption = Slick.prototype.slickSetOption = function(option, value, refresh) { + Slick.prototype.setOption = + Slick.prototype.slickSetOption = function() { + + /** + * accepts arguments in format of: + * + * - for changing a single option's value: + * .slick("setOption", option, value, refresh ) + * + * - for changing a set of responsive options: + * .slick("setOption", 'responsive', [{}, ...], refresh ) + * + * - for updating multiple values at once (not responsive) + * .slick("setOption", { 'option': value, ... }, refresh ) + */ + + var _ = this, l, item, option, value, refresh = false, type; + + if( $.isPlainObject( arguments[0] ) ) { + + option = arguments[0]; + refresh = arguments[1]; + type = 'multiple'; + + } else if ( typeof arguments[0] === 'string' ) { + + option = arguments[0]; + value = arguments[1]; + refresh = arguments[2]; + + if ( arguments[0] === 'responsive' && Array.isArray( arguments[1] ) ) { + + type = 'responsive'; + + } else if ( typeof arguments[1] !== 'undefined' ) { + + type = 'single'; + + } + + } + + if ( type === 'single' ) { + + _.options[option] = value; + + + } else if ( type === 'multiple' ) { + + $.each( option , function( opt, val ) { + + _.options[opt] = val; + + }); - var _ = this, l, item; - if( option === "responsive" && $.type(value) === "array" ) { + } else if ( type === 'responsive' ) { + for ( item in value ) { - if( $.type( _.options.responsive ) !== "array" ) { + + if( !Array.isArray( _.options.responsive ) ) { + _.options.responsive = [ value[item] ]; + } else { + l = _.options.responsive.length-1; + // loop through the responsive object and splice out duplicates. while( l >= 0 ) { + if( _.options.responsive[l].breakpoint === value[item].breakpoint ) { + _.options.responsive.splice(l,1); + } + l--; + } + _.options.responsive.push( value[item] ); + } + } - } else { - _.options[option] = value; + } - if (refresh === true) { + if ( refresh ) { + _.unload(); _.reinit(); + } }; @@ -1907,8 +2313,7 @@ $(this).find("a").first().attr({ _.transformType = 'transform'; _.transitionType = 'transition'; } - _.transformsEnabled = (_.animType !== null && _.animType !== false); - + _.transformsEnabled = _.options.useTransform && (_.animType !== null && _.animType !== false); }; @@ -1928,14 +2333,21 @@ $(this).find("a").first().attr({ if (_.options.centerMode === true) { - centerOffset = Math.floor(_.options.slidesToShow / 2); + var evenCoef; + + if (_.options.slidesToShow >= _.$slides.length) { + evenCoef = -1; + centerOffset = _.options.slidesToShow = _.$slides.length; + } else { + evenCoef = _.options.slidesToShow % 2 === 0 ? 1 : 0; + centerOffset = Math.floor(_.options.slidesToShow / 2); + } if (_.options.infinite === true) { if (index >= centerOffset && index <= (_.slideCount - 1) - centerOffset) { - _.$slides - .slice(index - centerOffset, index + centerOffset + 1) + .slice(index - centerOffset + evenCoef, index + centerOffset + 1) .addClass('slick-active') .attr('aria-hidden', 'false'); @@ -1943,7 +2355,7 @@ $(this).find("a").first().attr({ indexOffset = _.options.slidesToShow + index; allSlides - .slice(indexOffset - centerOffset + 1, indexOffset + centerOffset + 2) + .slice(indexOffset - centerOffset + 1 + evenCoef, indexOffset + centerOffset + 2) .addClass('slick-active') .attr('aria-hidden', 'false'); @@ -1952,7 +2364,7 @@ $(this).find("a").first().attr({ if (index === 0) { allSlides - .eq(allSlides.length - 1 - _.options.slidesToShow) + .eq( _.options.slidesToShow + _.slideCount + 1 ) .addClass('slick-center'); } else if (index === _.slideCount - 1) { @@ -2009,10 +2421,9 @@ $(this).find("a").first().attr({ } - if (_.options.lazyLoad === 'ondemand') { + if (_.options.lazyLoad === 'ondemand' || _.options.lazyLoad === 'anticipated') { _.lazyLoad(); } - }; Slick.prototype.setupInfinite = function() { @@ -2039,18 +2450,18 @@ $(this).find("a").first().attr({ for (i = _.slideCount; i > (_.slideCount - infiniteCount); i -= 1) { slideIndex = i - 1; - $(_.$slides[slideIndex]).clone(true).attr('id', '') + $(_.$slides[slideIndex]).clone(true).removeAttr('id') .attr('data-slick-index', slideIndex - _.slideCount) .prependTo(_.$slideTrack).addClass('slick-cloned'); } - for (i = 0; i < infiniteCount; i += 1) { + for (i = 0; i < infiniteCount + _.slideCount; i += 1) { slideIndex = i; - $(_.$slides[slideIndex]).clone(true).attr('id', '') + $(_.$slides[slideIndex]).clone(true).removeAttr('id') .attr('data-slick-index', slideIndex + _.slideCount) .appendTo(_.$slideTrack).addClass('slick-cloned'); } _.$slideTrack.find('.slick-cloned').find('[id]').each(function() { - $(this).attr('id', ''); + $(this).removeAttr('id'); }); } @@ -2059,18 +2470,15 @@ $(this).find("a").first().attr({ }; - Slick.prototype.setPaused = function(paused) { + Slick.prototype.interrupt = function( toggle ) { var _ = this; - if (_.options.autoplay === true && _.options.pauseOnHover === true) { - _.paused = paused; - if (!paused) { - _.autoPlay(); - } else { - _.autoPlayClear(); - } + if( !toggle ) { + _.autoPlay(); } + _.interrupted = toggle; + }; Slick.prototype.selectHandler = function(event) { @@ -2088,8 +2496,7 @@ $(this).find("a").first().attr({ if (_.slideCount <= _.options.slidesToShow) { - _.setSlideClasses(index); - _.asNavFor(index); + _.slideHandler(index, false, true); return; } @@ -2101,7 +2508,7 @@ $(this).find("a").first().attr({ Slick.prototype.slideHandler = function(index, sync, dontAnimate) { var targetSlide, animSlide, oldSlide, slideLeft, targetLeft = null, - _ = this; + _ = this, navTarget; sync = sync || false; @@ -2113,10 +2520,6 @@ $(this).find("a").first().attr({ return; } - if (_.slideCount <= _.options.slidesToShow) { - return; - } - if (sync === false) { _.asNavFor(index); } @@ -2130,7 +2533,7 @@ $(this).find("a").first().attr({ if (_.options.infinite === false && _.options.centerMode === false && (index < 0 || index > _.getDotCount() * _.options.slidesToScroll)) { if (_.options.fade === false) { targetSlide = _.currentSlide; - if (dontAnimate !== true) { + if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) { _.animateSlide(slideLeft, function() { _.postSlide(targetSlide); }); @@ -2142,7 +2545,7 @@ $(this).find("a").first().attr({ } else if (_.options.infinite === false && _.options.centerMode === true && (index < 0 || index > (_.slideCount - _.options.slidesToScroll))) { if (_.options.fade === false) { targetSlide = _.currentSlide; - if (dontAnimate !== true) { + if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) { _.animateSlide(slideLeft, function() { _.postSlide(targetSlide); }); @@ -2153,7 +2556,7 @@ $(this).find("a").first().attr({ return; } - if (_.options.autoplay === true) { + if ( _.options.autoplay ) { clearInterval(_.autoPlayTimer); } @@ -2182,6 +2585,17 @@ $(this).find("a").first().attr({ _.setSlideClasses(_.currentSlide); + if ( _.options.asNavFor ) { + + navTarget = _.getNavTarget(); + navTarget = navTarget.slick('getSlick'); + + if ( navTarget.slideCount <= navTarget.options.slidesToShow ) { + navTarget.setSlideClasses(_.currentSlide); + } + + } + _.updateDots(); _.updateArrows(); @@ -2201,7 +2615,7 @@ $(this).find("a").first().attr({ return; } - if (dontAnimate !== true) { + if (dontAnimate !== true && _.slideCount > _.options.slidesToShow) { _.animateSlide(targetLeft, function() { _.postSlide(animSlide); }); @@ -2256,9 +2670,9 @@ $(this).find("a").first().attr({ } if (_.options.verticalSwiping === true) { if ((swipeAngle >= 35) && (swipeAngle <= 135)) { - return 'left'; + return 'down'; } else { - return 'right'; + return 'up'; } } @@ -2269,44 +2683,80 @@ $(this).find("a").first().attr({ Slick.prototype.swipeEnd = function(event) { var _ = this, - slideCount; + slideCount, + direction; _.dragging = false; + _.swiping = false; + + if (_.scrolling) { + _.scrolling = false; + return false; + } - _.shouldClick = (_.touchObject.swipeLength > 10) ? false : true; + _.interrupted = false; + _.shouldClick = ( _.touchObject.swipeLength > 10 ) ? false : true; - if (_.touchObject.curX === undefined) { + if ( _.touchObject.curX === undefined ) { return false; } - if (_.touchObject.edgeHit === true) { - _.$slider.trigger('edge', [_, _.swipeDirection()]); + if ( _.touchObject.edgeHit === true ) { + _.$slider.trigger('edge', [_, _.swipeDirection() ]); } - if (_.touchObject.swipeLength >= _.touchObject.minSwipe) { + if ( _.touchObject.swipeLength >= _.touchObject.minSwipe ) { + + direction = _.swipeDirection(); + + switch ( direction ) { - switch (_.swipeDirection()) { case 'left': - slideCount = _.options.swipeToSlide ? _.checkNavigable(_.currentSlide + _.getSlideCount()) : _.currentSlide + _.getSlideCount(); - _.slideHandler(slideCount); + case 'down': + + slideCount = + _.options.swipeToSlide ? + _.checkNavigable( _.currentSlide + _.getSlideCount() ) : + _.currentSlide + _.getSlideCount(); + _.currentDirection = 0; - _.touchObject = {}; - _.$slider.trigger('swipe', [_, 'left']); + break; case 'right': - slideCount = _.options.swipeToSlide ? _.checkNavigable(_.currentSlide - _.getSlideCount()) : _.currentSlide - _.getSlideCount(); - _.slideHandler(slideCount); + case 'up': + + slideCount = + _.options.swipeToSlide ? + _.checkNavigable( _.currentSlide - _.getSlideCount() ) : + _.currentSlide - _.getSlideCount(); + _.currentDirection = 1; - _.touchObject = {}; - _.$slider.trigger('swipe', [_, 'right']); + break; + + default: + + } + + if( direction != 'vertical' ) { + + _.slideHandler( slideCount ); + _.touchObject = {}; + _.$slider.trigger('swipe', [_, direction ]); + + } + } else { - if (_.touchObject.startX !== _.touchObject.curX) { - _.slideHandler(_.currentSlide); + + if ( _.touchObject.startX !== _.touchObject.curX ) { + + _.slideHandler( _.currentSlide ); _.touchObject = {}; + } + } }; @@ -2354,11 +2804,11 @@ $(this).find("a").first().attr({ var _ = this, edgeWasHit = false, - curLeft, swipeDirection, swipeLength, positionOffset, touches; + curLeft, swipeDirection, swipeLength, positionOffset, touches, verticalSwipeLength; touches = event.originalEvent !== undefined ? event.originalEvent.touches : null; - if (!_.dragging || touches && touches.length !== 1) { + if (!_.dragging || _.scrolling || touches && touches.length !== 1) { return false; } @@ -2370,18 +2820,22 @@ $(this).find("a").first().attr({ _.touchObject.swipeLength = Math.round(Math.sqrt( Math.pow(_.touchObject.curX - _.touchObject.startX, 2))); + verticalSwipeLength = Math.round(Math.sqrt( + Math.pow(_.touchObject.curY - _.touchObject.startY, 2))); + + if (!_.options.verticalSwiping && !_.swiping && verticalSwipeLength > 4) { + _.scrolling = true; + return false; + } + if (_.options.verticalSwiping === true) { - _.touchObject.swipeLength = Math.round(Math.sqrt( - Math.pow(_.touchObject.curY - _.touchObject.startY, 2))); + _.touchObject.swipeLength = verticalSwipeLength; } swipeDirection = _.swipeDirection(); - if (swipeDirection === 'vertical') { - return; - } - if (event.originalEvent !== undefined && _.touchObject.swipeLength > 4) { + _.swiping = true; event.preventDefault(); } @@ -2429,6 +2883,8 @@ $(this).find("a").first().attr({ var _ = this, touches; + _.interrupted = true; + if (_.touchObject.fingerCount !== 1 || _.slideCount <= _.options.slidesToShow) { _.touchObject = {}; return false; @@ -2539,102 +2995,36 @@ $(this).find("a").first().attr({ _.$dots .find('li') - .removeClass('slick-active') - .attr('aria-hidden', 'true'); + .removeClass('slick-active') + .end(); _.$dots .find('li') .eq(Math.floor(_.currentSlide / _.options.slidesToScroll)) - .addClass('slick-active') - .attr('aria-hidden', 'false'); + .addClass('slick-active'); + } + }; Slick.prototype.visibility = function() { var _ = this; - if (document[_.hidden]) { - _.paused = true; - _.autoPlayClear(); - } else { - if (_.options.autoplay === true) { - _.paused = false; - _.autoPlay(); - } - } - }; - Slick.prototype.initADA = function() { - var _ = this; - _.$slides.add(_.$slideTrack.find('.slick-cloned')).attr({ - 'aria-hidden': 'true', - 'tabindex': '-1' - }).find('a, input, button, select').attr({ - 'tabindex': '-1' - }); - - _.$slides.not(_.$slideTrack.find('.slick-cloned')).each(function(i) { - $(this).attr({ - 'role': 'tabpanel', - 'aria-labelledby': 'slick-slide' + _.instanceUid + i + '' - }); - $(this).find("h3").first().attr({ - 'id': 'slick-slide' + _.instanceUid + i + '' - }) - $(this).find("a").first().attr({ - 'aria-labelledby': 'slick-slide' + _.instanceUid + i + '' - }) - }); + if ( _.options.autoplay ) { - if (_.$dots !== null) { - _.$dots.attr('role', 'tablist').find('li').each(function(i) { - $(this).attr({ - 'role': 'presentation', - 'aria-selected': 'false', - 'aria-controls': 'navigation' + _.instanceUid + i + '', - 'id': 'slick-slide' + _.instanceUid + i + '' - }); - }) - .first().attr('aria-selected', 'true').end() - .find('button').attr('role', 'button').end() - .closest('div').attr('role', 'toolbar'); - } - _.activateADA(); + if ( document[_.hidden] ) { - }; + _.interrupted = true; - Slick.prototype.activateADA = function() { - var _ = this, - _isSlideOnFocus =_.$slider.find('*').is(':focus'); - // _isSlideOnFocus = _.$slides.is(':focus') || _.$slides.find('*').is(':focus'); + } else { - _.$slideTrack.find('.slick-active').attr({ - 'aria-hidden': 'false' - }).find('a, input, button, select').attr({ - 'tabindex': '0' - }); + _.interrupted = false; - (_isSlideOnFocus) && _.$slideTrack.find('.slick-active').focus(); + } - }; + } - Slick.prototype.focusHandler = function() { - var _ = this; - _.$slider.on('focus.slick blur.slick', '*', function(event) { - event.stopImmediatePropagation(); - var sf = $(this); - setTimeout(function() { - if (_.isPlay) { - if (sf.is(':focus')) { - _.autoPlayClear(); - _.paused = true; - } else { - _.paused = false; - _.autoPlay(); - } - } - }, 0); - }); }; $.fn.slick = function() { @@ -2642,9 +3032,9 @@ $(this).find("a").first().attr({ opt = arguments[0], args = Array.prototype.slice.call(arguments, 1), l = _.length, - i = 0, + i, ret; - for (i; i < l; i++) { + for (i = 0; i < l; i++) { if (typeof opt == 'object' || typeof opt == 'undefined') _[i].slick = new Slick(_[i], opt); else @@ -2654,4 +3044,4 @@ $(this).find("a").first().attr({ return _; }; -})); \ No newline at end of file +})); diff --git a/ckanext/showcase/templates/home/snippets/showcase_list.html b/ckanext/showcase/templates/home/snippets/showcase_list.html index 60d5cbef..684a3b34 100644 --- a/ckanext/showcase/templates/home/snippets/showcase_list.html +++ b/ckanext/showcase/templates/home/snippets/showcase_list.html @@ -31,6 +31,7 @@ autoplay: false, autoplaySpeed: 5000, lazyLoad: 'ondemand', + rows: 0, slidesToShow: 4, slidesToScroll: 4, responsive: [ From 35740f8549953630e423373fff5c95ffd7f7b75d Mon Sep 17 00:00:00 2001 From: Jay Guo Date: Thu, 26 Feb 2026 11:13:24 -0500 Subject: [PATCH 2/2] Fix CI SonarQube error --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3ab47030..32d8d942 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -69,7 +69,7 @@ jobs: run: pytest --ckan-ini=test.ini --cov=ckanext.showcase --cov-report=term-missing --cov-append --disable-warnings ckanext/showcase/tests - name: Install unzip for SonarQube and cov - run: apt-get -y install unzip curl + run: apt-get update && apt-get -y install unzip curl - name: SonarQube Scan uses: sonarsource/sonarqube-scan-action@master