Tweaked how TabbedPage's work.

master
Pacman Ghost 3 years ago
parent d756179abf
commit 504fdd8138
  1. 28
      asl_rulebook2/webapp/static/TabbedPages.js

@ -24,19 +24,16 @@ gMainApp.component( "tabbed-pages", {
</div>`, </div>`,
created() { created() {
// FUDGE! It's nice to have the parent manage the TabbedPage's, and we just show the content gEventBus.on( "activate-tab", (sel, tabId) => {
// as a slot, but that makes it tricky for us to create the tab strip, since we don't know anything // check if this event is for us
// about the tabs themselves. We work around this by having each TabbedPage emit an event when if ( sel.substring( 0, 1 ) == "#" )
// they mount, but since we ourself mount only after all our children have mounted, it's tricky sel = sel.substring( 1 ) ;
// for us to catch these events ($on() was remove in Vue 3 :-/). So, we emit the event on the else
// global event bus, and check if they're for one of our TabbedPage's when we receive them. console.log( "INTERNAL ERROR: Tabs should be activated via a selector ID." ) ;
gEventBus.on( "tab-loaded", (tabbedPage) => { if ( this.$el.getAttribute( "id" ) != sel )
if ( ! tabbedPage.$el.parentNode.isSameNode( this.$el ) )
return ; return ;
// one of our TabbedPage's has just mounted - show it in our tab strip // yup - activate the specified tab
this.tabs.push( { this.activateTab( tabId ) ;
tabId: tabbedPage.tabId, caption: tabbedPage.caption
} ) ;
} ) ; } ) ;
}, },
@ -76,8 +73,11 @@ gMainApp.component( "tabbed-page", {
<div class="wrapper"> <slot /> </div> <div class="wrapper"> <slot /> </div>
</div>`, </div>`,
mounted() { created() {
gEventBus.emit( "tab-loaded", this ) ; // add ourself to the parent's list of child tabs
this.$parent.tabs.push( {
tabId: this.tabId, caption: this.caption
} ) ;
}, },
} ) ; } ) ;

Loading…
Cancel
Save