From 8cdda2e721e9635abb038f3d560c41b83ad19674 Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Thu, 27 Oct 2022 13:00:50 +0530 Subject: [PATCH 1/2] fix(router-js): handle case when link is not of same host --- frappe/public/js/frappe/router.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/frappe/public/js/frappe/router.js b/frappe/public/js/frappe/router.js index 315adab7d0..1149f4a297 100644 --- a/frappe/public/js/frappe/router.js +++ b/frappe/public/js/frappe/router.js @@ -38,16 +38,17 @@ $("body").on("click", "a", function (e) { return false; }; - const href = e.currentTarget.getAttribute("href"); + const targetElement = e.currentTarget; + const href = targetElement.getAttribute("href"); + const isOfSameHost = targetElement.hostname === window.location.hostname; // click handled, but not by href if ( - e.currentTarget.getAttribute("onclick") || // has a handler + targetElement.getAttribute("onclick") || // has a handler e.ctrlKey || e.metaKey || // open in a new tab - href === "#" + href === "#" // hash is home ) { - // hash is home return; } @@ -57,20 +58,20 @@ $("body").on("click", "a", function (e) { if (href && href.startsWith("#")) { // target startswith "#", this is a v1 style route, so remake it. - return override(e.currentTarget.hash); + return override(targetElement.hash); } - if (frappe.router.is_app_route(e.currentTarget.pathname)) { + if (isOfSameHost && frappe.router.is_app_route(targetElement.pathname)) { // target has "/app, this is a v2 style route. - if (e.currentTarget.search) { + if (targetElement.search) { frappe.route_options = {}; - let params = new URLSearchParams(e.currentTarget.search); + let params = new URLSearchParams(targetElement.search); for (const [key, value] of params) { frappe.route_options[key] = value; } } - return override(e.currentTarget.pathname + e.currentTarget.hash); + return override(targetElement.pathname + targetElement.hash); } }); From ccbd6ffab371d01dbb1ef09b2634b801a2b322bd Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Thu, 27 Oct 2022 16:30:28 +0530 Subject: [PATCH 2/2] fix(formatting): use snake case for variable names --- frappe/public/js/frappe/router.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/frappe/public/js/frappe/router.js b/frappe/public/js/frappe/router.js index 1149f4a297..2005a46cfe 100644 --- a/frappe/public/js/frappe/router.js +++ b/frappe/public/js/frappe/router.js @@ -38,13 +38,13 @@ $("body").on("click", "a", function (e) { return false; }; - const targetElement = e.currentTarget; - const href = targetElement.getAttribute("href"); - const isOfSameHost = targetElement.hostname === window.location.hostname; + const target_element = e.currentTarget; + const href = target_element.getAttribute("href"); + const is_on_same_host = target_element.hostname === window.location.hostname; // click handled, but not by href if ( - targetElement.getAttribute("onclick") || // has a handler + target_element.getAttribute("onclick") || // has a handler e.ctrlKey || e.metaKey || // open in a new tab href === "#" // hash is home @@ -58,20 +58,20 @@ $("body").on("click", "a", function (e) { if (href && href.startsWith("#")) { // target startswith "#", this is a v1 style route, so remake it. - return override(targetElement.hash); + return override(target_element.hash); } - if (isOfSameHost && frappe.router.is_app_route(targetElement.pathname)) { + if (is_on_same_host && frappe.router.is_app_route(target_element.pathname)) { // target has "/app, this is a v2 style route. - if (targetElement.search) { + if (target_element.search) { frappe.route_options = {}; - let params = new URLSearchParams(targetElement.search); + let params = new URLSearchParams(target_element.search); for (const [key, value] of params) { frappe.route_options[key] = value; } } - return override(targetElement.pathname + targetElement.hash); + return override(target_element.pathname + target_element.hash); } });