diff --git a/README.md b/README.md index 6b45306..26e11d5 100644 --- a/README.md +++ b/README.md @@ -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!! diff --git a/jquery.bgswitcher.js b/jquery.bgswitcher.js index b5d200c..6e4ae95 100644 --- a/jquery.bgswitcher.js +++ b/jquery.bgswitcher.js @@ -217,6 +217,13 @@ this.switching(); }, + /** + * Return current index + */ + current: function() { + return this.index + }, + /** * Switching the background image */ diff --git a/test/bg_switcher_spec.js b/test/bg_switcher_spec.js index 8ccb418..f4381a6 100644 --- a/test/bg_switcher_spec.js +++ b/test/bg_switcher_spec.js @@ -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});