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 the necessary methods and key bindings to show and hide a form
11 for jumping to any slide number/id in the deck (and processes that form
12 accordingly). The form-showing state is indicated by the presence of a class on
15 (function($, undefined) {
16 var $document = $(document);
19 var bindKeyEvents = function() {
20 $document.unbind('keydown.deckgoto');
21 $document.bind('keydown.deckgoto', function(event) {
22 var key = $.deck('getOptions').keys.goto;
23 if (event.which === key || $.inArray(event.which, key) > -1) {
24 event.preventDefault();
30 var populateDatalist = function() {
31 var options = $.deck('getOptions');
32 var $datalist = $(options.selectors.gotoDatalist);
34 $.each($.deck('getSlides'), function(i, $slide) {
35 var id = $slide.attr('id');
37 $datalist.append('<option value="' + id + '">');
42 var markRootSlides = function() {
43 var options = $.deck('getOptions');
44 var slideTest = $.map([
45 options.classes.before,
46 options.classes.previous,
47 options.classes.current,
55 $.each($.deck('getSlides'), function(i, $slide) {
56 var $parentSlides = $slide.parentsUntil(
57 options.selectors.container,
61 if ($parentSlides.length) {
62 $slide.removeData('rootIndex');
64 else if (!options.countNested) {
66 $slide.data('rootIndex', rootCounter);
71 var handleFormSubmit = function() {
72 var options = $.deck('getOptions');
73 var $form = $(options.selectors.gotoForm);
75 $form.unbind('submit.deckgoto');
76 $form.bind('submit.deckgoto', function(event) {
77 var $field = $(options.selectors.gotoInput);
78 var indexOrId = $field.val();
79 var index = parseInt(indexOrId, 10);
81 if (!options.countNested) {
82 if (!isNaN(index) && index >= rootCounter) {
85 $.each($.deck('getSlides'), function(i, $slide) {
86 if ($slide.data('rootIndex') === index) {
93 $.deck('go', isNaN(index) ? indexOrId : index - 1);
96 event.preventDefault();
101 Extends defaults/options.
104 This class is added to the deck container when showing the Go To Slide
107 options.selectors.gotoDatalist
108 The element that matches this selector is the datalist element that will
109 be populated with options for each of the slide ids. In browsers that
110 support the datalist element, this provides a drop list of slide ids to
111 aid the user in selecting a slide.
113 options.selectors.gotoForm
114 The element that matches this selector is the form that is submitted
115 when a user hits enter after typing a slide number/id in the gotoInput
118 options.selectors.gotoInput
119 The element that matches this selector is the text input field for
120 entering a slide number/id in the Go To Slide form.
123 The numeric keycode used to show the Go To Slide form.
126 If false, only top level slides will be counted when entering a
129 $.extend(true, $.deck.defaults, {
135 gotoDatalist: '#goto-datalist',
136 gotoForm: '.goto-form',
137 gotoInput: '#goto-slide'
148 jQuery.deck('showGoTo')
150 Shows the Go To Slide form by adding the class specified by the goto class
151 option to the deck container.
153 $.deck('extend', 'showGoTo', function() {
154 var options = $.deck('getOptions');
155 $.deck('getContainer').addClass(options.classes.goto);
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);
172 jQuery.deck('toggleGoTo')
174 Toggles between showing and hiding the Go To Slide form.
176 $.deck('extend', 'toggleGoTo', function() {
177 var options = $.deck('getOptions');
178 var hasGotoClass = $.deck('getContainer').hasClass(options.classes.goto);
179 $.deck(hasGotoClass ? 'hideGoTo' : 'showGoTo');
182 $document.bind('deck.init', function() {