Fossil SCM

Added the tab manager before-switch-from event.

stephan 2020-05-12 13:19 fileedit-ajaxify
Commit 2863abf5c52c22deb639bf029828a310197e51550b9acd20817bd32abd7abea3
1 file changed +13 -1
--- src/fossil.tabs.js
+++ src/fossil.tabs.js
@@ -147,10 +147,14 @@
147147
/**
148148
Registers an event listener for this object's custom events.
149149
The callback gets a CustomEvent object with a 'detail'
150150
propertly holding any tab-related state for the event. The events
151151
are:
152
+
153
+ - 'before-switch-from' is emitted immediately before a new tab
154
+ is switched away from. detail = the tab element being switched
155
+ away from.
152156
153157
- 'before-switch-to' is emitted immediately before a new tab is
154158
switched to. detail = the tab element.
155159
156160
- 'after-switch-to' is emitted immediately after a new tab is
@@ -167,23 +171,31 @@
167171
},
168172
169173
/**
170174
If the given DOM element, unique selector, or integer (0-based
171175
tab number) is one of this object's tabs, the UI makes that tab
172
- the currently-visible one. Returns this object.
176
+ the currently-visible one, firing any relevant events. Returns
177
+ this object. If the argument is the current tab, this is a
178
+ no-op, and no events are fired.
173179
*/
174180
switchToTab: function(tab){
175181
tab = tabArg(tab,this);
176182
const self = this;
183
+ if(tab===this._currentTab) return this;
184
+ else if(this._currentTab){
185
+ this._dispatchEvent('before-switch-from', this._currentTab);
186
+ }
187
+ delete this._currentTab;
177188
this.e.tabs.childNodes.forEach((e,ndx)=>{
178189
const btn = this.e.tabBar.childNodes[ndx];
179190
if(e===tab){
180191
if(D.hasClass(e,'selected')){
181192
return;
182193
}
183194
self._dispatchEvent('before-switch-to',tab);
184195
setVisible(e, true);
196
+ this._currentTab = e;
185197
D.addClass(btn,'selected');
186198
self._dispatchEvent('after-switch-to',tab);
187199
}else{
188200
if(D.hasClass(e,'selected')){
189201
return;
190202
--- src/fossil.tabs.js
+++ src/fossil.tabs.js
@@ -147,10 +147,14 @@
147 /**
148 Registers an event listener for this object's custom events.
149 The callback gets a CustomEvent object with a 'detail'
150 propertly holding any tab-related state for the event. The events
151 are:
 
 
 
 
152
153 - 'before-switch-to' is emitted immediately before a new tab is
154 switched to. detail = the tab element.
155
156 - 'after-switch-to' is emitted immediately after a new tab is
@@ -167,23 +171,31 @@
167 },
168
169 /**
170 If the given DOM element, unique selector, or integer (0-based
171 tab number) is one of this object's tabs, the UI makes that tab
172 the currently-visible one. Returns this object.
 
 
173 */
174 switchToTab: function(tab){
175 tab = tabArg(tab,this);
176 const self = this;
 
 
 
 
 
177 this.e.tabs.childNodes.forEach((e,ndx)=>{
178 const btn = this.e.tabBar.childNodes[ndx];
179 if(e===tab){
180 if(D.hasClass(e,'selected')){
181 return;
182 }
183 self._dispatchEvent('before-switch-to',tab);
184 setVisible(e, true);
 
185 D.addClass(btn,'selected');
186 self._dispatchEvent('after-switch-to',tab);
187 }else{
188 if(D.hasClass(e,'selected')){
189 return;
190
--- src/fossil.tabs.js
+++ src/fossil.tabs.js
@@ -147,10 +147,14 @@
147 /**
148 Registers an event listener for this object's custom events.
149 The callback gets a CustomEvent object with a 'detail'
150 propertly holding any tab-related state for the event. The events
151 are:
152
153 - 'before-switch-from' is emitted immediately before a new tab
154 is switched away from. detail = the tab element being switched
155 away from.
156
157 - 'before-switch-to' is emitted immediately before a new tab is
158 switched to. detail = the tab element.
159
160 - 'after-switch-to' is emitted immediately after a new tab is
@@ -167,23 +171,31 @@
171 },
172
173 /**
174 If the given DOM element, unique selector, or integer (0-based
175 tab number) is one of this object's tabs, the UI makes that tab
176 the currently-visible one, firing any relevant events. Returns
177 this object. If the argument is the current tab, this is a
178 no-op, and no events are fired.
179 */
180 switchToTab: function(tab){
181 tab = tabArg(tab,this);
182 const self = this;
183 if(tab===this._currentTab) return this;
184 else if(this._currentTab){
185 this._dispatchEvent('before-switch-from', this._currentTab);
186 }
187 delete this._currentTab;
188 this.e.tabs.childNodes.forEach((e,ndx)=>{
189 const btn = this.e.tabBar.childNodes[ndx];
190 if(e===tab){
191 if(D.hasClass(e,'selected')){
192 return;
193 }
194 self._dispatchEvent('before-switch-to',tab);
195 setVisible(e, true);
196 this._currentTab = e;
197 D.addClass(btn,'selected');
198 self._dispatchEvent('after-switch-to',tab);
199 }else{
200 if(D.hasClass(e,'selected')){
201 return;
202

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button