Nulo
3a0c41b736
Squashed commit of the following: commit 482eea28821868f03ace33562e7bd34ab9a4478f Merge: 5f485281c128f2
Author: f <f@sutty.nl> Date: Thu Nov 25 18:31:35 2021 -0300 Merge branch 'master' into limpiar-eventos commit 5f48528c28b0709bd859a4dc52a830f60bfedc6e Author: f <f@sutty.nl> Date: Thu Nov 25 18:23:23 2021 -0300 pretty commit 70d05bc90a6cb64d1c4bfc39f48388af3fbc3c18 Merge: c4f33c0ff1bc21
Author: Nulo <nulo@sutty.nl> Date: Thu Oct 28 16:46:31 2021 -0300 Merge branch 'master' into limpiar-eventos commit c4f33c084058002a10fc0ec2137ffe045826cfd2 Author: f <f@sutty.nl> Date: Thu Oct 28 14:52:41 2021 -0300 limpiar eventos
39 lines
838 B
JavaScript
39 lines
838 B
JavaScript
import { Controller } from "stimulus";
|
|
|
|
export default class extends Controller {
|
|
static targets = ["item"];
|
|
|
|
connect() {
|
|
this.scroll_section_event = this._scroll_section_event.bind(this);
|
|
|
|
window.addEventListener("scroll:section", this.scroll_section_event);
|
|
}
|
|
|
|
disconnect() {
|
|
window.removeEventListener("scroll:section", this.scroll_section_event);
|
|
}
|
|
|
|
_scroll_section_event(event) {
|
|
this.update(event.detail.id);
|
|
}
|
|
|
|
get items() {
|
|
if (!this._items) {
|
|
this._items = {};
|
|
|
|
for (const item of this.itemTargets) {
|
|
this._items[item.href.split("#")[1]] = item;
|
|
}
|
|
}
|
|
|
|
return this._items;
|
|
}
|
|
|
|
update(id) {
|
|
for (const item of Object.values(this.items)) {
|
|
item.classList.remove("active");
|
|
}
|
|
|
|
if (this.items[id]) this.items[id].classList.add("active");
|
|
}
|
|
}
|