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 hrefBase = window.location.href.replace(/#.*/, ''),
22 prevId = prevSlide ? prevSlide.attr('id') : undefined,
23 nextId = nextSlide ? nextSlide.attr('id') : undefined;
25 $(opts.selectors.previousLink)
26 .toggleClass(opts.classes.navDisabled, !to)
27 .attr('href', hrefBase + '#' + (prevId ? prevId : ''));
28 $(opts.selectors.nextLink)
29 .toggleClass(opts.classes.navDisabled, to === last)
30 .attr('href', hrefBase + '#' + (nextId ? nextId : ''));
34 Extends defaults/options.
36 options.classes.navDisabled
37 This class is added to a navigation link when that action is disabled.
38 It is added to the previous link when on the first slide, and to the
39 next link when on the last slide.
41 options.selectors.nextLink
42 The elements that match this selector will move the deck to the next
45 options.selectors.previousLink
46 The elements that match this selector will move to deck to the previous
49 $.extend(true, $[deck].defaults, {
51 navDisabled: 'deck-nav-disabled'
55 nextLink: '.deck-next-link',
56 previousLink: '.deck-prev-link'
60 $d.bind('deck.init', function() {
61 var opts = $[deck]('getOptions'),
62 slides = $[deck]('getSlides'),
63 $current = $[deck]('getSlide'),
66 // Setup prev/next link events
67 $(opts.selectors.previousLink)
68 .unbind('click.decknavigation')
69 .bind('click.decknavigation', function(e) {
74 $(opts.selectors.nextLink)
75 .unbind('click.decknavigation')
76 .bind('click.decknavigation', function(e) {
81 // Find where we started in the deck and set initial states
82 $.each(slides, function(i, $slide) {
83 if ($slide === $current) {
88 updateButtons(null, ndx, ndx);
90 .bind('deck.change', updateButtons);