Skip to content

Commit 3331f8e

Browse files
committed
#2821 reworked anchors on glossary page to scroll appropriately
1 parent 94230e9 commit 3331f8e

File tree

2 files changed

+86
-71
lines changed

2 files changed

+86
-71
lines changed

src/components/SearchTable.vue

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
11
<template>
22
<div ref="tableRef" class="table-container">
3-
<table aria-live="polite" class="table cve-border-dark-blue is-striped is-hoverable" >
3+
<table aria-live="polite" class="table cve-border-dark-blue is-striped is-hoverable">
44
<thead>
55
<tr>
6-
<th v-for="(header, index) in tableHeaders" :key="index">{{header}}</th>
6+
<th v-for="(header, index) in tableHeaders" :key="index">{{ header }}</th>
77
</tr>
88
</thead>
99
<tbody>
10-
<tr v-for="(entry, index) in tableData" :key="index"
10+
<tr
11+
v-for="(entry, index) in tableData"
12+
:key="index"
1113
:id="entry.id"
1214
:ref="entry.id"
1315
v-on:click="selectRow(entry.id)"
14-
15-
v-bind:class="{'cve-term-active': selectedRow === entry.id}">
16+
v-bind:class="{ 'cve-term-active': selectedRow === entry.id }"
17+
>
1618
<td class="table-column-width">
17-
<a :href="entry.termLink" v-bind:class="{'selectTermLink': selectedRow === entry.id}" class="has-text-weight-bold termLink"> {{ entry.term }} </a>
19+
<router-link
20+
:to="'#' + entry.id"
21+
v-bind:class="{ selectTermLink: selectedRow === entry.id }"
22+
class="has-text-weight-bold termLink"
23+
>
24+
{{ entry.term }}
25+
</router-link>
1826
</td>
19-
<td v-if="renderAsHTML" class="cve-term-definition" v-html="entry.definition"> </td>
20-
<td v-else class="cve-term-definition">{{ entry.definition }} </td>
27+
<td
28+
v-if="renderAsHTML"
29+
class="cve-term-definition"
30+
v-html="entry.definition"
31+
></td>
32+
<td v-else class="cve-term-definition">{{ entry.definition }}</td>
2133
</tr>
2234
</tbody>
2335
</table>
2436
</div>
25-
</template>
26-
27-
<script>
37+
</template>
2838

29-
export default {
30-
name: "SearchTable",
31-
props: {
32-
tableData: {
33-
type: Array,
34-
required: true,
35-
},
36-
tableHeaders: {
37-
type: Array,
38-
required: true,
39-
},
40-
renderAsHTML: {
41-
type: Boolean,
42-
default: false,
43-
required: false,
44-
}
39+
<script>
40+
export default {
41+
name: "SearchTable",
42+
props: {
43+
tableData: {
44+
type: Array,
45+
required: true,
4546
},
46-
data() {
47-
return {
48-
selectedRow: null
49-
};
47+
tableHeaders: {
48+
type: Array,
49+
required: true,
5050
},
51-
mounted() {
52-
let term = null;
53-
54-
// Add active term as a hash to scroll to it then select it
55-
if (this.$route.query.activeTerm) {
56-
term = this.$route.query.activeTerm;
57-
this.$router.push({hash: "#" + term })
58-
this.selectRow(term)
59-
}
60-
// If route already has a hash, just select the term
61-
else if (this.$route.hash) {
62-
term = this.$route.hash.slice(1);
63-
this.selectRow(term)
64-
}
51+
renderAsHTML: {
52+
type: Boolean,
53+
default: false,
54+
required: false,
6555
},
66-
methods: {
67-
selectRow(rowId) {
68-
69-
this.selectedRow = (rowId === this.selectedRow ? null : rowId)
70-
}
56+
},
57+
data() {
58+
return {
59+
selectedRow: null,
60+
};
61+
},
62+
mounted() {
63+
let term = null;
64+
65+
if (this.$route.hash) {
66+
term = this.$route.hash.slice(1);
67+
this.selectRow(term);
68+
}
69+
},
70+
methods: {
71+
selectRow(rowId) {
72+
this.selectedRow = rowId;
7173
},
72-
};
73-
</script>
74-
75-
<!-- Add "scoped" attribute to limit CSS to this component only -->
76-
<style scoped lang="scss">
77-
78-
@import '@/assets/style/routerLink.scss';
74+
},
75+
};
76+
</script>
7977

78+
<!-- Add "scoped" attribute to limit CSS to this component only -->
79+
<style scoped lang="scss">
8080
@media only screen and (min-width: $desktop) {
8181
.table-column-width {
8282
width: 30% !important;
@@ -85,18 +85,19 @@
8585
8686
.cve-term-active {
8787
background-color: $theme-color-accent-cool-light !important;
88-
color: black ;
89-
padding-left: 8px;
88+
color: black;
89+
padding-left: 8px;
9090
padding-top: 5px;
9191
padding-bottom: 5px;
9292
}
93-
93+
9494
.termLink {
9595
color: $theme-color-primary;
96+
background: unset;
97+
// scroll-margin: 50px;
9698
}
9799
98100
.selectTermLink {
99101
color: black;
100102
}
101103
</style>
102-

src/router/index.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,24 @@ import NotFound from '@/views/NotFound.vue';
4545

4646
const router = createRouter({
4747
history: createWebHistory(import.meta.env.BASE_URL),
48-
scrollBehavior(to) {
49-
if (to.hash) {
50-
return {
51-
el: to.hash,
52-
top: 55
53-
};
54-
}
55-
return {
56-
top: 0
57-
};
48+
scrollBehavior(to) {
49+
return new Promise((resolve) => {
50+
setTimeout(() => {
51+
if (to.hash) {
52+
resolve({
53+
el: to.hash,
54+
top: 55,
55+
behavior: "instant"
56+
});
57+
}
58+
resolve({
59+
top: 0
60+
});
61+
}, 0)
62+
63+
})
64+
65+
5866
},
5967
routes: [
6068
{
@@ -213,6 +221,12 @@ const router = createRouter({
213221
meta: {
214222
title: 'Glossary | CVE',
215223
},
224+
beforeEnter: (to) => {
225+
if (!to.hash) {
226+
const term = to.query.activeTerm;
227+
to.hash = '#' + term
228+
}
229+
},
216230
},
217231
{
218232
path: '/ResourcesSupport/FAQs',

0 commit comments

Comments
 (0)