Skip to content

Commit

Permalink
#149, move slide selector to an option, alias old init signature
Browse files Browse the repository at this point in the history
  • Loading branch information
imakewebthings committed Dec 1, 2013
1 parent f8fc230 commit 6e0b82b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
27 changes: 22 additions & 5 deletions core/deck.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -532,7 +548,8 @@ that use the API provided by core.
},

selectors: {
container: '.deck-container'
container: '.deck-container',
slides: '.slide'
},

keys: {
Expand Down
37 changes: 24 additions & 13 deletions test/spec.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand All @@ -33,7 +44,7 @@ describe('Deck JS', function() {

describe('navigation functions', function() {
beforeEach(function() {
$.deck('.slide');
$.deck();
});

describe('go(i)', function() {
Expand Down Expand Up @@ -87,7 +98,7 @@ describe('Deck JS', function() {

describe('getters', function() {
beforeEach(function() {
$.deck('.slide');
$.deck();
});

describe('getSlide()', function() {
Expand Down Expand Up @@ -139,7 +150,7 @@ describe('Deck JS', function() {

describe('container states', function() {
beforeEach(function() {
$.deck('.slide');
$.deck();
});

it('should start at state 0', function() {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
});
Expand All @@ -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);
});

Expand All @@ -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();
Expand Down Expand Up @@ -373,7 +384,7 @@ describe('Deck JS', function() {

runs(function() {
$d.bind('deck.beforeInit', f);
$.deck('.slide');
$.deck();
$d.unbind('deck.beforeInit', f);
});

Expand All @@ -388,7 +399,7 @@ describe('Deck JS', function() {
describe('empty deck', function() {
beforeEach(function() {
loadFixtures('empty.html');
$.deck('.slide');
$.deck();
});

describe('getSlide()', function() {
Expand Down

0 comments on commit 6e0b82b

Please sign in to comment.