Created
September 4, 2021 20:25
-
-
Save DeLaGuardo/65d4e58876c17adfeaa90b021da54719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns omnitech.shims) | |
(defn- closest [selector] | |
(this-as node | |
(let [node-list (.querySelectorAll js/document selector) | |
all (mapv #(aget node-list %) (range 0 (.-length node-list)))] | |
(loop [node node] | |
(let [parent (.-parentNode node)] | |
(if (some #(= parent %) all) | |
parent | |
(if parent | |
(recur parent) | |
false))))))) | |
(defn- trim [] | |
(this-as s | |
(-> s | |
(.replace (js/RegExp. "^\\s+") "") | |
(.replace (js/RegExp. "\\s+$") "")))) | |
(defn inject-shims [] | |
(do | |
(let [proto (.. js/window -HTMLElement -prototype)] | |
(when-not (.-closest proto) | |
(set! (.-closest proto) closest))) | |
(when-not (.. js/String -prototype -trim) | |
(set! (.. js/String -prototype -trim) trim)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment