2 Deck JS - deck.navigation
3 Copyright (c) 2011 Caleb Troughton
4 Dual licensed under the MIT license and GPL license.
5 https://github.com/imakewebthings/deck.js/blob/master/MIT-license.txt
6 https://github.com/imakewebthings/deck.js/blob/master/GPL-license.txt
10 This module adds clickable previous and next links to the deck.
12 (function($, deck, undefined) {
15 /* Updates link hrefs, and disabled states if last/first slide */
16 updateButtons = function(e, from, to) {
17 var opts = $[deck]('getOptions'),
18 last = $[deck]('getSlides').length - 1,
19 prevSlide = $[deck]('getSlide', to - 1),
20 nextSlide = $[deck]('getSlide', to + 1),
21 prevId = prevSlide ? prevSlide.attr('id') : undefined,
22 nextId = nextSlide ? nextSlide.attr('id') : undefined;
24 $(opts.selectors.previousLink)
25 .toggleClass(opts.classes.navDisabled, !to)
26 .attr('href', '#' + (prevId ? prevId : ''));
27 $(opts.selectors.nextLink)
28 .toggleClass(opts.classes.navDisabled, to === last)
29 .attr('href', '#' + (nextId ? nextId : ''));
33 Extends defaults/options.
35 options.classes.navDisabled
36 This class is added to a navigation link when that action is disabled.
37 It is added to the previous link when on the first slide, and to the
38 next link when on the last slide.
40 options.selectors.nextLink
41 The elements that match this selector will move the deck to the next
44 options.selectors.previousLink
45 The elements that match this selector will move to deck to the previous
48 $.extend(true, $[deck].defaults, {
50 navDisabled: 'deck-nav-disabled'
54 nextLink: '.deck-next-link',
55 previousLink: '.deck-prev-link'
59 $d.bind('deck.init', function() {
60 var opts = $[deck]('getOptions'),
61 slides = $[deck]('getSlides'),
62 $current = $[deck]('getSlide'),
65 // Setup prev/next link events
66 $(opts.selectors.previousLink)
67 .unbind('click.decknavigation')
68 .bind('click.decknavigation', function(e) {
73 $(opts.selectors.nextLink)
74 .unbind('click.decknavigation')
75 .bind('click.decknavigation', function(e) {
80 // Find where we started in the deck and set initial states
81 $.each(slides, function(i, $slide) {
82 if ($slide === $current) {
87 updateButtons(null, ndx, ndx);
89 .bind('deck.change', updateButtons);