From a0bf8b67ff4dd827f9298563616ecc519e7924c8 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 29 Sep 2011 23:00:10 -0700 Subject: [PATCH] change event to use target and relatedTarget (which more closely resembles actual event api) --- docs/javascript.html | 7 ++++--- js/bootstrap-tabs.js | 12 ++++++++---- js/tests/unit/bootstrap-tabs.js | 30 ++++++++++++++++++------------ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/docs/javascript.html b/docs/javascript.html index 1f5ad1a38f..956dfd0a83 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -368,14 +368,15 @@ $('#my-modal').bind('hidden', function () { change - This event fires on tab change. The event provides an additional parameter which holds the id of the previous tab and the id of the new current tab. This information is stored in an object with two properties called from and to, e.g. { to: '#home', from: '#profile' }. + This event fires on tab change. Use event.target and event.relatedTarget to target the active tab and the previous active tab respectively.
-$('#.tabs').bind('changed', function (e, c) {
-  // do something with c.from and c.to ...
+$('#.tabs').bind('change', function (e) {
+  e.target // activated tab
+  e.relatedTarget // previous tab
 })

Demo

') - , changeCount = 0 - , from - , to; + , $target + , count = 0 + , relatedTarget + , target - $tabsHTML.tabs().bind( "change", function (e, c){ - from = c.from; - to = c.to; - changeCount++ - }) + $tabsHTML + .tabs() + .bind( "change", function (e) { + target = e.target + relatedTarget = e.relatedTarget + count++ + }) - $tabsHTML.tabs().find('a').last().click() + $target = $tabsHTML + .find('a') + .last() + .click() - equals(from, "#home") - equals(to, "#profile") - equals(changeCount, 1) + equals(relatedTarget, $tabsHTML.find('a').first()[0]) + equals(target, $target[0]) + equals(count, 1) }) }) \ No newline at end of file