diff --git a/core/deck.core.js b/core/deck.core.js index 35f8d46a..4c415581 100644 --- a/core/deck.core.js +++ b/core/deck.core.js @@ -482,6 +482,44 @@ that use the API provided by core. return slides; }, + /* + jQuery.deck('getTopLevelSlides') + + Returns all slides that are not subslides. + */ + getTopLevelSlides: function() { + var topLevelSlides = []; + var slideSelector = options.selectors.slides; + var subSelector = [slideSelector, slideSelector].join(' '); + $.each(slides, function(i, $slide) { + if (!$slide.is(subSelector)) { + topLevelSlides.push($slide); + } + }); + return topLevelSlides; + }, + + /* + jQuery.deck('getNestedSlides', index) + + index: integer, optional + + Returns all the nested slides of the current slide. If index is + specified it returns the nested slides of the slide at that index. + If there are no nested slides this will return an empty array. + */ + getNestedSlides: function(index) { + debugger; + var targetIndex = index == null ? currentIndex : index; + var $targetSlide = $.deck('getSlide', targetIndex); + var $nesteds = $targetSlide.find(options.selectors.slides); + var nesteds = $nesteds.get(); + return $.map(nesteds, function(slide, i) { + return $(slide); + }); + }, + + /* jQuery.deck('getContainer') diff --git a/test/fixtures/nesteds.html b/test/fixtures/nesteds.html index 564a7ca9..cb0e2e5a 100644 --- a/test/fixtures/nesteds.html +++ b/test/fixtures/nesteds.html @@ -1,11 +1,11 @@
-
+
-
+
-
+
@@ -16,10 +16,10 @@
-
+
-
+

@@ -33,4 +33,4 @@ -

\ No newline at end of file +
diff --git a/test/index.html b/test/index.html index 333122ea..f8454e83 100644 --- a/test/index.html +++ b/test/index.html @@ -24,7 +24,6 @@ - diff --git a/test/spec.core.js b/test/spec.core.js index 7da35bad..5b3e5bf1 100755 --- a/test/spec.core.js +++ b/test/spec.core.js @@ -146,6 +146,33 @@ describe('Deck JS', function() { expect($.deck('getOptions')).toEqual(defaults); }); }); + + describe('getTopLevelSlides()', function() { + it('should return only root slides', function() { + loadFixtures('nesteds.html'); + $.deck(); + var expectation = []; + var topLevelSlides = $.deck('getTopLevelSlides'); + $('.toplevel').each(function() { + expectation.push($(this)); + }); + expect(topLevelSlides).toEqual(expectation); + }); + }); + + describe('getNestedSlides()', function() { + it('should return nested slides for current slide', function() { + loadFixtures('nesteds.html'); + $.deck(); + $.deck('go', 2); + var expectation = []; + var nestedSlides = $.deck('getNestedSlides'); + $.deck('getSlide').find('.slide').each(function() { + expectation.push($(this)); + }); + expect(nestedSlides).toEqual(expectation); + }); + }); }); describe('container states', function() {