Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libs #85

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ pom.xml
*.*~
\#*#
.#*
.DS_store
.DS_store
*.iml
25 changes: 10 additions & 15 deletions project.clj
Original file line number Diff line number Diff line change
@@ -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"}}]}
Expand Down
11 changes: 3 additions & 8 deletions src/cljs/domina.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down Expand Up @@ -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."
Expand Down
9 changes: 4 additions & 5 deletions src/cljs/domina/css.cljs
Original file line number Diff line number Diff line change
@@ -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
[]
Expand All @@ -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))))))))
(mapcat #(domina/normalize-seq (.querySelector % expr))
(domina/nodes base))))))))
2 changes: 1 addition & 1 deletion src/cljs/domina/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/cljs/domina/test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down