diff options
| author | Kasper Bøgebjerg Pedersen <[email protected]> | 2011-09-18 10:15:24 +0200 |
|---|---|---|
| committer | Kasper Bøgebjerg Pedersen <[email protected]> | 2011-09-18 10:15:24 +0200 |
| commit | e16de59260c860af67748a484631ae3de56fc244 (patch) | |
| tree | 3af1ddbc4d1abefb185ae6208f3b24dd27577b46 /js | |
| parent | 3eafbe5c8994e884744e4a664be51ab5b6558b80 (diff) | |
| download | bootstrap-e16de59260c860af67748a484631ae3de56fc244.tar.xz bootstrap-e16de59260c860af67748a484631ae3de56fc244.zip | |
Added changed event to bootstrap-tabs.js
Diffstat (limited to 'js')
| -rw-r--r-- | js/bootstrap-tabs.js | 4 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-tabs.js | 38 |
2 files changed, 33 insertions, 9 deletions
diff --git a/js/bootstrap-tabs.js b/js/bootstrap-tabs.js index 807b366a3..380ded17c 100644 --- a/js/bootstrap-tabs.js +++ b/js/bootstrap-tabs.js @@ -30,11 +30,12 @@ , href = $this.attr('href') , $ul = $(e.liveFired) , $controlled + , current = $ul.find('.active a').attr('href') if (/^#\w+/.test(href)) { e.preventDefault() - if ($this.hasClass('active')) { + if ($this.parent('li').hasClass('active')) { return } @@ -42,6 +43,7 @@ activate($this.parent('li'), $ul) activate($href, $href.parent()) + $this.trigger("changed", {from:current, to:href}) } } diff --git a/js/tests/unit/bootstrap-tabs.js b/js/tests/unit/bootstrap-tabs.js index 2ee6761ed..0b92b94db 100644 --- a/js/tests/unit/bootstrap-tabs.js +++ b/js/tests/unit/bootstrap-tabs.js @@ -11,39 +11,61 @@ $(function () { }) test("should activate element by tab id", function () { - var tabsHTML = '<ul class="tabs">' + var $tabsHTML = $('<ul class="tabs">' + '<li class="active"><a href="#home">Home</a></li>' + '<li><a href="#profile">Profile</a></li>' - + '</ul>' + + '</ul>') $('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff") - $(tabsHTML).tabs().find('a').last().click() + $tabsHTML.tabs().find('a').last().click() equals($("#qunit-runoff").find('.active').attr('id'), "profile") - $(tabsHTML).tabs().find('a').first().click() + $tabsHTML.tabs().find('a').first().click() equals($("#qunit-runoff").find('.active').attr('id'), "home") $("#qunit-runoff").empty() }) test("should activate element by pill id", function () { - var pillsHTML = '<ul class="pills">' + var $pillsHTML = $('<ul class="pills">' + '<li class="active"><a href="#home">Home</a></li>' + '<li><a href="#profile">Profile</a></li>' - + '</ul>' + + '</ul>') $('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff") - $(pillsHTML).pills().find('a').last().click() + $pillsHTML.pills().find('a').last().click() equals($("#qunit-runoff").find('.active').attr('id'), "profile") - $(pillsHTML).pills().find('a').first().click() + $pillsHTML.pills().find('a').first().click() equals($("#qunit-runoff").find('.active').attr('id'), "home") $("#qunit-runoff").empty() }) + + test( "should trigger changed event on activate", function () { + var $tabsHTML = $('<ul class="tabs">' + + '<li class="active"><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>') + , changeCount = 0 + , from + , to; + + $tabsHTML.tabs().bind( "changed", function (e, c){ + from = c.from; + to = c.to; + changeCount++ + }) + + $tabsHTML.tabs().find('a').last().click() + + equals(from, "#home") + equals(to, "#profile") + equals(changeCount, 1) + }) })
\ No newline at end of file |
