From f96898dcd562b948a18406e94ea04600690d5e54 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Tue, 12 Nov 2013 16:05:16 -0800 Subject: [PATCH] Therapeutic refactoring, make interwebs angry var keyword on each line, make interwebs angry Therapeutic refactoring --- .gitignore | 3 +- boilerplate.html | 198 +++--- core/deck.core.js | 1002 +++++++++++++++------------- core/deck.core.scss | 130 ++-- extensions/goto/deck.goto.html | 8 +- extensions/goto/deck.goto.js | 359 +++++----- extensions/goto/deck.goto.scss | 78 +-- extensions/hash/deck.hash.js | 288 ++++---- extensions/hash/deck.hash.scss | 16 +- extensions/menu/deck.menu.js | 430 ++++++------ extensions/menu/deck.menu.scss | 110 +-- extensions/navigation/deck.navigation.js | 185 ++--- extensions/navigation/deck.navigation.scss | 88 +-- extensions/scale/deck.scale.js | 355 +++++----- extensions/scale/deck.scale.scss | 56 +- extensions/status/deck.status.html | 6 +- extensions/status/deck.status.js | 204 +++--- extensions/status/deck.status.scss | 20 +- introduction/index.html | 444 ++++++------ test/fixtures/empty.html | 38 +- test/fixtures/nesteds.html | 72 +- test/fixtures/standard.html | 84 +-- test/index.html | 78 +-- test/spec.core.js | 668 +++++++++---------- test/spec.goto.js | 284 ++++---- test/spec.hash.js | 163 +++-- test/spec.menu.js | 167 +++-- test/spec.navigation.js | 106 +-- test/spec.scale.js | 114 ++-- test/spec.status.js | 120 ++-- themes/style/web-2.0.scss | 6 +- themes/transition/fade.scss | 118 ++-- themes/transition/horizontal-slide.scss | 144 ++-- themes/transition/vertical-slide.scss | 184 ++--- 34 files changed, 3230 insertions(+), 3096 deletions(-) rewrite boilerplate.html (77%) rewrite core/deck.core.js (93%) rewrite core/deck.core.scss (68%) rewrite extensions/goto/deck.goto.js (88%) rewrite extensions/goto/deck.goto.scss (89%) rewrite extensions/hash/deck.hash.js (81%) rewrite extensions/menu/deck.menu.js (90%) rewrite extensions/menu/deck.menu.scss (97%) rewrite extensions/navigation/deck.navigation.js (87%) rewrite extensions/navigation/deck.navigation.scss (73%) rewrite extensions/scale/deck.scale.js (83%) rewrite extensions/scale/deck.scale.scss (60%) rewrite extensions/status/deck.status.js (85%) rewrite introduction/index.html (63%) rewrite test/fixtures/empty.html (94%) rewrite test/fixtures/nesteds.html (95%) rewrite test/fixtures/standard.html (94%) rewrite test/index.html (88%) rewrite test/spec.core.js (98%) rewrite test/spec.goto.js (98%) rewrite test/spec.hash.js (80%) rewrite test/spec.menu.js (94%) rewrite test/spec.navigation.js (95%) rewrite test/spec.scale.js (96%) rewrite test/spec.status.js (93%) rewrite themes/transition/fade.scss (84%) rewrite themes/transition/horizontal-slide.scss (86%) rewrite themes/transition/vertical-slide.scss (86%) diff --git a/.gitignore b/.gitignore index cedd4ec..8dc6875 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .DS_Store -.sass-cache/ -progress/ \ No newline at end of file +.sass-cache/ \ No newline at end of file diff --git a/boilerplate.html b/boilerplate.html dissimilarity index 77% index 35f9557..bf9adc6 100644 --- a/boilerplate.html +++ b/boilerplate.html @@ -1,99 +1,99 @@ - - - - - - - - Your deck.js Presentation - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
-

Slide

-
- -
-

Content

-
- -
-

Here

-
- - - - - - - - - - -

- - / - -

- - -
- - - - -
- - - # - - -
- - - - - - - - - - - - - - - - - - + + + + + + + + Your deck.js Presentation + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+

Slide

+
+ +
+

Content

+
+ +
+

Here

+
+ + + + + + + + + + +

+ + / + +

