Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

convert htmlcollections to clojure vectors

  • Loading branch information...
commit 81cda22038920726e701bef977e1adb9aaf70628 1 parent 1c59fc4
Adeel Ahmad Khan authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 src/froelich/core.cljs
View
11 src/froelich/core.cljs
@@ -2,16 +2,21 @@
(:require [goog.dom :as gdom]
[goog.dom.classes :as gclasses]))
+
+(defn- collection-to-vec [coll]
+ (map (fn [i] (.item coll i)) (range 0 (.-length coll))))
+
;; selectors
(defn get-by-id [id]
(.getElementById js/document (name id)))
(defn get-by-class [klass container]
- (gdom/getElementsByClass (name klass) container))
+ (collection-to-vec (gdom/getElementsByClass (name klass) container)))
(defn get-by-tag-and-class [tag klass container]
- (gdom/getElementsByTagNameAndClass (name tag) (name klass) container))
+ (collection-to-vec
+ (gdom/getElementsByTagNameAndClass (name tag) (name klass) container)))
(comment
(dom/get-by-class :child (dom/get-by-id :container))
@@ -20,7 +25,7 @@
;; related
(defn get-children [el]
- (gdom/getChildren el))
+ (collection-to-vec (gdom/getChildren el)))
(defn get-next [el]
(gdom/getNextNode el))
Please sign in to comment.
Something went wrong with that request. Please try again.