Skip to content

Commit

Permalink
#148, add getTopLevelSlides and getNestedSlides methods
Browse files Browse the repository at this point in the history
  • Loading branch information
imakewebthings committed Dec 6, 2013
1 parent 3d8fb53 commit 4638a23
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 7 deletions.
38 changes: 38 additions & 0 deletions core/deck.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/nesteds.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="deck-container">
<div class="slide">
<div class="slide toplevel">
</div>

<div class="slide">
<div class="slide toplevel">
</div>

<div class="slide root">
<div class="slide root toplevel">
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
Expand All @@ -16,10 +16,10 @@
</div>
</div>

<div class="slide" id="after">
<div class="slide toplevel" id="after">
</div>

<div class="slide">
<div class="slide toplevel">
</div>

<p class="deck-status">
Expand All @@ -33,4 +33,4 @@
<input type="number" name="slidenum" id="goto-slide" value="">
<input type="submit" value="Go">
</form>
</div>
</div>
1 change: 0 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<script type="text/javascript" src="spec.menu.js"></script>
<script type="text/javascript" src="spec.goto.js"></script>
<script type="text/javascript" src="spec.navigation.js"></script>
<script type="text/javascript" src="spec.hash.js"></script>
<script type="text/javascript" src="spec.status.js"></script>
<script type="text/javascript" src="spec.scale.js"></script>
</head>
Expand Down
27 changes: 27 additions & 0 deletions test/spec.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4638a23

Please sign in to comment.