Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add a convenience dom/replace function #8

Closed
wants to merge 3 commits into from

1 participant

@pyr

This makes handling "pages" much easier, by doing:

(pe/on some-link :click
       (fn [me e]
         (dom/replace (dom/query "section#some-section") (some-partial))))
Pierre-Yves ... added some commits
Pierre-Yves Ritschard Add a convenience replace function 185c1f0
Pierre-Yves Ritschard Add a toggle class function 798f1d0
Pierre-Yves Ritschard typo cb590d1
@pyr pyr closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 27, 2011
  1. Add a convenience replace function

    Pierre-Yves Ritschard authored
  2. Add a toggle class function

    Pierre-Yves Ritschard authored
Commits on Sep 28, 2011
  1. typo

    Pierre-Yves Ritschard authored
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/pinot/dom.cljs
View
13 src/pinot/dom.cljs
@@ -4,8 +4,10 @@
[goog.style :as gstyle]
[goog.dom.query :as query]
[goog.dom.forms :as forms]
+ [goog.dom.classes :as classes]
[pinot.util.clj :as pclj]
- [pinot.util.js :as pjs]))
+ [pinot.util.js :as pjs])
+ (:refer-clojure :exclude [replace]))
;; ********************************************
;; Pinot specific
@@ -29,6 +31,9 @@
(gstyle/setStyle el (name k) (name v))))
elem)
+(defn toggle-class [elem class]
+ (classes/toggle elem class))
+
(defn attr
([elem attrs]
(if-not (map? attrs)
@@ -85,6 +90,12 @@
(doseq [elem (pclj/->coll elem)]
(dom/removeNode elem)))
+(defn replace [elem html]
+ (let [p (parent (if (coll? elem) (first elem) elem))]
+ (unappend elem)
+ (append p html)))
+
+
(defn nodelist->coll [nl]
;; The results are a nodelist, which looks like an array, but
;; isn't one. We have to turn it into a collection that we can
Something went wrong with that request. Please try again.