From 3e8386ad8e2b1ed830dfe85b309f4b7370098155 Mon Sep 17 00:00:00 2001 From: Taka Date: Thu, 20 May 2021 21:13:50 +1000 Subject: [PATCH] Changed how we open a content doc at a specific target/page. --- asl_rulebook2/webapp/static/ContentPane.js | 41 ++++++++-------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/asl_rulebook2/webapp/static/ContentPane.js b/asl_rulebook2/webapp/static/ContentPane.js index 9b23457..7063944 100644 --- a/asl_rulebook2/webapp/static/ContentPane.js +++ b/asl_rulebook2/webapp/static/ContentPane.js @@ -13,8 +13,8 @@ gMainApp.component( "content-pane", { template: `
- - + + @@ -36,38 +36,25 @@ gMainApp.component( "content-pane", { }, mounted() { - const showContentDoc = (cdocId) => { + const showContentDoc = (cdocId, initRuleid, initPageNo) => { // check if the content doc has already been loaded - let cdoc = this.loadedContentDocs[ cdocId ] ; - if ( cdoc == undefined ) { + if ( this.loadedContentDocs[ cdocId ] == undefined ) { // nope - load it - this.loadedContentDocs[ cdocId ] = this.contentDocs[ cdocId ] ; + this.loadedContentDocs[ cdocId ] = { + cdoc: this.contentDocs[ cdocId ], + initRuleid: initRuleid, + initPageNo: initPageNo, + } ; } this.$nextTick( () => { this.$refs.tabbedPages.activateTab( cdocId ) ; // nb: tabId == cdocId } ) ; - return (cdoc == undefined) ; } gEventBus.on( "show-target", (cdocId, ruleid) => { //eslint-disable-line no-unused-vars - let wasLoaded = showContentDoc( cdocId ) ; - if ( wasLoaded ) { - // FUDGE! If we just loaded a new content doc, it won't have been around to receive - // the "show-target" event, so we re-issue it here. This might cause some minor - // problems (e.g. footnotes showing twice), but we seem to be OK. - this.$nextTick( () => { - gEventBus.emit( "show-target", cdocId, ruleid ) ; - } ) ; - } + showContentDoc( cdocId, ruleid, null ) ; } ) ; gEventBus.on( "show-page", (cdocId, pageNo) => { //eslint-disable-line no-unused-vars - let wasLoaded = showContentDoc( cdocId ) ; - if ( wasLoaded ) { - // FUDGE! If we just loaded a new content doc, it won't have been around to receive - // the "show-page" event, so we re-issue it here. - this.$nextTick( () => { - gEventBus.emit( "show-page", cdocId, pageNo ) ; - } ) ; - } + showContentDoc( cdocId, null, pageNo ) ; } ) ; }, @@ -75,7 +62,7 @@ gMainApp.component( "content-pane", { // make sure the test empty document is loaded let cdoc = this.contentDocs[ "empty" ] ; if ( cdoc != undefined ) - this.loadedContentDocs[ "empty" ] = cdoc ; + this.loadedContentDocs[ "empty" ] = { cdoc: cdoc } ; }, methods: { @@ -171,9 +158,9 @@ gMainApp.component( "content-pane", { gMainApp.component( "content-doc", { - props: [ "cdoc" ], + props: [ "cdoc", "initRuleid", "initPageNo" ], data() { return { - ruleid: null, pageNo: null, + ruleid: this.initRuleid, pageNo: this.initPageNo, noContent: gUrlParams.get( "no-content" ), } ; },