diff --git a/.gitignore b/.gitignore index 1dbeeb3..4aea86f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ pom.xml *.*~ \#*# .#* -.DS_store \ No newline at end of file +.DS_store +*.iml \ No newline at end of file diff --git a/project.clj b/project.clj index 7a011d5..d23fe9a 100644 --- a/project.clj +++ b/project.clj @@ -1,36 +1,31 @@ (defproject domina "1.0.4-SNAPSHOT" :description "A DOM manipulation library for ClojureScript inspired by JQuery" - :source-paths ["src/cljs"] - :dependencies [[org.clojure/clojure "1.4.0"]] - :plugins [[lein-cljsbuild "0.3.0"] - [lein-clojars "0.9.1"]] + :dependencies [[org.clojure/clojure "1.11.1"] + [org.clojure/clojurescript "1.11.54"]] + :plugins [[lein-cljsbuild "1.1.8"]] :hooks [leiningen.cljsbuild] - :cljsbuild {:builds [{:jar true - :compiler {:libs ["goog/dom/query.js"] - :pretty-print true + :cljsbuild {:builds [{:source-paths ["src/cljs"] + :jar true + :compiler {:pretty-print true :output-dir ".cljsbuild/domina" :output-to "public/domina.js"}} {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :pretty-print true + :compiler {:pretty-print true :optimizations :none :output-dir "public/build_no_opt" :output-to "public/test_no_opt.js"}} {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :optimizations :whitespace + :compiler {:optimizations :whitespace :pretty-print true :output-dir ".cljsbuild/whitespace" :output-to "public/test_whitespace.js"}} {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :optimizations :simple + :compiler {:optimizations :simple :pretty-print true :output-dir ".cljsbuild/simple" :output-to "public/test_simple.js"}} {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :optimizations :advanced + :compiler {:optimizations :advanced :pretty-print true :output-dir ".cljsbuild/advanced" :output-to "public/test_advanced.js"}}]} diff --git a/src/cljs/domina.cljs b/src/cljs/domina.cljs index e7a8efa..c23d647 100644 --- a/src/cljs/domina.cljs +++ b/src/cljs/domina.cljs @@ -97,18 +97,13 @@ ;;;;;;;;;;;;;;;;;;; Protocols ;;;;;;;;;;;;;;;;; -;; These are to silence a bug where the compiler emits a warning when -;; it hits the defprotocol for DomContent. -(declare nodes) -(declare single-node) - (defprotocol DomContent (nodes [content] "Returns the content as a sequence of nodes.") (single-node [nodeseq] "Returns the content as a single node (the first node, if the content contains more than one")) ;;;;;;;;;;;;;;;;;;; Public API ;;;;;;;;;;;;;;;;; -(def *debug* true) +(def ^:dynamic *debug* true) (defn log-debug [& mesg] (when (and *debug* (not (= (.-console js/window) js/undefined))) (.log js/console (apply str mesg)))) @@ -191,12 +186,12 @@ (defn detach! "Removes all the nodes in a content from the DOM and returns them." [content] - (doall (map dom/removeNode (nodes content)))) + (doall (map dom/removeNode (vec (nodes content))))) (defn destroy! "Removes all the nodes in a content from the DOM. Returns nil." [content] - (dorun (map dom/removeNode (nodes content)))) + (dorun (map dom/removeNode (vec (nodes content))))) (defn destroy-children! "Removes all the child nodes in a content from the DOM. Returns the original content." diff --git a/src/cljs/domina/css.cljs b/src/cljs/domina/css.cljs index 6c723f1..ac847e4 100644 --- a/src/cljs/domina/css.cljs +++ b/src/cljs/domina/css.cljs @@ -1,7 +1,6 @@ (ns domina.css (:require [domina :as domina] - [goog.dom :as dom] - [goog.dom.query :as query])) + [goog.dom :as dom])) (defn- root-element [] @@ -12,9 +11,9 @@ "Returns content based on a css selector expression. Takes an optional content as a base; if none is given, uses the HTML element as a base." ([expr] (sel (root-element) expr)) ([base expr] (reify domina/DomContent - (nodes [_] (mapcat #(domina/normalize-seq (dom/query expr %)) + (nodes [_] (mapcat #(domina/normalize-seq (.querySelectorAll % expr)) (domina/nodes base))) (single-node [_] (first (filter (complement nil?) - (mapcat #(domina/normalize-seq (dom/query expr %)) - (domina/nodes base)))))))) \ No newline at end of file + (mapcat #(domina/normalize-seq (.querySelector % expr)) + (domina/nodes base)))))))) diff --git a/src/cljs/domina/events.cljs b/src/cljs/domina/events.cljs index 1db48f3..c65090d 100644 --- a/src/cljs/domina/events.cljs +++ b/src/cljs/domina/events.cljs @@ -129,7 +129,7 @@ "Dispatches an event of the given type, adding the values in event map to the event object. Optionally takes an event source. If none is provided, dispatches on the document's root element. Returns false if any handlers called prevent-default, otherwise true." ([type evt-map] (dispatch! root-element type evt-map)) ([source type evt-map] - (let [evt (events/Event. (name type))] + (let [evt (goog.events.Event. (name type))] (doseq [[k v] evt-map] (aset evt k v)) (if (is-event-target? source) (dispatch-event-target! source evt) diff --git a/test/cljs/domina/test.cljs b/test/cljs/domina/test.cljs index 0ebe5e1..fd0b136 100644 --- a/test/cljs/domina/test.cljs +++ b/test/cljs/domina/test.cljs @@ -12,7 +12,7 @@ [domina.xpath :only [xpath]] [domina.css :only [sel]] [domina.events :only [listen! capture! listen-once! capture-once! - unlisten! dispatch-event! dispatch! unlisten-by-key! + unlisten! dispatch! unlisten-by-key! get-listeners prevent-default stop-propagation target current-target event-type raw-event]]) (:require [goog.events :as events]