Skip to content

Instantly share code, notes, and snippets.

@bloodyowl
Created October 22, 2012 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bloodyowl/3931534 to your computer and use it in GitHub Desktop.
Save bloodyowl/3931534 to your computer and use it in GitHub Desktop.
Transition (craft.js mixin)
DOM.prototype.transition = function(transition, persistent){
var element = this,
hash = new Hash,
prop = "TransitionEvent" in window ? 0 : // FF >= 16
"WebKitTransitionEvent" in window ? 1 : // webkit
+opera.version() > 10.49 ? 2 : // Opera
"mozTransitionEvent" in window ? 3 : // FF <= 15
"msTransitionEvent" in window ? 4 : // IE
-1, // nope
event = Craft.toArray("transitionend webkitTransitionEnd oTransitionEnd mozTransitionEnd msTransitionEnd")[prop], // defines the matching event name
handler, // placeholder
emptyProperties; // placeholder
Craft.toArray("-webkit- -moz- -o- ").forEach(function(item){ hash.set((item + "transition").camelize(), transition) })
element.css(hash);
if(persistent == true || prop == -1) return;
element.listen(event, (handler = function(){
emptyProperties = hash.clone();
emptyProperties.forEach(function(item, index){ emptyProperties[index] = "" });
element.css(emptyProperties);
element.stopListening(event, handler)
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment