Don't blank pages when ctrl key is pressed.
[deck.blank.js.git] / deck.blank.js
blob9dd3a2b068e33cb8f2e63eab339da3711fae383b
1 /*!
2 Deck JS - deck.blank
3 Copyright (c) 2012 Daniel Knittl-Frank
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 */
9 /*
10 This module adds the methods and key binding to show a blank page instead of
11 the slides in the deck.  The deck menu state is indicated by the presence of
12 a class on the deck container.
14 (function($, deck, undefined) {
15         var $d = $(document);
17         /*
18         Extends defaults/options.
20         options.classes.blank
21                 These classes are added to the deck container when blanking the screen.
23         options.keys.black
24         options.keys.white
25                 The numeric keycodes used to toggle between a blank screen and slides.
26         */
27         $.extend(true, $[deck].defaults, {
28                 classes: {
29                         blank: 'deck-blank',
30                         black: 'deck-blank-black',
31                         white: 'deck-blank-white'
32                 },
34                 keys: {
35                         black: [66, 190], // b, .
36                         white: 87         // w
37                 }
38         });
40         /*
41         jQuery.deck('toggleBlank', color)
43         Shows a blank page (either black or white), or unhides the slides,
44         if currently blanked.
45         */
46         $[deck]('extend', 'toggleBlank', function(color) {
47                 var $c = $[deck]('getContainer'),
48                 opts = $[deck]('getOptions');
50                 if ($c.hasClass(opts.classes.blank))
51                         $c.removeClass([opts.classes.blank, opts.classes.black, opts.classes.white].join(' '));
52                 else
53                         $c.addClass([opts.classes.blank, opts.classes[color]].join(' '));
54         });
56         $d.bind('deck.init', function() {
57                 var opts = $[deck]('getOptions');
59                 $d.unbind('keydown.deckblank').bind('keydown.deckblank', function(e) {
60                         if (e.ctrlKey) return;
61                         if (e.which === opts.keys.black || $.inArray(e.which, opts.keys.black) > -1) {
62                                 $[deck]('toggleBlank', 'black');
63                                 e.preventDefault();
64                         } else if (e.which === opts.keys.white || $.inArray(e.which, opts.keys.white) > -1) {
65                                 $[deck]('toggleBlank', 'white');
66                                 e.preventDefault();
67                         }
68                 });
70         });
71 })(jQuery, 'deck');