Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ stop | Stop the switching
toggle | Toggle between start/stop
reset | Return to the first switching
select | Select the switching at index
current | Return current index
next | Go to the next switching
prev | Go to the previous switching
destroy | !!Destroy BgSwitcher!!
Expand Down
7 changes: 7 additions & 0 deletions jquery.bgswitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@
this.switching();
},

/**
* Return current index
*/
current: function() {
return this.index
},

/**
* Switching the background image
*/
Expand Down
13 changes: 13 additions & 0 deletions test/bg_switcher_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ describe('jQuery.BgSwitcher', function() {
});
});

describe('#current', function() {
beforeEach(function() {
bs.setConfig({images: ['foo', 'bar', 'baz']});
});

it('return current index', function() {
bs.select(2);
expect(bs.current()).to.be(2);
bs.prev();
expect(bs.current()).to.be(1);
});
});

describe('#switching', function() {
beforeEach(function() {
bs.setConfig({interval: INTERVAL});
Expand Down