Skip to content

Commit 285ba54

Browse files
committed
Add dynamic anchors
1 parent ce70b3f commit 285ba54

5 files changed

Lines changed: 42 additions & 3 deletions

File tree

apps/about/templates/about/allies.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ <h1>Aliados</h1>
1515
</p>
1616

1717
{% for ally in allies %}
18-
<div class="ally-block">
19-
<h2><img src="{{ ally.logo.url }}"> {{ ally.name }}</h2>
18+
<div class="ally-block" id="{{ ally.name|slugify }}">
19+
<h2 class="dyn-anchor-heading">
20+
<img src="{{ ally.logo.url }}"> {{ ally.name }}
21+
<a class="dyn-anchor-link" href="#{{ ally.name|slugify }}"><i class="fas fa-link"></i></a>
22+
</h2>
2023
<p class="description"><i class="fas fa-quote-left quote"></i> {{ ally.description }} <i class="fas fa-quote-right quote"></i></p>
2124
<ul>
2225
{% if ally.url %}

apps/commons/static/commons/css/base.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import './variables';
22
@import '~bulma/bulma.sass';
33
@import './override';
4+
@import './dyn-anchors';
45

56
html {
67
// source: https://stackoverflow.com/q/46463338
@@ -122,4 +123,4 @@ body {
122123
border-radius: 22.5px;
123124
border-color: $header-bg;
124125
background-color: whitesmoke;
125-
}
126+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.dyn-anchor-heading {
2+
a.dyn-anchor-link {
3+
font-size: 14pt;
4+
color: skyblue;
5+
margin-bottom: 5px;
6+
vertical-align: middle;
7+
opacity: 0;
8+
&:hover {
9+
color: darken(skyblue, 40%);
10+
}
11+
&.show-it {
12+
opacity: 1;
13+
}
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function init() {
2+
document.querySelectorAll('.dyn-anchor-heading').forEach((item) => {
3+
item.addEventListener('mouseenter', function(event) {
4+
event.preventDefault()
5+
let anchor = event.target.querySelector('.dyn-anchor-link')
6+
anchor.classList.add('show-it')
7+
})
8+
item.addEventListener('mouseleave', function(event) {
9+
event.preventDefault()
10+
let anchor = event.target.querySelector('.dyn-anchor-link')
11+
anchor.classList.remove('show-it')
12+
})
13+
})
14+
}
15+
16+
export default {
17+
init
18+
}

apps/commons/static/commons/js/general/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import NavbarBurger from './navbar-burger'
22
import Notifications from './notifications'
33
import Collapsable from './collapsable'
44
import ScrollUpButton from './scrollUpButton'
5+
import DynAnchors from './dyn-anchors'
56

67
export default {
78
init: () => {
89
NavbarBurger.init()
910
Notifications.init()
1011
Collapsable.init()
1112
ScrollUpButton.init()
13+
DynAnchors.init()
1214
},
1315
}

0 commit comments

Comments
 (0)