Skip to content

Commit

Permalink
changed api for events add-event is now listen and remove-event is no…
Browse files Browse the repository at this point in the history
…w remove-listener
  • Loading branch information
ckirkendall committed Jan 3, 2012
1 parent 3888c6a commit 6067509
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.textile
Expand Up @@ -100,8 +100,8 @@ New Transformations
<pre>
set-style (set-style :font-size "10px" :background "#fff")
remove-style (remove-style :font-size :background)
add-event (add-event :mouseover (fn [event] ...))
remove-event (remove-event :mouseover :mouseout)
listen (listen :mouseover (fn [event] ...))
remove-listener (remove-listener :mouseover :mouseout)
fade-in (fade-in time step-size)
or (fade-in time step-size callback)
fade-out (fade-out time step-size)
Expand Down
8 changes: 4 additions & 4 deletions project/cljs-macros/enfocus/macros.clj
Expand Up @@ -169,11 +169,11 @@
(defmacro remove-style [& forms]
`(enfocus.core/en-remove-style ~@forms))

(defmacro add-event [& forms]
`(enfocus.core/en-add-event ~@forms))
(defmacro listen [& forms]
`(enfocus.core/en-listen ~@forms))

(defmacro remove-event [& forms]
`(enfocus.core/en-remove-event ~@forms))
(defmacro remove-listener [& forms]
`(enfocus.core/en-remove-listener ~@forms))


(defmacro effect [step etype bad-etypes callback test-func & forms]
Expand Down
8 changes: 4 additions & 4 deletions project/cljs-src/enfocus/core.cljs
Expand Up @@ -457,19 +457,19 @@
@view-port-monitor)))


(defn en-add-event
(defn en-listen
"adding an event to the selected nodes"
[event func]
(cond
(= :mouseenter event) (en-add-event :mouseover (mouse-enter-leave func))
(= :mouseleave event) (en-add-event :mouseout (mouse-enter-leave func))
(= :mouseenter event) (en-listen :mouseover (mouse-enter-leave func))
(= :mouseleave event) (en-listen :mouseout (mouse-enter-leave func))
:else (chainable-standard
(fn [pnod]
(if (and (= :resize event) (identical? js/window pnod)) ;support window resize
(events/listen (get-vp-monitor) "resize" func)
(events/listen pnod (name event) func))))))

(defn en-remove-event
(defn en-remove-listener
"adding an event to the selected nodes"
[& event-list]
(chainable-standard
Expand Down
20 changes: 10 additions & 10 deletions project/cljs-src/enfocus/example.cljs
Expand Up @@ -84,10 +84,10 @@
(em/defaction test-grid []
["#test-content"] (em/content (test-cases))
["#test-content tbody tr:nth-of-type(even)"] (em/add-class "even")
["#test-content tbody tr"] (em/add-event
["#test-content tbody tr"] (em/listen
:mouseover
#((em/add-class "highlight") (.currentTarget %)))
["#test-content tbody tr"] (em/add-event
["#test-content tbody tr"] (em/listen
:mouseout
#((em/remove-class "highlight") (.currentTarget %)))
["#test-content2"] (em/content (template2 {"banana" 5 "pineapple" 10 "apple" 5}))
Expand All @@ -98,36 +98,36 @@
["#test-content4"] (em/set-style :background "#00dd00" :font-size "10px")
["#test-content5"] (em/set-style :background "#dd0000" :font-size "10px")
["#test-content5"] (em/remove-style :background :font-size)
["#test-content6"] (em/add-event
["#test-content6"] (em/listen
:mouseover
#((em/fade-out 500 20) (.currentTarget %)))
["#test-content6"] (em/add-event
["#test-content6"] (em/listen
:mouseout
#((em/fade-in 500 20) (.currentTarget %)))
["#test-content6_5"] (em/add-event
["#test-content6_5"] (em/listen
:mouseenter
#((em/fade-out 500 20) (.currentTarget %)))
["#test-content6_5"] (em/add-event
["#test-content6_5"] (em/listen
:mouseleave
#((em/fade-in 500 20) (.currentTarget %)))
["#click"] (em/add-event
["#click"] (em/listen
:click
#(em/at js/document
["#sz-tst"] (em/chain
(em/resize 2 30 500 20)
(em/resize 200 30 500 20 test-callback))))
["#mclick"] (em/add-event
["#mclick"] (em/listen
:click
#(em/at js/document
["#mv-tst"] (em/move 300 305 500 20
["#mv-tst"] (em/move 300 305 500 20
(em/move 0 0 500 20)))))

;(em/defaction test-suite [])



(defn funtimes [msg]
(em/at js/window (em/add-event :resize #(js/alert (str "you resized your window:" %))))
(em/at js/window (em/listen :resize #(js/alert (str "you resized your window:" %))))
(em/at js/document
[:.heading (ef/attr= :foo "true")] (em/content msg))
(em/wait-for-load (test-grid)))
Expand Down

0 comments on commit 6067509

Please sign in to comment.