Created
August 12, 2014 10:51
-
-
Save ameyamashiro/ef7afd39f98d09182577 to your computer and use it in GitHub Desktop.
Add fallback to transit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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