3 Copyright (c) 2011-2014 Caleb Troughton
4 Dual licensed under the MIT license.
5 https://github.com/imakewebthings/deck.js/blob/master/MIT-license.txt
9 This module adds a (current)/(total) style status indicator to the deck.
11 (function($, undefined) {
12 var $document
= $(document
);
15 var updateCurrent = function(event
, from, to
) {
16 var options
= $.deck('getOptions');
17 var currentSlideNumber
= to
+ 1;
18 if (!options
.countNested
) {
19 currentSlideNumber
= $.deck('getSlide', to
).data('rootSlide');
21 $(options
.selectors
.statusCurrent
).text(currentSlideNumber
);
24 var markRootSlides = function() {
25 var options
= $.deck('getOptions');
26 var slideTest
= $.map([
27 options
.classes
.before
,
28 options
.classes
.previous
,
29 options
.classes
.current
,
37 $.each($.deck('getSlides'), function(i
, $slide
) {
38 var $parentSlides
= $slide
.parentsUntil(
39 options
.selectors
.container
,
43 if ($parentSlides
.length
) {
44 $slide
.data('rootSlide', $parentSlides
.last().data('rootSlide'));
48 $slide
.data('rootSlide', rootCounter
);
53 var setInitialSlideNumber = function() {
54 var slides
= $.deck('getSlides');
55 var $currentSlide
= $.deck('getSlide');
58 $.each(slides
, function(i
, $slide
) {
59 if ($slide
=== $currentSlide
) {
64 updateCurrent(null, index
, index
);
67 var setTotalSlideNumber = function() {
68 var options
= $.deck('getOptions');
69 var slides
= $.deck('getSlides');
71 if (options
.countNested
) {
72 $(options
.selectors
.statusTotal
).text(slides
.length
);
75 $(options
.selectors
.statusTotal
).text(rootCounter
);
80 Extends defaults/options.
82 options.selectors.statusCurrent
83 The element matching this selector displays the current slide number.
85 options.selectors.statusTotal
86 The element matching this selector displays the total number of slides.
89 If false, only top level slides will be counted in the current and
92 $.extend(true, $.deck
.defaults
, {
94 statusCurrent
: '.deck-status-current',
95 statusTotal
: '.deck-status-total'
101 $document
.bind('deck.init', function() {
103 setInitialSlideNumber();
104 setTotalSlideNumber();
106 $document
.bind('deck.change', updateCurrent
);