+ + +
+ + + + +
+ + + # + + +
+ + + + + + + + + + + + + + + + + + diff --git a/core/deck.core.js b/core/deck.core.js dissimilarity index 93% index 8e1b928..b82ad3e 100644 --- a/core/deck.core.js +++ b/core/deck.core.js @@ -1,477 +1,525 @@ -/*! -Deck JS - deck.core -Copyright (c) 2011 Caleb Troughton -Dual licensed under the MIT license and GPL license. -https://github.com/imakewebthings/deck.js/blob/master/MIT-license.txt -https://github.com/imakewebthings/deck.js/blob/master/GPL-license.txt -*/ - -/* -The deck.core module provides all the basic functionality for creating and -moving through a deck. It does so by applying 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 navigating the deck and inspecting -its state, as well as basic key bindings for going to the next and previous -slides. More functionality is provided by wholly separate extension modules -that use the API provided by core. -*/ -(function($, deck, document, undefined) { - var slides, // Array of all the uh, slides... - current, // Array index of the current slide - $container, // Keeping this cached - - events = { - /* - This event fires at the beginning of a slide change, before the actual - change occurs. Its purpose is to give extension authors a way to prevent - the slide change from occuring. This is done by calling preventDefault - on the event object within this event. If that is done, the deck.change - event will never be fired and the slide will not change. - */ - beforeChange: 'deck.beforeChange', - - /* - This event fires whenever the current slide changes, whether by way of - next, prev, or go. The callback function is passed two parameters, from - and to, equal to the indices of the old slide and the new slide - respectively. If preventDefault is called on the event within this handler - the slide change does not occur. - - $(document).bind('deck.change', function(event, from, to) { - alert('Moving from slide ' + from + ' to ' + to); - }); - */ - change: 'deck.change', - - /* - This event fires at the beginning of deck initialization, after the options - are set but before the slides array is created. This event makes a good hook - for preprocessing extensions looking to modify the deck. - */ - beforeInitialize: 'deck.beforeInit', - - /* - 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 .deck event - namespace, as with the example below: - - var $d = $(document); - $.deck.defaults.keys.myExtensionKeycode = 70; // 'h' - $d.bind('deck.init', function() { - $d.bind('keydown.deck', function(event) { - if (event.which === $.deck.getOptions().keys.myExtensionKeycode) { - // Rock out - } - }); - }); - */ - initialize: 'deck.init' - }, - - options = {}, - $d = $(document), - - /* - Internal function. Updates slide and container classes based on which - slide is the current slide. - */ - updateStates = function() { - var oc = options.classes, - osc = options.selectors.container, - old = $container.data('onSlide'), - $all = $(); - - // Container state - $container.removeClass(oc.onPrefix + old) - .addClass(oc.onPrefix + current) - .data('onSlide', current); - - // Remove and re-add child-current classes for nesting - $('.' + oc.current).parentsUntil(osc).removeClass(oc.childCurrent); - slides[current].parentsUntil(osc).addClass(oc.childCurrent); - - // Remove previous states - $.each(slides, function(i, el) { - $all = $all.add(el); - }); - $all.removeClass([ - oc.before, - oc.previous, - oc.current, - oc.next, - oc.after - ].join(" ")); - - // Add new states back in - slides[current].addClass(oc.current); - if (current > 0) { - slides[current-1].addClass(oc.previous); - } - if (current + 1 < slides.length) { - slides[current+1].addClass(oc.next); - } - if (current > 1) { - $.each(slides.slice(0, current - 1), function(i, el) { - el.addClass(oc.before); - }); - } - if (current + 2 < slides.length) { - $.each(slides.slice(current+2), function(i, el) { - el.addClass(oc.after); - }); - } - }, - - /* Methods exposed in the jQuery.deck namespace */ - methods = { - - /* - jQuery.deck(selector, options) - - selector: string | jQuery | array - 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. - - $.deck('.slide'); - - or - - $.deck([ - '#first-slide', - '#second-slide', - '#etc' - ]); - */ - init: function(elements, opts) { - var startTouch, - tolerance, - esp = function(e) { - e.stopPropagation(); - }; - - options = $.extend(true, {}, $[deck].defaults, opts); - slides = []; - current = 0; - $container = $(options.selectors.container); - tolerance = options.touch.swipeTolerance; - - // Pre init event for preprocessing hooks - $d.trigger(events.beforeInitialize); - - // Hide the deck while states are being applied to kill transitions - $container.addClass(options.classes.loading); - - // Fill slides array depending on parameter type - if ($.isArray(elements)) { - $.each(elements, function(i, e) { - slides.push($(e)); - }); - } - else { - $(elements).each(function(i, e) { - slides.push($(e)); - }); - } - - /* Remove any previous bindings, and rebind key events */ - $d.unbind('keydown.deck').bind('keydown.deck', function(e) { - if (e.which === options.keys.next || $.inArray(e.which, options.keys.next) > -1) { - methods.next(); - e.preventDefault(); - } - else if (e.which === options.keys.previous || $.inArray(e.which, options.keys.previous) > -1) { - methods.prev(); - e.preventDefault(); - } - }) - /* Stop propagation of key events within editable elements */ - .undelegate('input, textarea, select, button, meter, progress, [contentEditable]', 'keydown', esp) - .delegate('input, textarea, select, button, meter, progress, [contentEditable]', 'keydown', esp); - - /* Bind touch events for swiping between slides on touch devices */ - $container.unbind('touchstart.deck').bind('touchstart.deck', function(e) { - if (!startTouch) { - startTouch = $.extend({}, e.originalEvent.targetTouches[0]); - } - }) - .unbind('touchmove.deck').bind('touchmove.deck', function(e) { - $.each(e.originalEvent.changedTouches, function(i, t) { - if (startTouch && t.identifier === startTouch.identifier) { - if (t.screenX - startTouch.screenX > tolerance || t.screenY - startTouch.screenY > tolerance) { - $[deck]('prev'); - startTouch = undefined; - } - else if (t.screenX - startTouch.screenX < -1 * tolerance || t.screenY - startTouch.screenY < -1 * tolerance) { - $[deck]('next'); - startTouch = undefined; - } - return false; - } - }); - e.preventDefault(); - }) - .unbind('touchend.deck').bind('touchend.deck', function(t) { - $.each(t.originalEvent.changedTouches, function(i, t) { - if (startTouch && t.identifier === startTouch.identifier) { - startTouch = undefined; - } - }); - }) - .scrollLeft(0).scrollTop(0); - - /* - Kick iframe videos, which dont like to redraw w/ transforms. - Remove this if Webkit ever fixes it. - */ - $.each(slides, function(i, $el) { - $el.unbind('webkitTransitionEnd.deck').bind('webkitTransitionEnd.deck', - function(event) { - if ($el.hasClass($[deck]('getOptions').classes.current)) { - var embeds = $(this).find('iframe').css('opacity', 0); - window.setTimeout(function() { - embeds.css('opacity', 1); - }, 100); - } - }); - }); - - if (slides.length) { - updateStates(); - } - - // Show deck again now that slides are in place - $container.removeClass(options.classes.loading); - $d.trigger(events.initialize); - }, - - /* - jQuery.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. - */ - go: function(index) { - var e = $.Event(events.beforeChange), - ndx; - - /* Number index, easy. */ - if (typeof index === 'number' && index >= 0 && index < slides.length) { - ndx = index; - } - /* Id string index, search for it and set integer index */ - else if (typeof index === 'string') { - $.each(slides, function(i, $slide) { - if ($slide.attr('id') === index) { - ndx = i; - return false; - } - }); - }; - - /* Out of bounds, id doesn't exist, illegal input, eject */ - if (typeof ndx === 'undefined') return; - - /* Trigger beforeChange. If nothing prevents the change, trigger - the slide change. */ - $d.trigger(e, [current, ndx]); - if (!e.isDefaultPrevented()) { - $d.trigger(events.change, [current, ndx]); - current = ndx; - updateStates(); - } - }, - - /* - jQuery.deck('next') - - Moves to the next slide. If the last slide is already active, the call - is ignored. - */ - next: function() { - methods.go(current+1); - }, - - /* - jQuery.deck('prev') - - Moves to the previous slide. If the first slide is already active, the - call is ignored. - */ - prev: function() { - methods.go(current-1); - }, - - /* - jQuery.deck('getSlide', index) - - index: integer, optional - - Returns a jQuery object containing the slide at index. If index is not - specified, the current slide is returned. - */ - getSlide: function(index) { - var i = typeof index !== 'undefined' ? index : current; - if (typeof i != 'number' || i < 0 || i >= slides.length) return null; - return slides[i]; - }, - - /* - jQuery.deck('getSlides') - - Returns all slides as an array of jQuery objects. - */ - getSlides: function() { - return slides; - }, - - /* - jQuery.deck('getContainer') - - Returns a jQuery object containing the deck container as defined by the - container option. - */ - getContainer: function() { - return $container; - }, - - /* - jQuery.deck('getOptions') - - Returns the options object for the deck, including any overrides that - were defined at initialization. - */ - getOptions: function() { - return options; - }, - - /* - jQuery.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'); - */ - extend: function(name, method) { - methods[name] = method; - } - }; - - /* jQuery extension */ - $[deck] = function(method, arg) { - if (methods[method]) { - return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); - } - else { - return methods.init(method, arg); - } - }; - - /* - The default settings object for a deck. All deck extensions should extend - this object to add defaults for any of their options. - - options.classes.after - This class is added to all slides that appear after the 'next' slide. - - options.classes.before - This class is added to all slides that appear before the 'previous' - slide. - - options.classes.childCurrent - This class is added to all elements in the DOM tree between the - 'current' slide and the deck container. For standard slides, this is - mostly seen and used for nested slides. - - options.classes.current - This class is added to the current slide. - - options.classes.loading - This class is applied to the deck container during loading phases and is - primarily used as a way to short circuit transitions between states - where such transitions are distracting or unwanted. For example, this - class is applied during deck initialization and then removed to prevent - all the slides from appearing stacked and transitioning into place - on load. - - options.classes.next - This class is added to the slide immediately following the 'current' - slide. - - options.classes.onPrefix - This prefix, concatenated with the current slide index, is added to the - deck container as you change slides. - - options.classes.previous - This class is added to the slide immediately preceding the 'current' - slide. - - options.selectors.container - Elements matched by this CSS selector will be considered the deck - container. The deck container is used to scope certain states of the - deck, as with the onPrefix option, or with extensions such as deck.goto - and deck.menu. - - options.keys.next - The numeric keycode used to go to the next slide. - - options.keys.previous - The numeric keycode used to go to the previous slide. - - options.touch.swipeTolerance - The number of pixels the users finger must travel to produce a swipe - gesture. - */ - $[deck].defaults = { - classes: { - after: 'deck-after', - before: 'deck-before', - childCurrent: 'deck-child-current', - current: 'deck-current', - loading: 'deck-loading', - next: 'deck-next', - onPrefix: 'on-slide-', - previous: 'deck-previous' - }, - - selectors: { - container: '.deck-container' - }, - - keys: { - // enter, space, page down, right arrow, down arrow, - next: [13, 32, 34, 39, 40], - // backspace, page up, left arrow, up arrow - previous: [8, 33, 37, 38] - }, - - touch: { - swipeTolerance: 60 - } - }; - - $d.ready(function() { - $('html').addClass('ready'); - }); -})(jQuery, 'deck', document); +/*! +Deck JS - deck.core +Copyright (c) 2011 Caleb Troughton +Dual licensed under the MIT license and GPL license. +https://github.com/imakewebthings/deck.js/blob/master/MIT-license.txt +https://github.com/imakewebthings/deck.js/blob/master/GPL-license.txt +*/ + +/* +The deck.core module provides all the basic functionality for creating and +moving through a deck. It does so by applying 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 navigating the deck and inspecting +its state, as well as basic key bindings for going to the next and previous +slides. More functionality is provided by wholly separate extension modules +that use the API provided by core. +*/ +(function($, undefined) { + var slides, currentIndex, $container; + + var events = { + /* + This event fires at the beginning of a slide change, before the actual + change occurs. Its purpose is to give extension authors a way to prevent + the slide change from occuring. This is done by calling preventDefault + on the event object within this event. If that is done, the deck.change + event will never be fired and the slide will not change. + */ + beforeChange: 'deck.beforeChange', + + /* + This event fires whenever the current slide changes, whether by way of + next, prev, or go. The callback function is passed two parameters, from + and to, equal to the indices of the old slide and the new slide + respectively. If preventDefault is called on the event within this handler + the slide change does not occur. + + $(document).bind('deck.change', function(event, from, to) { + alert('Moving from slide ' + from + ' to ' + to); + }); + */ + change: 'deck.change', + + /* + This event fires at the beginning of deck initialization, after the options + are set but before the slides array is created. This event makes a good hook + for preprocessing extensions looking to modify the deck. + */ + beforeInitialize: 'deck.beforeInit', + + /* + 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 .deck event + namespace, as with the example below: + + var $d = $(document); + $.deck.defaults.keys.myExtensionKeycode = 70; // 'h' + $d.bind('deck.init', function() { + $d.bind('keydown.deck', function(event) { + if (event.which === $.deck.getOptions().keys.myExtensionKeycode) { + // Rock out + } + }); + }); + */ + initialize: 'deck.init' + }; + + var options = {}; + var $document = $(document); + var stopPropagation = function(event) { + event.stopPropagation(); + }; + + var updateContainerState = function() { + var oldIndex = $container.data('onSlide'); + $container.removeClass(options.classes.onPrefix + oldIndex); + $container.addClass(options.classes.onPrefix + currentIndex); + $container.data('onSlide', currentIndex); + }; + + var updateChildCurrent = function() { + var $oldCurrent = $('.' + options.classes.current); + var $oldParents = $oldCurrent.parentsUntil(options.selectors.container); + var $newCurrent = slides[currentIndex]; + var $newParents = $newCurrent.parentsUntil(options.selectors.container); + $oldParents.removeClass(options.classes.childCurrent); + $newParents.addClass(options.classes.childCurrent); + }; + + var removeOldSlideStates = function() { + var $all = $(); + $.each(slides, function(i, el) { + $all = $all.add(el); + }); + $all.removeClass([ + options.classes.before, + options.classes.previous, + options.classes.current, + options.classes.next, + options.classes.after + ].join(' ')); + }; + + var addNewSlideStates = function() { + slides[currentIndex].addClass(options.classes.current); + if (currentIndex > 0) { + slides[currentIndex-1].addClass(options.classes.previous); + } + if (currentIndex + 1 < slides.length) { + slides[currentIndex+1].addClass(options.classes.next); + } + if (currentIndex > 1) { + $.each(slides.slice(0, currentIndex - 1), function(i, $slide) { + $slide.addClass(options.classes.before); + }); + } + if (currentIndex + 2 < slides.length) { + $.each(slides.slice(currentIndex+2), function(i, $slide) { + $slide.addClass(options.classes.after); + }); + } + }; + + var updateStates = function() { + updateContainerState(); + updateChildCurrent(); + removeOldSlideStates(); + addNewSlideStates(); + }; + + var initSlidesArray = function(elements) { + if ($.isArray(elements)) { + $.each(elements, function(i, element) { + slides.push($(element)); + }); + } + else { + $(elements).each(function(i, element) { + slides.push($(element)); + }); + } + }; + + var bindKeyEvents = function() { + var editables = [ + 'input', + 'textarea', + 'select', + 'button', + 'meter', + 'progress', + '[contentEditable]' + ].join(', '); + + $document.unbind('keydown.deck').bind('keydown.deck', function(event) { + var isNext = event.which === options.keys.next; + var isPrev = event.which === options.keys.previous; + isNext = isNext || $.inArray(event.which, options.keys.next) > -1; + isPrev = isPrev || $.inArray(event.which, options.keys.previous) > -1; + + if (isNext) { + methods.next(); + event.preventDefault(); + } + else if (isPrev) { + methods.prev(); + event.preventDefault(); + } + }); + + $document.undelegate(editables, 'keydown.deck', stopPropagation); + $document.delegate(editables, 'keydown.deck', stopPropagation); + }; + + var bindTouchEvents = function() { + var startTouch; + + $container.unbind('touchstart.deck'); + $container.bind('touchstart.deck', function(event) { + if (!startTouch) { + startTouch = $.extend({}, event.originalEvent.targetTouches[0]); + } + }); + + $container.unbind('touchmove.deck'); + $container.bind('touchmove.deck', function(event) { + $.each(event.originalEvent.changedTouches, function(i, touch) { + if (!startTouch || touch.identifier !== startTouch.identifier) { + return true; + } + var xDistance = touch.screenX - startTouch.screenX; + var yDistance = touch.screenY - startTouch.screenY; + var swipedLeftToRight = xDistance > options.touch.swipeTolerance; + var swipedRightToLeft = xDistance < -options.touch.swipeTolerance; + var swipedTopToBottom = yDistance > options.touch.swipeTolerance; + var swipedBottomToTop = yDistance < -options.touch.swipeTolerance; + + if (swipedLeftToRight || swipedTopToBottom) { + $.deck('prev'); + startTouch = undefined; + } + else if (swipedRightToLeft || swipedBottomToTop) { + $.deck('next'); + startTouch = undefined; + } + return false; + }); + event.preventDefault(); + }); + + $container.unbind('touchend.deck'); + $container.bind('touchend.deck', function(event) { + $.each(event.originalEvent.changedTouches, function(i, touch) { + if (startTouch && touch.identifier === startTouch.identifier) { + startTouch = undefined; + } + }); + }); + }; + + /* + Kick iframe videos, which dont like to redraw w/ transforms. + Remove this if Webkit ever fixes it. + */ + var hackWebkitIframes = function() { + $.each(slides, function(i, $slide) { + $slide.unbind('webkitTransitionEnd.deck'); + $slide.bind('webkitTransitionEnd.deck', function(event) { + if ($el.hasClass($.deck('getOptions').classes.current)) { + var embeds = $(this).find('iframe').css('opacity', 0); + window.setTimeout(function() { + embeds.css('opacity', 1); + }, 100); + } + }); + }); + }; + + var indexInBounds = function(index) { + return typeof index === 'number' && index >=0 && index < slides.length; + }; + + /* Methods exposed in the jQuery.deck namespace */ + var methods = { + + /* + jQuery.deck(selector, options) + + selector: string | jQuery | array + 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. + + $.deck('.slide'); + + or + + $.deck([ + '#first-slide', + '#second-slide', + '#etc' + ]); + */ + init: function(elements, opts) { + options = $.extend(true, {}, $.deck.defaults, opts); + slides = []; + currentIndex = 0; + $container = $(options.selectors.container); + tolerance = options.touch.swipeTolerance; + + // Pre init event for preprocessing hooks + $document.trigger(events.beforeInitialize); + + // Hide the deck while states are being applied to kill transitions + $container.addClass(options.classes.loading); + + initSlidesArray(elements); + bindKeyEvents(); + bindTouchEvents(); + // hackWebkitIframes(); + $container.scrollLeft(0).scrollTop(0); + + if (slides.length) { + updateStates(); + } + + // Show deck again now that slides are in place + $container.removeClass(options.classes.loading); + $document.trigger(events.initialize); + }, + + /* + jQuery.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. + */ + go: function(indexOrId) { + var beforeChangeEvent = $.Event(events.beforeChange); + var index; + + /* Number index, easy. */ + if (indexInBounds(indexOrId)) { + index = indexOrId; + } + /* Id string index, search for it and set integer index */ + else if (typeof indexOrId === 'string') { + $.each(slides, function(i, $slide) { + if ($slide.attr('id') === indexOrId) { + index = i; + return false; + } + }); + } + if (typeof index === 'undefined') { + return; + } + + /* Trigger beforeChange. If nothing prevents the change, trigger + the slide change. */ + $document.trigger(beforeChangeEvent, [currentIndex, index]); + if (!beforeChangeEvent.isDefaultPrevented()) { + $document.trigger(events.change, [currentIndex, index]); + currentIndex = index; + updateStates(); + } + }, + + /* + jQuery.deck('next') + + Moves to the next slide. If the last slide is already active, the call + is ignored. + */ + next: function() { + methods.go(currentIndex+1); + }, + + /* + jQuery.deck('prev') + + Moves to the previous slide. If the first slide is already active, the + call is ignored. + */ + prev: function() { + methods.go(currentIndex-1); + }, + + /* + jQuery.deck('getSlide', index) + + index: integer, optional + + Returns a jQuery object containing the slide at index. If index is not + specified, the current slide is returned. + */ + getSlide: function(index) { + index = typeof index !== 'undefined' ? index : currentIndex; + if (!indexInBounds(index)) { + return null; + } + return slides[index]; + }, + + /* + jQuery.deck('getSlides') + + Returns all slides as an array of jQuery objects. + */ + getSlides: function() { + return slides; + }, + + /* + jQuery.deck('getContainer') + + Returns a jQuery object containing the deck container as defined by the + container option. + */ + getContainer: function() { + return $container; + }, + + /* + jQuery.deck('getOptions') + + Returns the options object for the deck, including any overrides that + were defined at initialization. + */ + getOptions: function() { + return options; + }, + + /* + jQuery.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'); + */ + extend: function(name, method) { + methods[name] = method; + } + }; + + /* jQuery extension */ + $.deck = function(method, arg) { + var args = Array.prototype.slice.call(arguments, 1); + if (methods[method]) { + return methods[method].apply(this, args); + } + else { + return methods.init(method, arg); + } + }; + + /* + The default settings object for a deck. All deck extensions should extend + this object to add defaults for any of their options. + + options.classes.after + This class is added to all slides that appear after the 'next' slide. + + options.classes.before + This class is added to all slides that appear before the 'previous' + slide. + + options.classes.childCurrent + This class is added to all elements in the DOM tree between the + 'current' slide and the deck container. For standard slides, this is + mostly seen and used for nested slides. + + options.classes.current + This class is added to the current slide. + + options.classes.loading + This class is applied to the deck container during loading phases and is + primarily used as a way to short circuit transitions between states + where such transitions are distracting or unwanted. For example, this + class is applied during deck initialization and then removed to prevent + all the slides from appearing stacked and transitioning into place + on load. + + options.classes.next + This class is added to the slide immediately following the 'current' + slide. + + options.classes.onPrefix + This prefix, concatenated with the current slide index, is added to the + deck container as you change slides. + + options.classes.previous + This class is added to the slide immediately preceding the 'current' + slide. + + options.selectors.container + Elements matched by this CSS selector will be considered the deck + container. The deck container is used to scope certain states of the + deck, as with the onPrefix option, or with extensions such as deck.goto + and deck.menu. + + options.keys.next + The numeric keycode used to go to the next slide. + + options.keys.previous + The numeric keycode used to go to the previous slide. + + options.touch.swipeTolerance + The number of pixels the users finger must travel to produce a swipe + gesture. + */ + $.deck.defaults = { + classes: { + after: 'deck-after', + before: 'deck-before', + childCurrent: 'deck-child-current', + current: 'deck-current', + loading: 'deck-loading', + next: 'deck-next', + onPrefix: 'on-slide-', + previous: 'deck-previous' + }, + + selectors: { + container: '.deck-container' + }, + + keys: { + // enter, space, page down, right arrow, down arrow, + next: [13, 32, 34, 39, 40], + // backspace, page up, left arrow, up arrow + previous: [8, 33, 37, 38] + }, + + touch: { + swipeTolerance: 60 + } + }; + + $document.ready(function() { + $('html').addClass('ready'); + }); +})(jQuery); diff --git a/core/deck.core.scss b/core/deck.core.scss dissimilarity index 68% index a7e12ff..baab0fd 100755 --- a/core/deck.core.scss +++ b/core/deck.core.scss @@ -1,65 +1,65 @@ -html, body { - height:100%; - padding:0; - margin:0; -} - -.deck-container { - position:relative; - min-height:100%; - margin:0 auto; - overflow:hidden; - overflow-y:auto; - - .js & { - visibility:hidden; - } - - .ready & { - visibility:visible; - } - - .touch & { - -webkit-text-size-adjust:none; - -moz-text-size-adjust:none; - } -} - -.deck-loading { - display:none; -} - -.slide { - width:auto; - min-height:100%; - position:relative; -} - -.deck-before, .deck-previous, .deck-next, .deck-after { - position:absolute; - left:-999em; - top:-999em; -} - -.deck-current { - z-index:2; -} - -.slide .slide { - visibility:hidden; - position:static; - min-height:0; -} - -.deck-child-current { - position:static; - z-index:2; - - .slide { - visibility:hidden; - } - - .deck-previous, .deck-before, .deck-current { - visibility:visible; - } -} \ No newline at end of file +html, body { + height:100%; + padding:0; + margin:0; +} + +.deck-container { + position:relative; + min-height:100%; + margin:0 auto; + overflow:hidden; + overflow-y:auto; + + .js & { + visibility:hidden; + } + + .ready & { + visibility:visible; + } + + .touch & { + -webkit-text-size-adjust:none; + -moz-text-size-adjust:none; + } +} + +.deck-loading { + display:none; +} + +.slide { + width:auto; + min-height:100%; + position:relative; +} + +.deck-before, .deck-previous, .deck-next, .deck-after { + position:absolute; + left:-999em; + top:-999em; +} + +.deck-current { + z-index:2; +} + +.slide .slide { + visibility:hidden; + position:static; + min-height:0; +} + +.deck-child-current { + position:static; + z-index:2; + + .slide { + visibility:hidden; + } + + .deck-previous, .deck-before, .deck-current { + visibility:visible; + } +} \ No newline at end of file diff --git a/extensions/goto/deck.goto.html b/extensions/goto/deck.goto.html index e3b6a18..4b73998 100644 --- a/extensions/goto/deck.goto.html +++ b/extensions/goto/deck.goto.html @@ -1,7 +1,7 @@
- - - - + + + +
\ No newline at end of file diff --git a/extensions/goto/deck.goto.js b/extensions/goto/deck.goto.js dissimilarity index 88% index eedba10..5992444 100644 --- a/extensions/goto/deck.goto.js +++ b/extensions/goto/deck.goto.js @@ -1,170 +1,189 @@ -/*! -Deck JS - deck.goto -Copyright (c) 2011 Caleb Troughton -Dual licensed under the MIT license and GPL license. -https://github.com/imakewebthings/deck.js/blob/master/MIT-license.txt -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/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. -*/ -(function($, deck, undefined) { - var $d = $(document); - - /* - Extends defaults/options. - - options.classes.goto - 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/id in the gotoInput - element. - - options.selectors.gotoInput - The element that matches this selector is the text input field for - entering a slide number/id in the Go To Slide form. - - options.keys.goto - The numeric keycode used to show the Go To Slide form. - - options.countNested - If false, only top level slides will be counted when entering a - slide number. - */ - $.extend(true, $[deck].defaults, { - classes: { - goto: 'deck-goto' - }, - - selectors: { - gotoDatalist: '#goto-datalist', - gotoForm: '.goto-form', - gotoInput: '#goto-slide' - }, - - keys: { - goto: 71 // g - }, - - countNested: true - }); - - /* - jQuery.deck('showGoTo') - - Shows the Go To Slide form by adding the class specified by the goto class - option to the deck container. - */ - $[deck]('extend', 'showGoTo', function() { - $[deck]('getContainer').addClass($[deck]('getOptions').classes.goto); - $($[deck]('getOptions').selectors.gotoInput).focus(); - }); - - /* - jQuery.deck('hideGoTo') - - Hides the Go To Slide form by removing the class specified by the goto class - option from the deck container. - */ - $[deck]('extend', 'hideGoTo', function() { - $($[deck]('getOptions').selectors.gotoInput).blur(); - $[deck]('getContainer').removeClass($[deck]('getOptions').classes.goto); - }); - - /* - jQuery.deck('toggleGoTo') - - Toggles between showing and hiding the Go To Slide form. - */ - $[deck]('extend', 'toggleGoTo', function() { - $[deck]($[deck]('getContainer').hasClass($[deck]('getOptions').classes.goto) ? 'hideGoTo' : 'showGoTo'); - }); - - $d.bind('deck.init', function() { - var opts = $[deck]('getOptions'), - $datalist = $(opts.selectors.gotoDatalist), - slideTest = $.map([ - opts.classes.before, - opts.classes.previous, - opts.classes.current, - opts.classes.next, - opts.classes.after - ], function(el, i) { - return '.' + el; - }).join(', '), - rootCounter = 1; - - // 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) { - e.preventDefault(); - $[deck]('toggleGoTo'); - } - }); - - /* Populate datalist and work out countNested*/ - $.each($[deck]('getSlides'), function(i, $slide) { - var id = $slide.attr('id'), - $parentSlides = $slide.parentsUntil(opts.selectors.container, slideTest); - - if (id) { - $datalist.append('