From 9880900d8e46f14fd828e475f3c5625b06b7bd3b Mon Sep 17 00:00:00 2001 From: mamzellejuu Date: Wed, 7 Dec 2016 10:17:34 -0500 Subject: [PATCH 1/2] fix the event binding problem for afterChange. The slick afterChange event was triggered before the binding --- app/scripts/app.coffee | 26 ++++++++++++++++++-------- dist/slick.js | 33 ++++++++++++++++++++++----------- dist/slick.min.js | 4 ++-- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/app/scripts/app.coffee b/app/scripts/app.coffee index f10dd50..1549172 100644 --- a/app/scripts/app.coffee +++ b/app/scripts/app.coffee @@ -67,6 +67,24 @@ angular.module('slick', []) customPaging = (slick, index) -> scope.customPaging({ slick: slick, index: index }) + slider.on 'afterChange', (event, slick, currentSlide, nextSlide) -> + scope.onAfterChange() if scope.onAfterChange + + if currentIndex? + scope.$apply(-> + currentIndex = currentSlide + scope.currentIndex = currentSlide + ) + + slider.on 'afterChange', (event, slick, currentSlide, nextSlide) -> + scope.onAfterChange() if scope.onAfterChange + + if currentIndex? + scope.$apply(-> + currentIndex = currentSlide + scope.currentIndex = currentSlide + ) + slider.slick accessibility: scope.accessibility isnt "false" adaptiveHeight: scope.adaptiveHeight is "true" @@ -114,14 +132,6 @@ angular.module('slick', []) if currentIndex? sl.slideHandler(currentIndex) - slider.on 'afterChange', (event, slick, currentSlide, nextSlide) -> - scope.onAfterChange() if scope.onAfterChange - - if currentIndex? - scope.$apply(-> - currentIndex = currentSlide - scope.currentIndex = currentSlide - ) scope.$watch("currentIndex", (newVal, oldVal) -> if currentIndex? and newVal? and newVal != currentIndex diff --git a/dist/slick.js b/dist/slick.js index e9da126..cbc27f7 100644 --- a/dist/slick.js +++ b/dist/slick.js @@ -75,6 +75,28 @@ angular.module('slick', []).directive('slick', [ index: index }); }; + slider.on('afterChange', function (event, slick, currentSlide, nextSlide) { + if (scope.onAfterChange) { + scope.onAfterChange(); + } + if (currentIndex != null) { + return scope.$apply(function () { + currentIndex = currentSlide; + return scope.currentIndex = currentSlide; + }); + } + }); + slider.on('afterChange', function (event, slick, currentSlide, nextSlide) { + if (scope.onAfterChange) { + scope.onAfterChange(); + } + if (currentIndex != null) { + return scope.$apply(function () { + currentIndex = currentSlide; + return scope.currentIndex = currentSlide; + }); + } + }); slider.slick({ accessibility: scope.accessibility !== 'false', adaptiveHeight: scope.adaptiveHeight === 'true', @@ -124,17 +146,6 @@ angular.module('slick', []).directive('slick', [ return sl.slideHandler(currentIndex); } }); - slider.on('afterChange', function (event, slick, currentSlide, nextSlide) { - if (scope.onAfterChange) { - scope.onAfterChange(); - } - if (currentIndex != null) { - return scope.$apply(function () { - currentIndex = currentSlide; - return scope.currentIndex = currentSlide; - }); - } - }); return scope.$watch('currentIndex', function (newVal, oldVal) { if (currentIndex != null && newVal != null && newVal !== currentIndex) { return slider.slick('slickGoTo', newVal); diff --git a/dist/slick.min.js b/dist/slick.min.js index 0b74254..bd1fc85 100644 --- a/dist/slick.min.js +++ b/dist/slick.min.js @@ -1,2 +1,2 @@ -/*! angular-slick v0.2.0 */ -"use strict";angular.module("slick",[]).directive("slick",["$timeout",function(a){return{restrict:"AEC",scope:{initOnload:"@",data:"=",currentIndex:"=",accessibility:"@",adaptiveHeight:"@",arrows:"@",asNavFor:"@",appendArrows:"@",appendDots:"@",autoplay:"@",autoplaySpeed:"@",centerMode:"@",centerPadding:"@",cssEase:"@",customPaging:"&",dots:"@",draggable:"@",easing:"@",fade:"@",focusOnSelect:"@",infinite:"@",initialSlide:"@",lazyLoad:"@",onBeforeChange:"&",onAfterChange:"&",onInit:"&",onReInit:"&",onSetPosition:"&",pauseOnHover:"@",pauseOnDotsHover:"@",responsive:"=",rtl:"@",slide:"@",slidesToShow:"@",slidesToScroll:"@",speed:"@",swipe:"@",swipeToSlide:"@",touchMove:"@",touchThreshold:"@",useCSS:"@",variableWidth:"@",vertical:"@",prevArrow:"@",nextArrow:"@"},link:function(b,c,d){var e,f,g;return e=function(){return a(function(){var a;return a=$(c),a.slick("unslick"),a.find(".slick-list").remove(),a})},f=function(){return a(function(){var a,e,f;return f=$(c),null!=b.currentIndex&&(a=b.currentIndex),e=function(a,c){return b.customPaging({slick:a,index:c})},f.slick({accessibility:"false"!==b.accessibility,adaptiveHeight:"true"===b.adaptiveHeight,arrows:"false"!==b.arrows,asNavFor:b.asNavFor?b.asNavFor:void 0,appendArrows:$(b.appendArrows?b.appendArrows:c),appendDots:$(b.appendDots?b.appendDots:c),autoplay:"true"===b.autoplay,autoplaySpeed:null!=b.autoplaySpeed?parseInt(b.autoplaySpeed,10):3e3,centerMode:"true"===b.centerMode,centerPadding:b.centerPadding||"50px",cssEase:b.cssEase||"ease",customPaging:d.customPaging?e:void 0,dots:"true"===b.dots,draggable:"false"!==b.draggable,easing:b.easing||"linear",fade:"true"===b.fade,focusOnSelect:"true"===b.focusOnSelect,infinite:"false"!==b.infinite,initialSlide:b.initialSlide||0,lazyLoad:b.lazyLoad||"ondemand",beforeChange:d.onBeforeChange?b.onBeforeChange:void 0,onReInit:d.onReInit?b.onReInit:void 0,onSetPosition:d.onSetPosition?b.onSetPosition:void 0,pauseOnHover:"false"!==b.pauseOnHover,responsive:b.responsive||void 0,rtl:"true"===b.rtl,slide:b.slide||"div",slidesToShow:null!=b.slidesToShow?parseInt(b.slidesToShow,10):1,slidesToScroll:null!=b.slidesToScroll?parseInt(b.slidesToScroll,10):1,speed:null!=b.speed?parseInt(b.speed,10):300,swipe:"false"!==b.swipe,swipeToSlide:"true"===b.swipeToSlide,touchMove:"false"!==b.touchMove,touchThreshold:b.touchThreshold?parseInt(b.touchThreshold,10):5,useCSS:"false"!==b.useCSS,variableWidth:"true"===b.variableWidth,vertical:"true"===b.vertical,prevArrow:b.prevArrow?$(b.prevArrow):void 0,nextArrow:b.nextArrow?$(b.nextArrow):void 0}),f.on("init",function(c){return d.onInit&&b.onInit(),null!=a?c.slideHandler(a):void 0}),f.on("afterChange",function(c,d,e){return b.onAfterChange&&b.onAfterChange(),null!=a?b.$apply(function(){return a=e,b.currentIndex=e}):void 0}),b.$watch("currentIndex",function(b){return null!=a&&null!=b&&b!==a?f.slick("slickGoTo",b):void 0})})},b.initOnload?(g=!1,b.$watch("data",function(a){return null!=a?(g&&e(),f(),g=!0):void 0})):f()}}}]); \ No newline at end of file +/*! angular-slick v0.2.1 */ +"use strict";angular.module("slick",[]).directive("slick",["$timeout",function(a){return{restrict:"AEC",scope:{initOnload:"@",data:"=",currentIndex:"=",accessibility:"@",adaptiveHeight:"@",arrows:"@",asNavFor:"@",appendArrows:"@",appendDots:"@",autoplay:"@",autoplaySpeed:"@",centerMode:"@",centerPadding:"@",cssEase:"@",customPaging:"&",dots:"@",draggable:"@",easing:"@",fade:"@",focusOnSelect:"@",infinite:"@",initialSlide:"@",lazyLoad:"@",onBeforeChange:"&",onAfterChange:"&",onInit:"&",onReInit:"&",onSetPosition:"&",pauseOnHover:"@",pauseOnDotsHover:"@",responsive:"=",rtl:"@",slide:"@",slidesToShow:"@",slidesToScroll:"@",speed:"@",swipe:"@",swipeToSlide:"@",touchMove:"@",touchThreshold:"@",useCSS:"@",variableWidth:"@",vertical:"@",prevArrow:"@",nextArrow:"@"},link:function(b,c,d){var e,f,g;return e=function(){return a(function(){var a;return a=$(c),a.slick("unslick"),a.find(".slick-list").remove(),a})},f=function(){return a(function(){var a,e,f;return f=$(c),null!=b.currentIndex&&(a=b.currentIndex),e=function(a,c){return b.customPaging({slick:a,index:c})},f.on("afterChange",function(c,d,e,f){return b.onAfterChange&&b.onAfterChange(),null!=a?b.$apply(function(){return a=e,b.currentIndex=e}):void 0}),f.on("afterChange",function(c,d,e,f){return b.onAfterChange&&b.onAfterChange(),null!=a?b.$apply(function(){return a=e,b.currentIndex=e}):void 0}),f.slick({accessibility:"false"!==b.accessibility,adaptiveHeight:"true"===b.adaptiveHeight,arrows:"false"!==b.arrows,asNavFor:b.asNavFor?b.asNavFor:void 0,appendArrows:b.appendArrows?$(b.appendArrows):$(c),appendDots:b.appendDots?$(b.appendDots):$(c),autoplay:"true"===b.autoplay,autoplaySpeed:null!=b.autoplaySpeed?parseInt(b.autoplaySpeed,10):3e3,centerMode:"true"===b.centerMode,centerPadding:b.centerPadding||"50px",cssEase:b.cssEase||"ease",customPaging:d.customPaging?e:void 0,dots:"true"===b.dots,draggable:"false"!==b.draggable,easing:b.easing||"linear",fade:"true"===b.fade,focusOnSelect:"true"===b.focusOnSelect,infinite:"false"!==b.infinite,initialSlide:b.initialSlide||0,lazyLoad:b.lazyLoad||"ondemand",beforeChange:d.onBeforeChange?b.onBeforeChange:void 0,onReInit:d.onReInit?b.onReInit:void 0,onSetPosition:d.onSetPosition?b.onSetPosition:void 0,pauseOnHover:"false"!==b.pauseOnHover,responsive:b.responsive||void 0,rtl:"true"===b.rtl,slide:b.slide||"div",slidesToShow:null!=b.slidesToShow?parseInt(b.slidesToShow,10):1,slidesToScroll:null!=b.slidesToScroll?parseInt(b.slidesToScroll,10):1,speed:null!=b.speed?parseInt(b.speed,10):300,swipe:"false"!==b.swipe,swipeToSlide:"true"===b.swipeToSlide,touchMove:"false"!==b.touchMove,touchThreshold:b.touchThreshold?parseInt(b.touchThreshold,10):5,useCSS:"false"!==b.useCSS,variableWidth:"true"===b.variableWidth,vertical:"true"===b.vertical,prevArrow:b.prevArrow?$(b.prevArrow):void 0,nextArrow:b.nextArrow?$(b.nextArrow):void 0}),f.on("init",function(c){return d.onInit&&b.onInit(),null!=a?c.slideHandler(a):void 0}),b.$watch("currentIndex",function(b,c){return null!=a&&null!=b&&b!==a?f.slick("slickGoTo",b):void 0})})},b.initOnload?(g=!1,b.$watch("data",function(a,b){return null!=a?(g&&e(),f(),g=!0):void 0})):f()}}}]); \ No newline at end of file From 4771e3e6b852c282d15239a02b97e2b4d62a8d12 Mon Sep 17 00:00:00 2001 From: mamzellejuu Date: Wed, 7 Dec 2016 12:37:43 -0500 Subject: [PATCH 2/2] pass the parameters for the callback afterChange --- app/scripts/app.coffee | 4 ++-- dist/slick.js | 2 +- dist/slick.min.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/scripts/app.coffee b/app/scripts/app.coffee index 1549172..de74d8c 100644 --- a/app/scripts/app.coffee +++ b/app/scripts/app.coffee @@ -77,8 +77,8 @@ angular.module('slick', []) ) slider.on 'afterChange', (event, slick, currentSlide, nextSlide) -> - scope.onAfterChange() if scope.onAfterChange - + scope.onAfterChange(event, slick, currentSlide, nextSlide) if scope.onAfterChange + if currentIndex? scope.$apply(-> currentIndex = currentSlide diff --git a/dist/slick.js b/dist/slick.js index cbc27f7..b1cf8d3 100644 --- a/dist/slick.js +++ b/dist/slick.js @@ -88,7 +88,7 @@ angular.module('slick', []).directive('slick', [ }); slider.on('afterChange', function (event, slick, currentSlide, nextSlide) { if (scope.onAfterChange) { - scope.onAfterChange(); + scope.onAfterChange(event, slick, currentSlide, nextSlide); } if (currentIndex != null) { return scope.$apply(function () { diff --git a/dist/slick.min.js b/dist/slick.min.js index bd1fc85..a8cd0c0 100644 --- a/dist/slick.min.js +++ b/dist/slick.min.js @@ -1,2 +1,2 @@ /*! angular-slick v0.2.1 */ -"use strict";angular.module("slick",[]).directive("slick",["$timeout",function(a){return{restrict:"AEC",scope:{initOnload:"@",data:"=",currentIndex:"=",accessibility:"@",adaptiveHeight:"@",arrows:"@",asNavFor:"@",appendArrows:"@",appendDots:"@",autoplay:"@",autoplaySpeed:"@",centerMode:"@",centerPadding:"@",cssEase:"@",customPaging:"&",dots:"@",draggable:"@",easing:"@",fade:"@",focusOnSelect:"@",infinite:"@",initialSlide:"@",lazyLoad:"@",onBeforeChange:"&",onAfterChange:"&",onInit:"&",onReInit:"&",onSetPosition:"&",pauseOnHover:"@",pauseOnDotsHover:"@",responsive:"=",rtl:"@",slide:"@",slidesToShow:"@",slidesToScroll:"@",speed:"@",swipe:"@",swipeToSlide:"@",touchMove:"@",touchThreshold:"@",useCSS:"@",variableWidth:"@",vertical:"@",prevArrow:"@",nextArrow:"@"},link:function(b,c,d){var e,f,g;return e=function(){return a(function(){var a;return a=$(c),a.slick("unslick"),a.find(".slick-list").remove(),a})},f=function(){return a(function(){var a,e,f;return f=$(c),null!=b.currentIndex&&(a=b.currentIndex),e=function(a,c){return b.customPaging({slick:a,index:c})},f.on("afterChange",function(c,d,e,f){return b.onAfterChange&&b.onAfterChange(),null!=a?b.$apply(function(){return a=e,b.currentIndex=e}):void 0}),f.on("afterChange",function(c,d,e,f){return b.onAfterChange&&b.onAfterChange(),null!=a?b.$apply(function(){return a=e,b.currentIndex=e}):void 0}),f.slick({accessibility:"false"!==b.accessibility,adaptiveHeight:"true"===b.adaptiveHeight,arrows:"false"!==b.arrows,asNavFor:b.asNavFor?b.asNavFor:void 0,appendArrows:b.appendArrows?$(b.appendArrows):$(c),appendDots:b.appendDots?$(b.appendDots):$(c),autoplay:"true"===b.autoplay,autoplaySpeed:null!=b.autoplaySpeed?parseInt(b.autoplaySpeed,10):3e3,centerMode:"true"===b.centerMode,centerPadding:b.centerPadding||"50px",cssEase:b.cssEase||"ease",customPaging:d.customPaging?e:void 0,dots:"true"===b.dots,draggable:"false"!==b.draggable,easing:b.easing||"linear",fade:"true"===b.fade,focusOnSelect:"true"===b.focusOnSelect,infinite:"false"!==b.infinite,initialSlide:b.initialSlide||0,lazyLoad:b.lazyLoad||"ondemand",beforeChange:d.onBeforeChange?b.onBeforeChange:void 0,onReInit:d.onReInit?b.onReInit:void 0,onSetPosition:d.onSetPosition?b.onSetPosition:void 0,pauseOnHover:"false"!==b.pauseOnHover,responsive:b.responsive||void 0,rtl:"true"===b.rtl,slide:b.slide||"div",slidesToShow:null!=b.slidesToShow?parseInt(b.slidesToShow,10):1,slidesToScroll:null!=b.slidesToScroll?parseInt(b.slidesToScroll,10):1,speed:null!=b.speed?parseInt(b.speed,10):300,swipe:"false"!==b.swipe,swipeToSlide:"true"===b.swipeToSlide,touchMove:"false"!==b.touchMove,touchThreshold:b.touchThreshold?parseInt(b.touchThreshold,10):5,useCSS:"false"!==b.useCSS,variableWidth:"true"===b.variableWidth,vertical:"true"===b.vertical,prevArrow:b.prevArrow?$(b.prevArrow):void 0,nextArrow:b.nextArrow?$(b.nextArrow):void 0}),f.on("init",function(c){return d.onInit&&b.onInit(),null!=a?c.slideHandler(a):void 0}),b.$watch("currentIndex",function(b,c){return null!=a&&null!=b&&b!==a?f.slick("slickGoTo",b):void 0})})},b.initOnload?(g=!1,b.$watch("data",function(a,b){return null!=a?(g&&e(),f(),g=!0):void 0})):f()}}}]); \ No newline at end of file +"use strict";angular.module("slick",[]).directive("slick",["$timeout",function(a){return{restrict:"AEC",scope:{initOnload:"@",data:"=",currentIndex:"=",accessibility:"@",adaptiveHeight:"@",arrows:"@",asNavFor:"@",appendArrows:"@",appendDots:"@",autoplay:"@",autoplaySpeed:"@",centerMode:"@",centerPadding:"@",cssEase:"@",customPaging:"&",dots:"@",draggable:"@",easing:"@",fade:"@",focusOnSelect:"@",infinite:"@",initialSlide:"@",lazyLoad:"@",onBeforeChange:"&",onAfterChange:"&",onInit:"&",onReInit:"&",onSetPosition:"&",pauseOnHover:"@",pauseOnDotsHover:"@",responsive:"=",rtl:"@",slide:"@",slidesToShow:"@",slidesToScroll:"@",speed:"@",swipe:"@",swipeToSlide:"@",touchMove:"@",touchThreshold:"@",useCSS:"@",variableWidth:"@",vertical:"@",prevArrow:"@",nextArrow:"@"},link:function(b,c,d){var e,f,g;return e=function(){return a(function(){var a;return a=$(c),a.slick("unslick"),a.find(".slick-list").remove(),a})},f=function(){return a(function(){var a,e,f;return f=$(c),null!=b.currentIndex&&(a=b.currentIndex),e=function(a,c){return b.customPaging({slick:a,index:c})},f.on("afterChange",function(c,d,e,f){return b.onAfterChange&&b.onAfterChange(),null!=a?b.$apply(function(){return a=e,b.currentIndex=e}):void 0}),f.on("afterChange",function(c,d,e,f){return b.onAfterChange&&b.onAfterChange(c,d,e,f),null!=a?b.$apply(function(){return a=e,b.currentIndex=e}):void 0}),f.slick({accessibility:"false"!==b.accessibility,adaptiveHeight:"true"===b.adaptiveHeight,arrows:"false"!==b.arrows,asNavFor:b.asNavFor?b.asNavFor:void 0,appendArrows:b.appendArrows?$(b.appendArrows):$(c),appendDots:b.appendDots?$(b.appendDots):$(c),autoplay:"true"===b.autoplay,autoplaySpeed:null!=b.autoplaySpeed?parseInt(b.autoplaySpeed,10):3e3,centerMode:"true"===b.centerMode,centerPadding:b.centerPadding||"50px",cssEase:b.cssEase||"ease",customPaging:d.customPaging?e:void 0,dots:"true"===b.dots,draggable:"false"!==b.draggable,easing:b.easing||"linear",fade:"true"===b.fade,focusOnSelect:"true"===b.focusOnSelect,infinite:"false"!==b.infinite,initialSlide:b.initialSlide||0,lazyLoad:b.lazyLoad||"ondemand",beforeChange:d.onBeforeChange?b.onBeforeChange:void 0,onReInit:d.onReInit?b.onReInit:void 0,onSetPosition:d.onSetPosition?b.onSetPosition:void 0,pauseOnHover:"false"!==b.pauseOnHover,responsive:b.responsive||void 0,rtl:"true"===b.rtl,slide:b.slide||"div",slidesToShow:null!=b.slidesToShow?parseInt(b.slidesToShow,10):1,slidesToScroll:null!=b.slidesToScroll?parseInt(b.slidesToScroll,10):1,speed:null!=b.speed?parseInt(b.speed,10):300,swipe:"false"!==b.swipe,swipeToSlide:"true"===b.swipeToSlide,touchMove:"false"!==b.touchMove,touchThreshold:b.touchThreshold?parseInt(b.touchThreshold,10):5,useCSS:"false"!==b.useCSS,variableWidth:"true"===b.variableWidth,vertical:"true"===b.vertical,prevArrow:b.prevArrow?$(b.prevArrow):void 0,nextArrow:b.nextArrow?$(b.nextArrow):void 0}),f.on("init",function(c){return d.onInit&&b.onInit(),null!=a?c.slideHandler(a):void 0}),b.$watch("currentIndex",function(b,c){return null!=a&&null!=b&&b!==a?f.slick("slickGoTo",b):void 0})})},b.initOnload?(g=!1,b.$watch("data",function(a,b){return null!=a?(g&&e(),f(),g=!0):void 0})):f()}}}]); \ No newline at end of file