From 6e0b82b61fd576d98ed3c35cb7237a252048d3f1 Mon Sep 17 00:00:00 2001 From: imakewebthings Date: Sat, 30 Nov 2013 22:21:32 -0800 Subject: [PATCH] #149, move slide selector to an option, alias old init signature --- core/deck.core.js | 27 ++++++++++++++++++++++----- test/spec.core.js | 37 ++++++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/core/deck.core.js b/core/deck.core.js index a4c619e..a13854a 100644 --- a/core/deck.core.js +++ b/core/deck.core.js @@ -272,10 +272,20 @@ that use the API provided by core. '#etc' ]); */ - init: function(elements, opts) { + init: function(opts) { var beforeInitEvent = createBeforeInitEvent(); + var overrides = opts; - options = $.extend(true, {}, $.deck.defaults, opts); + if (!$.isPlainObject(opts)) { + overrides = arguments[1] || {}; + $.extend(true, overrides, { + selectors: { + slides: arguments[0] + } + }); + } + + options = $.extend(true, {}, $.deck.defaults, overrides); slides = []; currentIndex = 0; $container = $(options.selectors.container); @@ -284,12 +294,12 @@ that use the API provided by core. $container.addClass(options.classes.loading); // populate the array of slides for pre-init - initSlidesArray(elements); + initSlidesArray(options.selectors.slides); // Pre init event for preprocessing hooks beforeInitEvent.done = function() { // re-populate the array of slides slides = []; - initSlidesArray(elements); + initSlidesArray(options.selectors.slides); bindKeyEvents(); bindTouchEvents(); $container.scrollLeft(0).scrollTop(0); @@ -504,6 +514,12 @@ that use the API provided by core. deck, as with the onPrefix option, or with extensions such as deck.goto and deck.menu. + options.selectors.slides + Elements matched by this selector make up the individual deck slides. + If a user chooses to pass the slide selector as the first argument to + $.deck() on initialization it does the same thing as passing in this + option and this option value will be set to the value of that parameter. + options.keys.next The numeric keycode used to go to the next slide. @@ -532,7 +548,8 @@ that use the API provided by core. }, selectors: { - container: '.deck-container' + container: '.deck-container', + slides: '.slide' }, keys: { diff --git a/test/spec.core.js b/test/spec.core.js index 0259ecd..f86f6ac 100755 --- a/test/spec.core.js +++ b/test/spec.core.js @@ -11,9 +11,20 @@ describe('Deck JS', function() { } }); + describe('init(options.selectors.slides)', function() { + it('should create slides', function() { + $.deck({ + selectors: { + slides: '.slide3' + } + }); + expect($.deck('getSlides').length).toEqual($('.slide3').length); + }); + }); + describe('init(selector)', function() { it('should create slides', function() { - $.deck('.slide'); + $.deck(); expect($.deck('getSlides').length).toEqual($('.slide').length); }); }); @@ -33,7 +44,7 @@ describe('Deck JS', function() { describe('navigation functions', function() { beforeEach(function() { - $.deck('.slide'); + $.deck(); }); describe('go(i)', function() { @@ -87,7 +98,7 @@ describe('Deck JS', function() { describe('getters', function() { beforeEach(function() { - $.deck('.slide'); + $.deck(); }); describe('getSlide()', function() { @@ -139,7 +150,7 @@ describe('Deck JS', function() { describe('container states', function() { beforeEach(function() { - $.deck('.slide'); + $.deck(); }); it('should start at state 0', function() { @@ -252,7 +263,7 @@ describe('Deck JS', function() { var index, oldIndex; beforeEach(function() { - $.deck('.slide'); + $.deck(); $.deck('go', 1); $d.one('deck.change', function(event, from, to) { index = to; @@ -291,7 +302,7 @@ describe('Deck JS', function() { describe('deck.init', function() { it('should fire on deck initialization', function() { - $.deck('.slide'); + $.deck(); expect($.deck('getSlides').length).toBeGreaterThan(0); }); }); @@ -307,17 +318,17 @@ describe('Deck JS', function() { }); it('should fire on deck initialization', function() { - $.deck('.slide'); + $.deck(); expect(beforeHit).toBeTruthy(); }); - it('should have not populated the slides array', function() { + it('should have populated the slides array', function() { var f = function() { - expect($.deck('getSlides').length).toEqual(0); + expect($.deck('getSlides').length).toEqual($('.slide').length); }; $d.bind('deck.beforeInit', f); - $.deck('.slide'); + $.deck(); $d.unbind('deck.beforeInit', f); }); @@ -332,7 +343,7 @@ describe('Deck JS', function() { $d.bind('deck.beforeInit', f); $d.bind('deck.init', g); - $.deck('.slide'); + $.deck(); $d.unbind('deck.beforeInit', f); $d.unbind('deck.init', g); expect(initHit).toBeFalsy(); @@ -373,7 +384,7 @@ describe('Deck JS', function() { runs(function() { $d.bind('deck.beforeInit', f); - $.deck('.slide'); + $.deck(); $d.unbind('deck.beforeInit', f); }); @@ -388,7 +399,7 @@ describe('Deck JS', function() { describe('empty deck', function() { beforeEach(function() { loadFixtures('empty.html'); - $.deck('.slide'); + $.deck(); }); describe('getSlide()', function() { -- 2.11.4.GIT