From 1b55cd8e487d5433b3e8abaf7e214a75fca50c89 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Sat, 5 Nov 2011 17:06:26 +0800 Subject: [PATCH] Update goto form to accept ids + add datalist --- extensions/goto/deck.goto.css | 4 +-- extensions/goto/deck.goto.html | 3 ++- extensions/goto/deck.goto.js | 46 +++++++++++++++++++++++----------- extensions/goto/deck.goto.scss | 4 +-- introduction/index.html | 5 ++-- test/fixtures/standard.html | 3 ++- test/index.html | 2 +- test/spec.goto.js | 26 +++++++++++++------ 8 files changed, 62 insertions(+), 31 deletions(-) diff --git a/extensions/goto/deck.goto.css b/extensions/goto/deck.goto.css index 4d04dd2..108e4f9 100644 --- a/extensions/goto/deck.goto.css +++ b/extensions/goto/deck.goto.css @@ -4,7 +4,7 @@ bottom: 10px; left: 50%; height: 1.75em; - margin: 0 0 0 -7.125em; + margin: 0 0 0 -9.125em; line-height: 1.75em; padding: 0.625em; display: none; @@ -29,7 +29,7 @@ } #goto-slide { - width: 4.375em; + width: 8.375em; margin: 0 0.625em; height: 1.4375em; } diff --git a/extensions/goto/deck.goto.html b/extensions/goto/deck.goto.html index da96066..e3b6a18 100644 --- a/extensions/goto/deck.goto.html +++ b/extensions/goto/deck.goto.html @@ -1,6 +1,7 @@
- + +
\ No newline at end of file diff --git a/extensions/goto/deck.goto.js b/extensions/goto/deck.goto.js index 78e368f..21ec43c 100644 --- a/extensions/goto/deck.goto.js +++ b/extensions/goto/deck.goto.js @@ -8,7 +8,7 @@ https://github.com/imakewebthings/deck.js/blob/master/GPL-license.txt /* This module adds the necessary methods and key bindings to show and hide a form -for jumping to any slide number in the deck (and processes that form +for jumping to any slide number/id in the deck (and processes that form accordingly). The form-showing state is indicated by the presence of a class on the deck container. */ @@ -22,18 +22,23 @@ the deck container. This class is added to the deck container when showing the Go To Slide form. + options.selectors.gotoDatalist + The element that matches this selector is the datalist element that will + be populated with options for each of the slide ids. In browsers that + support the datalist element, this provides a drop list of slide ids to + aid the user in selecting a slide. + options.selectors.gotoForm The element that matches this selector is the form that is submitted - when a user hits enter after typing a slide number in the gotoInput + when a user hits enter after typing a slide number/id in the gotoInput element. options.selectors.gotoInput The element that matches this selector is the text input field for - entering a slide number in the Go To Slide form. + entering a slide number/id in the Go To Slide form. options.keys.goto - The numeric keycode used to toggle between showing and hiding the Go To - Slide form. + The numeric keycode used to show the Go To Slide form. */ $.extend(true, $[deck].defaults, { classes: { @@ -41,6 +46,7 @@ the deck container. }, selectors: { + gotoDatalist: '#goto-datalist', gotoForm: '.goto-form', gotoInput: '#goto-slide' }, @@ -68,8 +74,8 @@ the deck container. option from the deck container. */ $[deck]('extend', 'hideGoTo', function() { - $[deck]('getContainer').removeClass($[deck]('getOptions').classes.goto); $($[deck]('getOptions').selectors.gotoInput).blur(); + $[deck]('getContainer').removeClass($[deck]('getOptions').classes.goto); }); /* @@ -82,33 +88,43 @@ the deck container. }); $d.bind('deck.init', function() { + var opts = $[deck]('getOptions'), + $datalist = $(opts.selectors.gotoDatalist); + // Bind key events $d.unbind('keydown.deckgoto').bind('keydown.deckgoto', function(e) { var key = $[deck]('getOptions').keys.goto; - if (e.which === key ||$.inArray(e.which, key) > -1) { + if (e.which === key || $.inArray(e.which, key) > -1) { e.preventDefault(); $[deck]('toggleGoTo'); } }); + /* Populate datalist */ + $.each($[deck]('getSlides'), function(i, $slide) { + var id = $slide.attr('id'); + + if (id) { + $datalist.append('