ncase.me-trust/js/core/Scratcher.js

50 lines
986 B
JavaScript
Raw Normal View History

2017-07-10 15:38:20 +00:00
(function(exports){
var Scratcher = {};
exports.Scratcher = Scratcher;
2017-07-12 13:42:17 +00:00
Scratcher.scratch = function(gotoID){
2017-07-10 15:38:20 +00:00
var dom = $("#scratcher");
dom.style.display = "block";
Scratcher.scratchAnim(true)
.then(function(){
2017-07-12 13:42:17 +00:00
if(gotoID){
publish("slideshow/goto", [gotoID]);
}else{
publish("slideshow/next");
}
2017-07-10 15:38:20 +00:00
})
.then(function(){
return Scratcher.scratchAnim(false);
})
.then(function(){
dom.style.display = "none";
});
};
subscribe("slideshow/scratch", Scratcher.scratch);
Scratcher.scratchAnim = function(scratchIn){
var dom = $("#scratcher");
var deferred = Q.defer();
var frame = 0;
var interval = setInterval(function(){
frame++;
if(frame>19){
clearInterval(interval);
deferred.resolve();
}else{
Scratcher.gotoFrame(scratchIn, frame);
}
},40);
return deferred.promise;
};
Scratcher.gotoFrame = function(scratchIn, frame){
var dom = $("#scratcher");
dom.style.backgroundPosition = (scratchIn?0:-100)+"% "+(frame*-100)+"%";
};
})(window);