Skip to content

Instantly share code, notes, and snippets.

@ameyamashiro
Created August 12, 2014 10:51
Show Gist options
  • Save ameyamashiro/ef7afd39f98d09182577 to your computer and use it in GitHub Desktop.
Save ameyamashiro/ef7afd39f98d09182577 to your computer and use it in GitHub Desktop.
Add fallback to transit.js
(function() {
$.fn.transitAnimate = function(properties, duration, easing, callback) {
var deepFallback, fallbackCSS, hasDelay, needFallback, self;
self = this;
hasDelay = false;
needFallback = false;
deepFallback = false;
fallbackCSS = {};
if (properties.hasOwnProperty('delay')) {
hasDelay = true;
}
if (properties.hasOwnProperty('fallback')) {
needFallback = true;
}
if ($.fn.transition === null) {
needFallback = true;
}
if (!$.support.transition) {
needFallback = true;
}
if (!$.support.opacity) {
if (properties.hasOwnProperty('opacity')) {
fallbackCSS.opacity = properties.opacity;
delete properties.opacity;
}
}
if (!$.support.transition) {
if (!properties.hasOwnProperty('nodeepfallback')) {
deepFallback = true;
}
}
if (duration instanceof Function) {
callback = duration;
}
if (needFallback) {
if (deepFallback) {
return setTimeout(function() {
return self.css(fallbackCSS);
}, properties.delay);
} else if (hasDelay) {
setTimeout(function() {
return self.css(fallbackCSS);
}, properties.delay);
return this.delay(properties.delay).animate(properties, duration, easing, function() {
if (callback instanceof Function) {
return callback.call($(this));
}
});
} else {
return this.animate(properties, duration, easing, function() {
$(this).css(fallbackCSS);
if (callback instanceof Function) {
return callback.call($(this));
}
});
}
} else {
if (properties.hasOwnProperty('nodeepfallback')) {
delete properties.nodeepfallback;
}
return this.transition(properties, duration, easing, callback);
}
};
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment