Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created August 23, 2013 14:11
Show Gist options
  • Select an option

  • Save aamedina/6319740 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/6319740 to your computer and use it in GitHub Desktop.
(defprotocol IAnimatable
(position [this])
(scroll [this])
(dims [this])
(width [this])
(height [this])
(fade-in! [el time show?])
(fade-out! [el time hide?]))
(extend-protocol IAnimatable
js/Element
(position [this]
(let [{:keys [x y]} (js->clj (style/getPosition this) :keywordize-keys true)]
(vector x y)))
(scroll [this]
(vector (.-scrollLeft this) (.-scrollTop this)))
(dims [this]
(let [d (js->clj (style/getSize this) :keywordize-keys true)]
(vector (:width d) (:height d))))
(width [this]
(first (dims this)))
(height [this]
(second (dims this)))
(fade-in! [el time show?]
(if show?
(.play (goog.fx.dom.FadeInAndShow. el time))
(.play (goog.fx.dom.FadeIn. el time))))
(fade-out! [el time hide?]
(.play (goog.fx.dom.FadeOutAndHide. el time))))
(defprotocol IStartable
(start [this]))
(defprotocol IDisposable
(dispose [this]))
(extend-protocol IStartable
goog.fx.AnimationQueue
(start [this] (.play this ()))
goog.fx.dom.PredefinedEffect
(start [this] (.play this ())))
(extend-protocol IDisposable
goog.fx.AnimationQueue
(dispose [this] (.dispose this ()))
goog.fx.dom.PredefinedEffect
(dispose [this] (.dispose this ())))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment