Skip to content

Commit 6fcca1a

Browse files
namedgraphclaude
andcommitted
Keep tab href in sync with address-bar mode across navigation
Threads the active mode into ldh:AddTabNavBarListItem so newly created tabs carry the current ?mode= in their @href, and updates the matching tab's @href on every RDFDocumentLoad so it stays in lockstep with the pushed history state. Tab click and close handlers now derive the navigation target from the anchor's @href (parsed query string) instead of the bare data-uri, so the preserved mode rides through to ldh:DocumentNavigate via the new query-params parameter. Server-side layout.xsl wraps the first tab's @href in ldh:href(..., ldh:build-query(ac:mode(root()))) so the initial render is already mode-aware. Drops the now-redundant ixsl:contains(., 'dataset.uri') guard from ldh:RenderTab since every tab li carries data-uri unconditionally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent cae32c5 commit 6fcca1a

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/layout.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ exclude-result-prefixes="#all">
757757
<div class="row-fluid">
758758
<ul class="nav nav-tabs span12" id="tab-bar-list">
759759
<li data-uri="{ac:absolute-path(ldh:base-uri(.))}">
760-
<a href="{ac:absolute-path(ldh:base-uri(.))}">
760+
<a href="{ldh:href(ac:absolute-path(ldh:base-uri(.)), ldh:build-query(ac:mode(root())))}">
761761
<xsl:apply-templates select="key('resources', ac:absolute-path(ldh:base-uri(.)))" mode="ac:label"/>
762762
</a>
763763
</li>

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/client.xsl

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ WHERE
505505
<xsl:call-template name="ldh:AddTabNavBarListItem">
506506
<xsl:with-param name="uri" select="$uri"/>
507507
<xsl:with-param name="label" select="$label"/>
508+
<xsl:with-param name="mode" select="$mode"/>
508509
</xsl:call-template>
509510

510511
<xsl:for-each select="id('tab-content', ixsl:page())/div[contains-token(@class, 'tab-pane')][./div[contains-token(@class, 'document-body')][starts-with(@about, lapp:origin(ldh:request-uri()) || '/')]]">
@@ -659,11 +660,12 @@ WHERE
659660
<xsl:template name="ldh:AddTabNavBarListItem">
660661
<xsl:param name="uri" as="xs:anyURI"/>
661662
<xsl:param name="label" as="xs:string"/>
663+
<xsl:param name="mode" as="xs:anyURI"/>
662664

663665
<!-- append the new tab <li> to the tab bar -->
664666
<xsl:result-document href="#tab-bar-list" method="ixsl:append-content">
665667
<li data-uri="{$uri}">
666-
<a href="{ldh:href($uri)}" title="{$uri}">
668+
<a href="{ldh:href($uri, ldh:build-query($mode))}" title="{$uri}">
667669
<xsl:value-of select="$label"/>
668670
</a>
669671
<span class="tab-close">&#xd7;</span>
@@ -703,7 +705,7 @@ WHERE
703705
<xsl:template name="ldh:RenderTab">
704706
<xsl:param name="tab-pane-id" as="xs:string"/>
705707
<xsl:param name="uri" as="xs:anyURI"/>
706-
<xsl:param name="tab-list-item" select="id('tab-bar-list', ixsl:page())/li[ixsl:contains(., 'dataset.uri')][ixsl:get(., 'dataset.uri') = $uri]" as="element()?"/>
708+
<xsl:param name="tab-list-item" select="id('tab-bar-list', ixsl:page())/li[ixsl:get(., 'dataset.uri') = $uri]" as="element()?"/>
707709
<xsl:param name="mode" as="xs:anyURI"/>
708710
<xsl:param name="response" as="map(*)"/>
709711
<xsl:param name="refresh-content" select="()" as="xs:boolean?"/>
@@ -822,6 +824,12 @@ WHERE
822824
<xsl:with-param name="title" select="()"/>
823825
<xsl:with-param name="container" select="$container"/>
824826
</xsl:call-template>
827+
828+
<!-- keep the matching tab's @href in lockstep with the address bar -->
829+
<!-- $uri may carry a query string (e.g. /employees/8/?mode=X) when handlers fall back to $uri = $href for local URLs; data-uri is bare, so strip query before comparing -->
830+
<xsl:for-each select="id('tab-bar-list', ixsl:page())/li[ixsl:get(., 'dataset.uri') = string(ac:absolute-path($uri))]/a">
831+
<ixsl:set-attribute name="href" select="string($href)" object="."/>
832+
</xsl:for-each>
825833
</xsl:if>
826834

827835
<xsl:call-template name="ldh:RDFDocumentLoad">
@@ -1094,12 +1102,15 @@ WHERE
10941102
<!-- tab bar: click on a tab link to activate it -->
10951103
<xsl:template match="ul[@id = 'tab-bar-list']/li[not(contains-token(@class, 'active'))]/a" mode="ixsl:onclick">
10961104
<xsl:sequence select="ixsl:call(ixsl:event(), 'preventDefault', [])"/>
1097-
<xsl:variable name="uri" select="xs:anyURI(ixsl:get(.., 'dataset.uri'))" as="xs:anyURI"/>
1105+
<xsl:variable name="href" select="xs:anyURI(resolve-uri(@href, ldh:base-uri(.)))" as="xs:anyURI"/>
1106+
<xsl:variable name="query-params" select="ldh:parse-query-params(substring-after($href, '?'))" as="map(xs:string, xs:string*)"/>
1107+
<xsl:variable name="uri" select="if (map:contains($query-params, 'uri')) then xs:anyURI(map:get($query-params, 'uri')) else $href" as="xs:anyURI"/>
10981108

10991109
<xsl:apply-templates select=".." mode="ldh:ActivateTab"/>
11001110

11011111
<xsl:call-template name="ldh:DocumentNavigate">
11021112
<xsl:with-param name="uri" select="$uri"/>
1113+
<xsl:with-param name="query-params" select="map:remove($query-params, 'uri')"/>
11031114
<xsl:with-param name="container" select=".."/>
11041115
</xsl:call-template>
11051116
</xsl:template>
@@ -1123,8 +1134,14 @@ WHERE
11231134
<!-- if the closed tab was active, activate the fallback and navigate to its URI -->
11241135
<xsl:if test="$was-active and $fallback-li">
11251136
<xsl:apply-templates select="$fallback-li" mode="ldh:ActivateTab"/>
1137+
1138+
<xsl:variable name="fallback-href" select="xs:anyURI(resolve-uri($fallback-li/a/@href, ldh:base-uri(.)))" as="xs:anyURI"/>
1139+
<xsl:variable name="fallback-query-params" select="ldh:parse-query-params(substring-after($fallback-href, '?'))" as="map(xs:string, xs:string*)"/>
1140+
<xsl:variable name="fallback-uri" select="if (map:contains($fallback-query-params, 'uri')) then xs:anyURI(map:get($fallback-query-params, 'uri')) else $fallback-href" as="xs:anyURI"/>
1141+
11261142
<xsl:call-template name="ldh:DocumentNavigate">
1127-
<xsl:with-param name="uri" select="xs:anyURI(ixsl:get($fallback-li, 'dataset.uri'))"/>
1143+
<xsl:with-param name="uri" select="$fallback-uri"/>
1144+
<xsl:with-param name="query-params" select="map:remove($fallback-query-params, 'uri')"/>
11281145
</xsl:call-template>
11291146
</xsl:if>
11301147

0 commit comments

Comments
 (0)