PageSourceSearch

https://adamdaniels.ca/talks/mithriljs-devtricks-2016/extensions/status/deck.status.js

js adamdaniels.ca collected 2026-09-25 22:30:32 UTC 2,727 bytes, 108 lines download raw bytes

1/*!
2Deck JS - deck.status
3Copyright (c) 2011-2014 Caleb Troughton
4Dual licensed under the MIT license.
5https://github.com/imakewebthings/deck.js/blob/master/MIT-license.txt
6*/
7
8/*
9This module adds a (current)/(total) style status indicator to the deck.
10*/
11(function($, undefined) {
12  var $document = $(document);
13  var rootCounter;
14
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');
20    }
21    $(options.selectors.statusCurrent).text(currentSlideNumber);
22  };
23
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,
30      options.classes.next,
31      options.classes.after
32    ], function(el, i) {
33      return '.' + el;
34    }).join(', ');
35
36    rootCounter = 0;
37    $.each($.deck('getSlides'), function(i, $slide) {
38      var $parentSlides = $slide.parentsUntil(
39        options.selectors.container,
40        slideTest
41      );
42
43      if ($parentSlides.length) {
44        $slide.data('rootSlide', $parentSlides.last().data('rootSlide'));
45      }
46      else {
47        ++rootCounter;
48        $slide.data('rootSlide', rootCounter);
49      }
50    });
51  };
52
53  var setInitialSlideNumber = function() {
54    var slides = $.deck('getSlides');
55    var $currentSlide = $.deck('getSlide');
56    var index;
57
58    $.each(slides, function(i, $slide) {
59      if ($slide === $currentSlide) {
60        index = i;
61        return false;
62      }
63    });
64    updateCurrent(null, index, index);
65  };
66
67  var setTotalSlideNumber = function() {
68    var options = $.deck('getOptions');
69    var slides = $.deck('getSlides');
70
71    if (options.countNested) {
72      $(options.selectors.statusTotal).text(slides.length);
73    }
74    else {
75      $(options.selectors.statusTotal).text(rootCounter);
76    }
77  };
78
79  /*
80  Extends defaults/options.
81
82  options.selectors.statusCurrent
83    The element matching this selector displays the current slide number.
84
85  options.selectors.statusTotal
86    The element matching this selector displays the total number of slides.
87
88  options.countNested
89    If false, only top level slides will be counted in the current and
90    total numbers.
91  */
92  $.extend(true, $.deck.defaults, {
93    selectors: {
94      statusCurrent: '.deck-status-current',
95      statusTotal: '.deck-status-total'
96    },
97
98    countNested: true
99  });
100
101  $document.bind('deck.init', function() {
102    markRootSlides();
103    setInitialSlideNumber();
104    setTotalSlideNumber();
105  });
106  $document.bind('deck.change', updateCurrent);
107})(jQuery, 'deck');
108

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.