From a04c110698b50aaa22386250d8630f27e3315848 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Thu, 8 Sep 2022 16:10:30 +0200 Subject: [PATCH] maint(pat navigationmarker): Modernize code. --- src/pat/navigationmarker/navigationmarker.js | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/pat/navigationmarker/navigationmarker.js b/src/pat/navigationmarker/navigationmarker.js index effd3be06..d9d5c32d1 100644 --- a/src/pat/navigationmarker/navigationmarker.js +++ b/src/pat/navigationmarker/navigationmarker.js @@ -5,29 +5,31 @@ export default Base.extend({ name: "navigationmarker", trigger: ".pat-navigationmarker", parser: "mockup", - init: function () { + init() { const portal_url = document.body.dataset.portalUrl; - var href = + const href = document.querySelector('head link[rel="canonical"]').href || window.location.href; + const hrefParts = href.split("/"); - $("a", this.$el).each(function () { - var navlink = this.href.replace("/view", ""); + const nav_items = this.el.querySelectorAll("a"); + + for (const nav_item of nav_items) { + const navlink = nav_item.getAttribute("href", "").replace("/view", ""); if (href.indexOf(navlink) !== -1) { - var parent = $(this).parent(); + const parent = $(nav_item).parent(); // check the input-openers within the path - var check = parent.find("> input"); + const check = parent.find("> input"); if (check.length) { check[0].checked = true; } // set "inPath" to all nav items which are within the current path // check if parts of navlink are in canonical url parts - var hrefParts = href.split("/"); - var navParts = navlink.split("/"); - var inPath = false; - for (var i = 0, size = navParts.length; i < size; i++) { + const navParts = navlink.split("/"); + let inPath = false; + for (let i = 0, size = navParts.length; i < size; i++) { // The last path-part must match. inPath = false; if (navParts[i] === hrefParts[i]) { @@ -47,6 +49,6 @@ export default Base.extend({ parent.addClass("current"); } } - }); + } }, });