comparison deck.js/extensions/status/deck.status.js @ 0:dd1c78c6398f

add having slides
author taiki <taiki@cr.ie.u-ryukyu.ac.jp>
date Mon, 25 Mar 2013 05:14:03 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:dd1c78c6398f
1 /*!
2 Deck JS - deck.status
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
7 */
8
9 /*
10 This module adds a (current)/(total) style status indicator to the deck.
11 */
12 (function($, deck, undefined) {
13 var $d = $(document),
14
15 updateCurrent = function(e, from, to) {
16 var opts = $[deck]('getOptions');
17
18 $(opts.selectors.statusCurrent).text(opts.countNested ?
19 to + 1 :
20 $[deck]('getSlide', to).data('rootSlide')
21 );
22 };
23
24 /*
25 Extends defaults/options.
26
27 options.selectors.statusCurrent
28 The element matching this selector displays the current slide number.
29
30 options.selectors.statusTotal
31 The element matching this selector displays the total number of slides.
32
33 options.countNested
34 If false, only top level slides will be counted in the current and
35 total numbers.
36 */
37 $.extend(true, $[deck].defaults, {
38 selectors: {
39 statusCurrent: '.deck-status-current',
40 statusTotal: '.deck-status-total'
41 },
42
43 countNested: true
44 });
45
46 $d.bind('deck.init', function() {
47 var opts = $[deck]('getOptions'),
48 slides = $[deck]('getSlides'),
49 $current = $[deck]('getSlide'),
50 ndx;
51
52 // Set total slides once
53 if (opts.countNested) {
54 $(opts.selectors.statusTotal).text(slides.length);
55 }
56 else {
57 /* Determine root slides by checking each slide's ancestor tree for
58 any of the slide classes. */
59 var rootIndex = 1,
60 slideTest = $.map([
61 opts.classes.before,
62 opts.classes.previous,
63 opts.classes.current,
64 opts.classes.next,
65 opts.classes.after
66 ], function(el, i) {
67 return '.' + el;
68 }).join(', ');
69
70 /* Store the 'real' root slide number for use during slide changes. */
71 $.each(slides, function(i, $el) {
72 var $parentSlides = $el.parentsUntil(opts.selectors.container, slideTest);
73
74 $el.data('rootSlide', $parentSlides.length ?
75 $parentSlides.last().data('rootSlide') :
76 rootIndex++
77 );
78 });
79
80 $(opts.selectors.statusTotal).text(rootIndex - 1);
81 }
82
83 // Find where we started in the deck and set initial state
84 $.each(slides, function(i, $el) {
85 if ($el === $current) {
86 ndx = i;
87 return false;
88 }
89 });
90 updateCurrent(null, ndx, ndx);
91 })
92 /* Update current slide number with each change event */
93 .bind('deck.change', updateCurrent);
94 })(jQuery, 'deck');
95