Docs
deck.core
The deck.core module provides all the basic functionality for creating and moving through a deck. It applies and removes classes to indicate the state of the deck and its slides, allowing CSS to take care of the visual representation of each state. It also provides methods for interacting with the deck, as well as basic key bindings for going to the next and previous slides. Separate extension modules provide more functionality using the API provided by core.
Methods
init - $.deck(selector, options)
- selector:
- string | jQuery | array, optional
- options:
- object, optional
Initializes the deck, using each element matched by selector
as a slide. May also be passed an array of string selectors or jQuery objects, in which case each selector in the array is considered a slide. The second parameter is an optional options object which will extend the default values.
Users may also pass only an options object to init. In this case the slide selector will be options.selectors.slides
which defaults to .slide
.
$.deck('.slide');
$.deck([
'#first-slide',
'#second-slide',
'#etc'
]);
next - $.deck('next')
Moves to the next slide. If the last slide is already active, the call is ignored.
prev - $.deck('prev')
Moves to the previous slide. If the first slide is already active, the call is ignored.
go - $.deck('go', index)
- index:
- integer | string
Moves to the slide at the specified index
if index is a number. Index is 0-based, so $.deck('go', 0);
will move to the first slide. If index
is a string this will move to the slide with the specified id
. If index
is out of bounds or doesn’t match a slide id
the call is ignored.
getSlide - $.deck('getSlide', index)
Returns: jQuery
- index:
- integer | string, optional
Returns a jQuery object containing the slide at index
. If index
is not specified, the current slide is returned.
getSlides - $.deck('getSlides')
Returns: array
Returns all slides as an array of jQuery objects.
getTopLevelSlides - $.deck('getTopLevelSlides')
Returns: array
Returns all slides that are not subslides as an array of jQuery objects.
getNestedSlides - $.deck('getNestedSlides', index)
Returns: array
- index
- integer, optional
Returns all nested slides of the current slide as an array of jQuery objects. If index
is specified it returns nested slides of the slide at that index. If there are no nested slides this will return an empty array.
getContainer - $.deck('getContainer')
Returns: jQuery
Returns a jQuery object containing the deck container as defined by the container option.
getOptions - $.deck('getOptions')
Returns: object
Returns the options object for the deck, including any overrides that were defined at initialization.
extend - $.deck('extend', name, method)
- name:
- string
- method:
- function
Adds method
to the deck namespace with the key of name
. This doesn’t give access to any private member data — public methods must still be used within method
— but lets extension authors piggyback on the deck namespace rather than pollute jQuery.
$.deck('extend', 'alert', function(msg) {
alert(msg);
});
// Alerts 'boom'
$.deck('alert', 'boom');
Events
All events are triggered on the document
.
- deck.beforeChange
-
This event fires when a slide change has been triggered but before the change occurs. The callback function is passed two parameters,
from
andto
, equal to the indices of the old slide and the new slide respectively. IfpreventDefault
is called on the event within this handler thedeck.change
event will not fire and the slide change does not occur. Handlers for this event should only focus on this aspect of the slide change, whether the change should occur and preventing default accordingly. - deck.change
-
This event fires whenever the current slide changes, whether by way of next, prev, or go. The callback function is passed two parameters,
from
andto
, equal to the indices of the old slide and the new slide respectively.$(document).bind('deck.change', function(event, from, to) { alert('Moving from slide ' + from + ' to ' + to); });
- deck.beforeInit
-
This event fires at the beginning of deck initialization. This event makes a good hook for preprocessing extensions looking to modify the DOM before the deck is fully initialized. It is also possible to halt the
deck.init
event from firing while you do things in beforeInit. This can be done by callinglockInit
on the event object. The init can be released by callingreleaseInit
.
The init event will be fired regardless after$(document).bind('deck.beforeInit', function(event) { event.lockInit(); // halts deck.init event window.setTimeout(function() { event.releaseInit(); // deck.init will now fire 2 seconds later }, 2000); });
options.initLockTimeout
milliseconds if locks still persist. - deck.init
-
This event fires at the end of deck initialization. Extensions should implement any code that relies on user extensible options (key bindings, element selectors, classes) within a handler for this event. Native events associated with deck.js should be scoped under a
.deckmodule
event namespace, as with the example below:var $d = $(document); $.deck.defaults.keys.myExtensionKeycode = 70; // 'h' $d.bind('deck.init', function() { $d.bind('keydown.deckmyextension', function(event) { if (event.which === $.deck.getOptions().keys.myExtensionKeycode) { // Rock out } }); });
Theming
Below is a skeleton example of a standard deck and all the theme-able components included in core. What follows is an explanation of each component and the base CSS properties that themes must extend. These bare styles can be seen on the Getting Started page and selecting "None" for both Style and Transition themes.
<body class="deck-container">
<section class="slide deck-before">...</section>
<section class="slide deck-before deck-child-current">
...
<section class="slide deck-before">...</section>
<section class="slide deck-previous">...</section>
<section class="slide deck-current"></section>
<section class="slide deck-next">...</section>
</section>
<section class="slide deck-after">...</section>
<section class="slide deck-after">...</section>
</body>
- .deck-container
-
The deck container wraps all slides. Keeping the
position:relative
andheight:100%
rules intact is recommended, as they tend to be needed for transition themes.position: relative; height: 100%; width: 70%; margin: 0 auto; padding: 0 48px;
- .slide
-
These are generic styles for all slides, including nested slides. These should rarely be overwritten.
width: auto; min-height: 100%; position: relative;
- .deck-before, .deck-previous, .deck-next, .deck-after
-
All slides that are not the current one are accessibly hidden off the screen.
position: absolute; left: -999em; top: -999em;
- .deck-current
-
The current slide is given a z-index. This does nothing on its own, but is included in core as it is commonly used in transition themes.
z-index: 2;
- .slide .slide
-
All nested slides are reset to a static position to maintain the parent slide layout and hidden in place.
visibility: hidden; position: static; min-height: 0;
- .deck-child-current
-
Parents of active nested slides are reset to a static position to keep them in place despite having a
.deck-previous
or.deck-before
class simultaneously.position: static; z-index: 2;
- .deck-child-current .slide
-
All nested slides are hidden by default.
visibility: hidden;
- .deck-child-current any(.deck-previous, .deck-before, .deck-current)
-
The current nested slide and any previous nested slides are visible.
visibility: visible;
deck.goto
This module adds the necessary methods and key bindings to show and hide a 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.
Methods
showGoTo - $.deck('showGoTo')
Shows the Go To Slide form by adding the class specified by the goto class option to the deck container.
hideGoTo - $.deck('hideGoTo')
Hides the Go To Slide form by removing the class specified by the goto class option from the deck container.
toggleGoTo - $.deck('toggleGoTo')
Theming
<form action="." method="get" class="goto-form">
<label for="goto-slide">Go to slide:</label>
<input type="number" name="slidenum" id="goto-slide" list="goto-datalist">
<datalist id="goto-datalist"></datalist>
<input type="submit" value="Go">
</form>
- .goto-form
-
The form is centered at the bottom of the deck container by default. Defining everything in
em
units lets the form scale if the base font size of the deck container changes with the theme.position: absolute; z-index: 3; bottom: 10px; left: 50%; height: 1.75em; margin: 0 0 0 -9.125em; line-height: 1.75em; padding: 0.625em; display: none; background: #ccc; overflow: hidden; // .border-radius .goto-form -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; // .deck-goto .goto-form (showing form) display: block;
- .goto-form label
-
font-weight: bold; float: left;
- .goto-form input
-
display: inline-block; font-family: inherit;
- #goto-slide
-
width: 8.375em; margin: 0 0.625em; height: 1.4375em;
deck.scale
This module adds automatic scaling to the deck. Each slide is scaled down using CSS transforms to fit within the deck container. If the container is big enough to hold the slide without scaling, no scaling occurs. The user can disable and enable scaling with a keyboard shortcut.
Note: CSS transforms may make Flash videos render incorrectly. Presenters that need to use Flash videos may want to disable scaling to play them. HTML5 video works fine.
Methods
enableScale - $.deck('enableScale')
Enables scaling and adds the scale class to the deck container.
disableScale - $.deck('disableScale')
Disables scaling and removes the scale class from the deck container.
toggleScale - $.deck('toggleScale')
Toggles between enabling and disabling scaling.
deck.status
This module adds a (current)/(total) style status indicator to the deck.
Theming
<p class="deck-status">
<span class="deck-status-current"></span>
/
<span class="deck-status-total"></span>
</p>
- .deck-status
-
The status indicator is placed in the bottom right padding of the deck container by default.
.deck-status-current
and.deck-status-total
are used by the extension’s JS, but also provide hooks for styling. They inherit from.deck-status
with no custom styles of their own.position: absolute; bottom: 10px; right: 0; color: #888; z-index: 3; margin: 0;