From 46b7c29155d362a6fc389d5bdc922eafc64dadb5 Mon Sep 17 00:00:00 2001 From: Kit Grose Date: Fri, 24 Jan 2014 17:47:08 +1100 Subject: [PATCH] Added next slide number as a second parameter to the start() callback. This allows other JavaScript to react to the content of the next slide before the animation has been performed (no matter how the user navigates around). Compiled the JS with CoffeeScript v1.1.2 and minified it with UglifyJS. --- source/jquery.slides.coffee | 6 +- source/jquery.slides.js | 176 +++++++++++++++++------------------- source/jquery.slides.min.js | 2 +- 3 files changed, 88 insertions(+), 96 deletions(-) diff --git a/source/jquery.slides.coffee b/source/jquery.slides.coffee index cdeb9ba..eef08a6 100755 --- a/source/jquery.slides.coffee +++ b/source/jquery.slides.coffee @@ -516,7 +516,7 @@ # Stop/pause slideshow on mouse enter slidesContainer.bind "mouseenter", => clearTimeout @data.restartDelay - $.data this, "restartDelay", null + $.data this, "restartDelay", null @stop() # Play slideshow on mouse leave @@ -609,7 +609,7 @@ zIndex: 10 # Start the slide animation - @options.callback.start(currentSlide + 1) + @options.callback.start(currentSlide + 1, next + 1) if @data.vendorPrefix # If supported use CSS3 for the animation @@ -723,7 +723,7 @@ zIndex: 10 # Start of the animation, call the start callback - @options.callback.start(currentSlide + 1) + @options.callback.start(currentSlide + 1, next + 1) if @options.effect.fade.crossfade # Fade out current slide to next slide diff --git a/source/jquery.slides.js b/source/jquery.slides.js index f5b2d27..4c370c9 100644 --- a/source/jquery.slides.js +++ b/source/jquery.slides.js @@ -1,6 +1,5 @@ -// Generated by CoffeeScript 1.6.1 (function() { - + var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; (function($, window, document) { var Plugin, defaults, pluginName; pluginName = "slidesjs"; @@ -41,7 +40,6 @@ } }; Plugin = (function() { - function Plugin(element, options) { this.element = element; this.options = $.extend(true, {}, defaults, options); @@ -49,13 +47,10 @@ this._name = pluginName; this.init(); } - return Plugin; - })(); Plugin.prototype.init = function() { - var $element, nextButton, pagination, playButton, prevButton, stopButton, - _this = this; + var $element, nextButton, pagination, playButton, prevButton, stopButton; $element = $(this.element); this.data = $.data(this); $.data(this, "animating", false); @@ -93,15 +88,15 @@ return $slide.attr("slidesjs-index", i); }); if (this.data.touch) { - $(".slidesjs-control", $element).on("touchstart", function(e) { - return _this._touchstart(e); - }); - $(".slidesjs-control", $element).on("touchmove", function(e) { - return _this._touchmove(e); - }); - $(".slidesjs-control", $element).on("touchend", function(e) { - return _this._touchend(e); - }); + $(".slidesjs-control", $element).on("touchstart", __bind(function(e) { + return this._touchstart(e); + }, this)); + $(".slidesjs-control", $element).on("touchmove", __bind(function(e) { + return this._touchmove(e); + }, this)); + $(".slidesjs-control", $element).on("touchend", __bind(function(e) { + return this._touchend(e); + }, this)); } $element.fadeIn(0); this.update(); @@ -127,16 +122,16 @@ text: "Next" }).appendTo($element); } - $(".slidesjs-next", $element).click(function(e) { + $(".slidesjs-next", $element).click(__bind(function(e) { e.preventDefault(); - _this.stop(true); - return _this.next(_this.options.navigation.effect); - }); - $(".slidesjs-previous", $element).click(function(e) { + this.stop(true); + return this.next(this.options.navigation.effect); + }, this)); + $(".slidesjs-previous", $element).click(__bind(function(e) { e.preventDefault(); - _this.stop(true); - return _this.previous(_this.options.navigation.effect); - }); + this.stop(true); + return this.previous(this.options.navigation.effect); + }, this)); if (this.options.play.active) { playButton = $("", { "class": "slidesjs-play slidesjs-navigation", @@ -150,14 +145,14 @@ title: "Stop", text: "Stop" }).appendTo($element); - playButton.click(function(e) { + playButton.click(__bind(function(e) { e.preventDefault(); - return _this.play(true); - }); - stopButton.click(function(e) { + return this.play(true); + }, this)); + stopButton.click(__bind(function(e) { e.preventDefault(); - return _this.stop(true); - }); + return this.stop(true); + }, this)); if (this.options.play.swap) { stopButton.css({ display: "none" @@ -168,7 +163,7 @@ pagination = $("