Skip to content

Instantly share code, notes, and snippets.

@maolion
Created November 24, 2014 12:35
Show Gist options
  • Save maolion/69e263d4f225e7d2991c to your computer and use it in GitHub Desktop.
Save maolion/69e263d4f225e7d2991c to your computer and use it in GitHub Desktop.
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);
}
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