mirror of
https://github.com/metosin/reitit.git
synced 2025-12-22 18:41:10 +00:00
Simplify contentEditable check for frontend routing
This commit is contained in:
parent
f5eb1d17f5
commit
6123230f98
2 changed files with 12 additions and 5 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue