From 54cb9f8c7097213f0131d62e944deda103bced86 Mon Sep 17 00:00:00 2001 From: Jeremy Clement Date: Mon, 25 Nov 2013 17:29:09 +0100 Subject: [PATCH 1/4] Allow to set custom id, title and href on pagination items Use data-slidejs-id, data-slidejs-title and data-slidejs-href on each childnodes of the slide --- source/jquery.slides.coffee | 31 +++++++++++++++++++++++------- source/jquery.slides.js | 38 ++++++++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/source/jquery.slides.coffee b/source/jquery.slides.coffee index cdeb9ba..ce5da88 100755 --- a/source/jquery.slides.coffee +++ b/source/jquery.slides.coffee @@ -94,11 +94,12 @@ Plugin::init = -> $element = $(@element) + $children = $element.children().not(".slidesjs-navigation", $element); @data = $.data this # Set data $.data this, "animating", false - $.data this, "total", $element.children().not(".slidesjs-navigation", $element).length + $.data this, "total", $children.length $.data this, "current", @options.start - 1 $.data this, "vendorPrefix", @_getVendorPrefix() @@ -112,7 +113,7 @@ $element.css overflow: "hidden" # Create container - $element.slidesContainer = $element.children().not(".slidesjs-navigation", $element).wrapAll("
", $element).parent().css + $element.slidesContainer = $children.wrapAll("
", $element).parent().css overflow: "hidden" position: "relative" @@ -238,17 +239,34 @@ ).appendTo($element) # Create a list item and anchor for each slide - $.each(new Array(@data.total), (i) => + $children.each (i, element) => + + # Get optionnal data of element + dataId = $(element).data 'slidejs-id' + if not dataId + dataId = "slidejs-pagination-#{( i + 1 )}" + dataTitle = $(element).data 'slidejs-title' + if not dataTitle + dataTitle = i + 1 + dataHref = $(element).data 'slidejs-href' + if not dataHref + dataHref= "#" + + # Create html paginationItem = $("
  • " + id: dataId class: "slidesjs-pagination-item" ).appendTo(pagination) paginationLink = $("" - href: "#" + href: dataHref "data-slidesjs-item": i - html: i + 1 ).appendTo(paginationItem) + paginationText = $("" + html: dataTitle + ).appendTo(paginationLink) + # bind click events paginationLink.click (e) => e.preventDefault() @@ -256,7 +274,6 @@ @stop(true) # Goto to selected slide @goto( ($(e.currentTarget).attr("data-slidesjs-item") * 1) + 1 ) - ) # Bind update on browser resize $(window).bind("resize", () => @@ -516,7 +533,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 diff --git a/source/jquery.slides.js b/source/jquery.slides.js index f5b2d27..fec5dcc 100644 --- a/source/jquery.slides.js +++ b/source/jquery.slides.js @@ -1,6 +1,5 @@ -// Generated by CoffeeScript 1.6.1 +// Generated by CoffeeScript 1.6.3 (function() { - (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); @@ -54,12 +52,13 @@ })(); Plugin.prototype.init = function() { - var $element, nextButton, pagination, playButton, prevButton, stopButton, + var $children, $element, nextButton, pagination, playButton, prevButton, stopButton, _this = this; $element = $(this.element); + $children = $element.children().not(".slidesjs-navigation", $element); this.data = $.data(this); $.data(this, "animating", false); - $.data(this, "total", $element.children().not(".slidesjs-navigation", $element).length); + $.data(this, "total", $children.length); $.data(this, "current", this.options.start - 1); $.data(this, "vendorPrefix", this._getVendorPrefix()); if (typeof TouchEvent !== "undefined") { @@ -69,7 +68,7 @@ $element.css({ overflow: "hidden" }); - $element.slidesContainer = $element.children().not(".slidesjs-navigation", $element).wrapAll("
    ", $element).parent().css({ + $element.slidesContainer = $children.wrapAll("
    ", $element).parent().css({ overflow: "hidden", position: "relative" }); @@ -168,16 +167,31 @@ pagination = $("