Author: johnh
Date: Mon May 10 23:00:05 2010
New Revision: 942942
URL: http://svn.apache.org/viewvc?rev=942942&view=rev
Log:
Add support for reading from and writing to user pref "selectedTab" to the tabs
lib.
Modified:
shindig/trunk/features/src/main/javascript/features/tabs/feature.xml
shindig/trunk/features/src/main/javascript/features/tabs/tabs.js
Modified: shindig/trunk/features/src/main/javascript/features/tabs/feature.xml
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/tabs/feature.xml?rev=942942&r1=942941&r2=942942&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/tabs/feature.xml
(original)
+++ shindig/trunk/features/src/main/javascript/features/tabs/feature.xml Mon
May 10 23:00:05 2010
@@ -19,6 +19,7 @@ specific language governing permissions
<feature>
<name>tabs</name>
<dependency>globals</dependency>
+ <dependency>core.prefs</dependency>
<gadget>
<script src="tabs.js"/>
<script src="taming.js"/>
Modified: shindig/trunk/features/src/main/javascript/features/tabs/tabs.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/tabs/tabs.js?rev=942942&r1=942941&r2=942942&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/tabs/tabs.js (original)
+++ shindig/trunk/features/src/main/javascript/features/tabs/tabs.js Mon May 10
23:00:05 2010
@@ -118,6 +118,8 @@ gadgets.TabSet = function(opt_moduleId,
this.navTable_ = null;
this.tabsContainer_ = null;
this.rtl_ = document.body.dir === 'rtl';
+ this.prefs_ = new gadgets.Prefs();
+ this.selectedTabIndex_ = this.prefs_.getString("selectedTab");
this.mainContainer_ = this.createMainContainer_(opt_container);
this.tabTable_ = this.createTabTable_();
this.displayTabs(false);
@@ -223,6 +225,9 @@ gadgets.TabSet.prototype.addTab = functi
this.tabs_.push(tab);
} else {
this.tabs_.splice(tabIndex, 0, tab);
+
+ // Inserting may change selected tab's index
+ this.saveSelectedTabIndex_();
}
if (tabName == this.defaultTabName_ || (!this.defaultTabName_ && tabIndex
=== 0)) {
@@ -616,7 +621,7 @@ gadgets.TabSet.prototype.setSelectedTabG
* @param {gadgets.Tab} tab The tab to select.
* @private
*/
-gadgets.TabSet.prototype.selectTab_ = function(tab) {
+gadgets.TabSet.prototype.selectTab_ = function(tab, opt_inhibit_save) {
if (this.selectedTab_ === tab) {
return;
}
@@ -633,11 +638,29 @@ gadgets.TabSet.prototype.selectTab_ = fu
tab.contentContainer_.style.display = 'block';
this.selectedTab_ = tab;
+ // Remember which tab is selected only if nosave is not true.
+ var nosave = (opt_inhibit_save === true) ? true : false;
+ if (!nosave) {
+ this.saveSelectedTabIndex_();
+ }
+
if (typeof tab.callback_ === 'function') {
tab.callback_(tab.contentContainer_.id);
}
};
+gadgets.TabSet.prototype.saveSelectedTabIndex_ = function() {
+ try {
+ var currentTabIndex = this.selectedTab_.getIndex();
+ if (currentTabIndex >= 0) {
+ this.selectedTabIndex_ = currentTabIndex;
+ this.prefs_.set("selectedTab", currentTabIndex);
+ }
+ } catch (e) {
+ // ignore. setprefs is optional for tablib.
+ }
+};
+
// Aliases for legacy code
/**