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 the necessary methods and key bindings to show and hide a form
10 for jumping to any slide number/id in the deck (and processes that form
11 accordingly). The form-showing state is indicated by the presence of a class on
14 (function($, undefined) {
15 var $document
= $(document
);
18 var bindKeyEvents = function() {
19 $document
.unbind('keydown.deckgoto');
20 $document
.bind('keydown.deckgoto', function(event
) {
21 var key
= $.deck('getOptions').keys
.goto;
22 if (event
.which
=== key
|| $.inArray(event
.which
, key
) > -1) {
23 event
.preventDefault();
29 var populateDatalist = function() {
30 var options
= $.deck('getOptions');
31 var $datalist
= $(options
.selectors
.gotoDatalist
);
33 $.each($.deck('getSlides'), function(i
, $slide
) {
34 var id
= $slide
.attr('id');
36 $datalist
.append('<option value="' + id
+ '">');
41 var markRootSlides = function() {
42 var options
= $.deck('getOptions');
43 var slideTest
= $.map([
44 options
.classes
.before
,
45 options
.classes
.previous
,
46 options
.classes
.current
,
54 $.each($.deck('getSlides'), function(i
, $slide
) {
55 var $parentSlides
= $slide
.parentsUntil(
56 options
.selectors
.container
,
60 if ($parentSlides
.length
) {
61 $slide
.removeData('rootIndex');
63 else if (!options
.countNested
) {
65 $slide
.data('rootIndex', rootCounter
);
70 var handleFormSubmit = function() {
71 var options
= $.deck('getOptions');
72 var $form
= $(options
.selectors
.gotoForm
);
74 $form
.unbind('submit.deckgoto');
75 $form
.bind('submit.deckgoto', function(event
) {
76 var $field
= $(options
.selectors
.gotoInput
);
77 var indexOrId
= $field
.val();
78 var index
= parseInt(indexOrId
, 10);
80 if (!options
.countNested
) {
81 if (!isNaN(index
) && index
>= rootCounter
) {
84 $.each($.deck('getSlides'), function(i
, $slide
) {
85 if ($slide
.data('rootIndex') === index
) {
92 $.deck('go', isNaN(index
) ? indexOrId
: index
- 1);
95 event
.preventDefault();
100 Extends defaults/options.
103 This class is added to the deck container when showing the Go To Slide
106 options.selectors.gotoDatalist
107 The element that matches this selector is the datalist element that will
108 be populated with options for each of the slide ids. In browsers that
109 support the datalist element, this provides a drop list of slide ids to
110 aid the user in selecting a slide.
112 options.selectors.gotoForm
113 The element that matches this selector is the form that is submitted
114 when a user hits enter after typing a slide number/id in the gotoInput
117 options.selectors.gotoInput
118 The element that matches this selector is the text input field for
119 entering a slide number/id in the Go To Slide form.
122 The numeric keycode used to show the Go To Slide form.
125 If false, only top level slides will be counted when entering a
128 $.extend(true, $.deck
.defaults
, {
134 gotoDatalist
: '#goto-datalist',
135 gotoForm
: '.goto-form',
136 gotoInput
: '#goto-slide'
147 jQuery.deck('showGoTo')
149 Shows the Go To Slide form by adding the class specified by the goto class
150 option to the deck container.
152 $.deck('extend', 'showGoTo', function() {
153 var options
= $.deck('getOptions');
154 $.deck('getContainer').addClass(options
.classes
.goto);
155 $(options
.selectors
.gotoForm
).attr('aria-hidden', false);
156 $(options
.selectors
.gotoInput
).focus();
160 jQuery.deck('hideGoTo')
162 Hides the Go To Slide form by removing the class specified by the goto class
163 option from the deck container.
165 $.deck('extend', 'hideGoTo', function() {
166 var options
= $.deck('getOptions');
167 $(options
.selectors
.gotoInput
).blur();
168 $.deck('getContainer').removeClass(options
.classes
.goto);
169 $(options
.selectors
.gotoForm
).attr('aria-hidden', true);
173 jQuery.deck('toggleGoTo')
175 Toggles between showing and hiding the Go To Slide form.
177 $.deck('extend', 'toggleGoTo', function() {
178 var options
= $.deck('getOptions');
179 var hasGotoClass
= $.deck('getContainer').hasClass(options
.classes
.goto);
180 $.deck(hasGotoClass
? 'hideGoTo' : 'showGoTo');
183 $document
.bind('deck.init', function() {