Permalink
Browse files

convert htmlcollections to clojure vectors

  • Loading branch information...
1 parent 1c59fc4 commit 81cda22038920726e701bef977e1adb9aaf70628 Adeel Ahmad Khan committed Mar 6, 2012
Showing with 8 additions and 3 deletions.
  1. +8 −3 src/froelich/core.cljs
View
@@ -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))

0 comments on commit 81cda22

Please sign in to comment.