Fossil SCM
Added the tab manager before-switch-from event.
Commit
2863abf5c52c22deb639bf029828a310197e51550b9acd20817bd32abd7abea3
Parent
bbb738d07dfbecb…
1 file changed
+13
-1
+13
-1
| --- src/fossil.tabs.js | ||
| +++ src/fossil.tabs.js | ||
| @@ -147,10 +147,14 @@ | ||
| 147 | 147 | /** |
| 148 | 148 | Registers an event listener for this object's custom events. |
| 149 | 149 | The callback gets a CustomEvent object with a 'detail' |
| 150 | 150 | propertly holding any tab-related state for the event. The events |
| 151 | 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. | |
| 152 | 156 | |
| 153 | 157 | - 'before-switch-to' is emitted immediately before a new tab is |
| 154 | 158 | switched to. detail = the tab element. |
| 155 | 159 | |
| 156 | 160 | - 'after-switch-to' is emitted immediately after a new tab is |
| @@ -167,23 +171,31 @@ | ||
| 167 | 171 | }, |
| 168 | 172 | |
| 169 | 173 | /** |
| 170 | 174 | If the given DOM element, unique selector, or integer (0-based |
| 171 | 175 | 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. | |
| 173 | 179 | */ |
| 174 | 180 | switchToTab: function(tab){ |
| 175 | 181 | tab = tabArg(tab,this); |
| 176 | 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; | |
| 177 | 188 | this.e.tabs.childNodes.forEach((e,ndx)=>{ |
| 178 | 189 | const btn = this.e.tabBar.childNodes[ndx]; |
| 179 | 190 | if(e===tab){ |
| 180 | 191 | if(D.hasClass(e,'selected')){ |
| 181 | 192 | return; |
| 182 | 193 | } |
| 183 | 194 | self._dispatchEvent('before-switch-to',tab); |
| 184 | 195 | setVisible(e, true); |
| 196 | + this._currentTab = e; | |
| 185 | 197 | D.addClass(btn,'selected'); |
| 186 | 198 | self._dispatchEvent('after-switch-to',tab); |
| 187 | 199 | }else{ |
| 188 | 200 | if(D.hasClass(e,'selected')){ |
| 189 | 201 | return; |
| 190 | 202 |
| --- 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 |