Skip to content

Commit

Permalink
[MIM-1711] Add anchor field to content-type, show in view if it exist…
Browse files Browse the repository at this point in the history
…s. (#2477)

* Add anchor field to content-type

* Anchor should apply to target url

* Add regexp limitation and clarify tool tip
  • Loading branch information
Glenruben authored Jan 26, 2024
1 parent 27a2267 commit d0a310a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
24 changes: 16 additions & 8 deletions src/main/resources/site/content-types/menuBox/menuBox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
<super-type>base:structured</super-type>
<form>
<item-set name="menu">
<occurrences minimum="0" maximum="99"/>
<occurrences minimum="0" maximum="99" />
<label>Kort</label>
<items>
<input type="TextLine" name="title">
<label>Tittel</label>
<occurrences minimum="0" maximum="1"/>
<occurrences minimum="0" maximum="1" />
</input>
<input type="TextLine" name="subtitle">
<label>Undertittel</label>
<occurrences minimum="0" maximum="1"/>
<occurrences minimum="0" maximum="1" />
</input>

<input name="image" type="imageSelector">
<occurrences minimum="0" maximum="1"/>
<occurrences minimum="0" maximum="1" />
<label>Bilde</label>
<config>
<allowPath>${site}</allowPath>
Expand All @@ -27,7 +27,7 @@
<option-set name="urlSrc">
<label>Lenkemål</label>
<expanded>true</expanded>
<occurrences minimum="1" maximum="1"/>
<occurrences minimum="1" maximum="1" />
<options minimum="1" maximum="1">
<option name="manual">
<label>Url</label>
Expand All @@ -36,7 +36,7 @@
<items>
<input name="url" type="TextLine">
<label>Kildelenke</label>
<occurrences minimum="1" maximum="1"/>
<occurrences minimum="1" maximum="1" />
</input>
</items>
</option>
Expand All @@ -46,8 +46,16 @@
<items>
<input name="contentId" type="ContentSelector">
<label>Relatert innhold</label>
<occurrences minimum="1" maximum="1"/>
<config/>
<occurrences minimum="1" maximum="1" />
<config />
</input>
<input name="anchor" type="TextLine">
<label>Anker som lenkekortet skal peke til. Ingen mellomrom, æøå eller spesialtegn.</label>
<help-text>OBS: Kun bokstaver a-z, tall og bindestrek/underscore er tillatt!</help-text>
<occurrences minimum="0" maximum="1" />
<config>
<regexp>[A-Za-z0-9_-]</regexp>
</config>
</input>
</items>
</option>
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/site/parts/menuBox/menuBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ function getHref(menuConfig: MenuConfig): string {
if (menuConfig.urlSrc && menuConfig.urlSrc._selected === 'manual') {
return menuConfig.urlSrc.manual.url
} else if (menuConfig.urlSrc && menuConfig.urlSrc.content) {
return pageUrl({
const url = pageUrl({
id: menuConfig.urlSrc.content.contentId,
})
if (menuConfig.urlSrc.content.anchor) {
return url + '#' + menuConfig.urlSrc.content.anchor
} else return url
}
return ''
}
Expand Down Expand Up @@ -133,6 +136,7 @@ interface hrefContent {
_selected: 'content'
content: {
contentId: string
anchor: string
}
}

Expand Down

0 comments on commit d0a310a

Please sign in to comment.