Thanks David. That worked a treat.
For anyone curious, I've added my working code below.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(ns drag
(:require [goog.math :as math]
[goog.fx :as fx]
[goog.fx.Dragger :as Dragger]
[goog.dom :as dom]
[goog.style :as style]
[goog.events :as events]))
;;
(def Z 5)
(defn setZ [e]
(this-as window
(set! Z (+ Z 1))
(set! (.zIndex (.style (.target window))) Z)
(style/setOpacity (.target window) 0.5)))
(defn end [e]
(this-as window
(style/setOpacity (.target window) 1)))
(def limits (math/Rect. 100 100 500 400))
;; define draggers
(def draggers
(doall
(for [id ["win1" "win2" "win3"]]
(let [win (dom/getElement id)
handle (.firstChild win)]
(doto (fx/Dragger. win handle limits)
(events/listen "start" setZ)
(events/listen "end" end))))))
;; special setup for 3rd dragger
(doto (nth draggers 2)
(.setHysteresis 6)
(.setLimits nil))
On 4 November 2011 07:18, David Nolen <[email protected]> wrote:
> Accessing "this" is supported via this-as
>
>
> https://github.com/clojure/clojurescript/commit/09ff093dc86b455e3090ce3612c5e01f3b5bada6
>
>
> On Thu, Nov 3, 2011 at 1:51 AM, olivergeorge <[email protected]>wrote:
>
>> Hello,
>>
>> This must be obvious (pun unintended) but I'm struggling to work out
>> how to define a callback function in clojurescript which has a local
>> "this" variable.
>>
>> I see references to "gthis" in the compiler.clj but I'm unsure how to
>> do define a function which uses it.
>>
>> Below is the javascript code snippet I'm attempting to translate into
>> clojurescript.
>>
>> Thanks and apologies the the newby question.
>>
>> cheers, Oliver
>>
>> ====================
>>
>> function started(e) {
>> goog.style.setOpacity(this.target, 0.50);
>> }
>>
>> function ended(e) {
>> goog.style.setOpacity(this.target, 1);
>> }
>>
>> goog.events.listen(window1, 'start', started);
>> goog.events.listen(window1, 'end', ended);
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en