Make deck.change preventable, closes #48
This commit is contained in:
parent
a68f7e2e1b
commit
75a07a7aa8
2 changed files with 16 additions and 4 deletions
|
@ -25,7 +25,8 @@ that use the API provided by core.
|
|||
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.
|
||||
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);
|
||||
|
@ -249,11 +250,15 @@ that use the API provided by core.
|
|||
or not a number the call is ignored.
|
||||
*/
|
||||
go: function(index) {
|
||||
var e = $.Event(events.change);
|
||||
|
||||
if (typeof index != 'number' || index < 0 || index >= slides.length) return;
|
||||
|
||||
$d.trigger(events.change, [current, index]);
|
||||
current = index;
|
||||
updateStates();
|
||||
$d.trigger(e, [current, index]);
|
||||
if (!e.isDefaultPrevented()) {
|
||||
current = index;
|
||||
updateStates();
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
|
|
|
@ -271,6 +271,13 @@ describe('Deck JS', function() {
|
|||
$.deck('go', 3);
|
||||
$d.unbind('deck.change', f);
|
||||
});
|
||||
|
||||
it('should not change slides if default prevented', function() {
|
||||
$d.bind('deck.change', false);
|
||||
$.deck('go', 3);
|
||||
expect($.deck('getSlide')).toEqual($.deck('getSlide', 1));
|
||||
$d.unbind('deck.change', false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deck.init', function() {
|
||||
|
|
Loading…
Reference in a new issue