Simplify contentEditable check for frontend routing

This commit is contained in:
Juho Teperi 2019-02-08 13:57:03 +02:00
parent f5eb1d17f5
commit 6123230f98
2 changed files with 12 additions and 5 deletions

View file

@ -27,7 +27,13 @@
[:ul
[:li [:a {:href "http://google.com"} "external link"]]
[:li [:a {:href (rfe/href ::foobar)} "Missing route"]]
[:li [:a {:href (rfe/href ::item)} "Missing route params"]]]])
[:li [:a {:href (rfe/href ::item)} "Missing route params"]]]
[:div
{:content-editable true
:suppressContentEditableWarning true}
[:p "Link inside contentEditable element is ignored."]
[:a {:href (rfe/href ::frontpage)} "Link"]]])
(defn item-page [match]
(let [{:keys [path query]} (:parameters match)

View file

@ -4,8 +4,7 @@
(:require [reitit.core :as reitit]
[reitit.core :as r]
[reitit.frontend :as rf]
[goog.events :as gevents]
[goog.dom :as gdom])
[goog.events :as gevents])
(:import goog.Uri))
(defprotocol History
@ -78,8 +77,10 @@
(not (contains? #{"_blank" "self"} (.getAttribute el "target")))
;; Left button
(= 0 (.-button e))
(reitit/match-by-path router (.getPath uri))
(not (gdom/getAncestor el (fn [node] (.isContentEditable node)))))
;; isContentEditable property is inherited from parents,
;; so if the anchor is inside contenteditable div, the property will be true.
(not (.-isContentEditable (.-target e)))
(reitit/match-by-path router (.getPath uri)))
(.preventDefault e)
(let [path (str (.getPath uri)
(if (seq (.getQuery uri))