aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2025-02-09 22:04:25 +0100
committerOscar Najera <hi@oscarnajera.com>2025-02-09 22:04:25 +0100
commitd8711c197de79cb74e2de2c18bb23baeef3387fb (patch)
tree16aa92decda35c4692233758d06c289b0ea1a0a8
parent5b0e2eb19bb432e4e170d9bdb1cb8169d526801f (diff)
downloadscratch-d8711c197de79cb74e2de2c18bb23baeef3387fb.tar.gz
scratch-d8711c197de79cb74e2de2c18bb23baeef3387fb.tar.bz2
scratch-d8711c197de79cb74e2de2c18bb23baeef3387fb.zip
[FIX] current targe when link wraps other elements
Many times the A tag wraps many things. It happened that those contained element where the target and so the link would be undefined as they don't have href. The correct links resides on event.currentTarget.href. A second bug happens, on links to externals which I set to open in new window. Somehow, on the return of register-visit, the event has no currentTarget and so, it is the correct way to use event.target.target to figure out if I wanted to open a new window.
-rw-r--r--webstats/stats.paren9
1 files changed, 5 insertions, 4 deletions
diff --git a/webstats/stats.paren b/webstats/stats.paren
index 4721272..6491020 100644
--- a/webstats/stats.paren
+++ b/webstats/stats.paren
@@ -13,14 +13,15 @@
(when (or (= 1 (@ event which))
(= 2 (@ event which)))
(chain event (prevent-default))
- (let ((link (getprop event 'target 'href)))
+ (let ((link (getprop event 'current-target 'href)))
(chain
(register-visit (create :click link
:page (@ document location href)))
(finally (lambda ()
- (if (= 1 (@ event which))
- (setf (@ window location href) link)
- (chain window (open link "_blank")))))))))
+ (if (or (= 2 (@ event which))
+ (eql (@ event target target) "_blank"))
+ (chain window (open link "_blank"))
+ (setf (@ window location href) link))))))))
(defun instrument-links ()
(for-of (link ((@ document query-selector-all) "a"))