Last active
August 29, 2015 14:10
-
-
Save maolion/02fe7a0a78923275d550 to your computer and use it in GitHub Desktop.
This file contains 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
var | |
Base = require("akd:base"), | |
Animation = require("akd:modules/Animation"), | |
Loading = new Base.Event | |
; | |
var animates = {}; | |
var loading = null; | |
Loading.init = function(){ | |
loading = jQuery("#loading"); | |
animates.centerSwipeToTop = new Animation({ | |
element : loading, | |
duration : 800, | |
timing : 'easeOutBack', | |
to : { opacity : 0, top : '80%' }, | |
onStart : function(){ | |
loading.addClass('pause-circle-animate'); | |
}, | |
onEnd : function(){ | |
Loading.hide(); | |
} | |
}); | |
animates.centerSwipeToBottom = new Animation({ | |
element : loading, | |
duration : 800, | |
timing : 'easeOutBack', | |
to : { opacity : 0, top : '20%' }, | |
onStart : function(){ | |
loading.addClass('pause-circle-animate'); | |
}, | |
onEnd : function(){ | |
Loading.hide(); | |
} | |
}); | |
animates.bottomSwipeToCenter = new Animation({ | |
element : loading, | |
duration : 800, | |
timing : 'easeOutBack', | |
from : { opacity : 0, top : '80%' }, | |
to : { opacity : 1, top : '50%' }, | |
onStart : function(){ | |
loading.addClass('pause-circle-animate'); | |
}, | |
onEnd : function(){ | |
loading.removeClass('pause-circle-animate showing'); | |
} | |
}); | |
animates.topSwipeToCenter = new Animation({ | |
element : loading, | |
duration : 800, | |
timing : 'easeOutBack', | |
from : { opacity : 0, top : '20%' }, | |
to : { opacity : 1, top : '50%' }, | |
onStart : function(){ | |
loading.addClass('pause-circle-animate'); | |
}, | |
onEnd : function(){ | |
loading.removeClass('pause-circle-animate showing'); | |
} | |
}); | |
animates.swipePrev = new Animation( | |
[{ | |
element : loading, | |
duration : 400, | |
to : { opacity : 0, top : '80%' } | |
}, | |
{ | |
element : loading, | |
duration : 800, | |
timing : 'easeOutBack', | |
from : { opacity : 0, top : '20%' }, | |
to : { opacity : 1, top : '50%' } | |
}], | |
{ | |
onStart : function(){ | |
loading.addClass('pause-circle-animate'); | |
}, | |
onEnd : function(){ | |
loading.removeClass('pause-circle-animate showing'); | |
} | |
} | |
); | |
animates.swipeNext = new Animation( | |
[{ | |
element : loading, | |
duration : 400, | |
to : { opacity : 0, top : '20%' } | |
}, | |
{ | |
element : loading, | |
duration : 800, | |
timing : 'easeOutBack', | |
from : { opacity : 0, top : '80%' }, | |
to : { opacity : 1, top : '50%' } | |
}], | |
{ | |
onStart : function(){ | |
loading.addClass('pause-circle-animate'); | |
}, | |
onEnd : function(){ | |
loading.removeClass('pause-circle-animate showing'); | |
} | |
} | |
); | |
loading.on("webkitAnimationEnd animationend", function(){ | |
Loading.hide(); | |
}); | |
}; | |
L = Loading; | |
var prevAnimate = null; | |
Loading.show = function(direc){ | |
var | |
direc = arguments.length ? ~~direc : 0, | |
animate = null | |
; | |
if (!prevAnimate) { | |
animate = direc > 0 ? animates.bottomSwipeToCenter : animates.topSwipeToCenter; | |
loading.css("opacity", 0); | |
} else { | |
prevAnimate.pause(); | |
animate = direc > 0 ? animates.swipeNext : animates.swipePrev; | |
} | |
loading.attr("class", "show pause-circle-animate"); | |
animate.reset(); | |
animate.play(); | |
prevAnimate = animate; | |
}; | |
Loading.hide = function(direc){ | |
if (!loading.hasClass('show')) return; | |
if (prevAnimate) { | |
prevAnimate.pause(); | |
prevAnimate = null; | |
} | |
if (arguments.length === 0) { | |
loading.attr("class", "pause-circle-animate"); | |
return; | |
} | |
var animate = animates[~~direc < 0 ? 'centerSwipeToTop' : 'centerSwipeToBottom']; | |
animate.reset(); | |
animate.play(); | |
prevAnimate = animate; | |
}; | |
Loading.done = function(){ | |
if (!loading.hasClass('show')) return; | |
if (prevAnimate && prevAnimate.isRunning()) { | |
if (prevAnimate === animates.centerSwipeToTop || prevAnimate == animates.centerSwipeToBottom) { | |
return; | |
} | |
var p = prevAnimate; | |
p.un("end", Loading.done); | |
p.one("paused", function(){ | |
p.un("end", Loading.done); | |
}); | |
p.on("end", Loading.done); | |
return; | |
} | |
loading.addClass("done pause-circle-animate"); | |
}; | |
module.exports = Loading; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment