2009-04-08 05:44:44 -04:00
|
|
|
/*
|
|
|
|
Animation Task Manager
|
|
|
|
|
|
|
|
Usage:
|
2009-04-08 06:11:37 -04:00
|
|
|
window['piro.sakura.ne.jp'].animationManager.addTask(
|
2009-04-09 21:32:03 -04:00
|
|
|
function(aTime, aBeginningValue, aTotalChange, aDuration) {
|
2009-04-08 06:11:37 -04:00
|
|
|
// some animation task runned by interval
|
2009-04-09 21:32:03 -04:00
|
|
|
var current = someEasingFunction(aTime, aBeginningValue, aTotalChange, aDuration);
|
2009-04-08 06:11:37 -04:00
|
|
|
target.style.left = current+'px';
|
2009-04-09 21:32:03 -04:00
|
|
|
return aTime > aDuration; // return true if the animation finished.
|
2009-04-08 06:11:37 -04:00
|
|
|
},
|
|
|
|
100, // beginning
|
2009-04-09 21:32:03 -04:00
|
|
|
200, // total change (so, the final value will be 100+200=300)
|
|
|
|
250 // msec, duration
|
2009-04-08 06:11:37 -04:00
|
|
|
);
|
2009-04-08 05:44:44 -04:00
|
|
|
// stop all
|
|
|
|
window['piro.sakura.ne.jp'].animationManager.stop();
|
2009-04-09 21:35:01 -04:00
|
|
|
// restart after doing something
|
|
|
|
window['piro.sakura.ne.jp'].animationManager.start();
|
2009-04-08 05:44:44 -04:00
|
|
|
|
2010-08-26 11:40:13 -04:00
|
|
|
license: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
|
2009-04-08 05:44:44 -04:00
|
|
|
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
|
|
|
|
original:
|
|
|
|
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/animationManager.js
|
|
|
|
*/
|
2010-06-22 19:46:51 -04:00
|
|
|
|
2010-06-26 11:13:11 -04:00
|
|
|
/* To work as a JS Code Module (*require jstimer.jsm)
|
2010-06-22 21:32:31 -04:00
|
|
|
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/jstimer.jsm */
|
|
|
|
if (typeof window == 'undefined') {
|
|
|
|
this.EXPORTED_SYMBOLS = ['animationManager'];
|
2010-06-22 19:46:51 -04:00
|
|
|
|
2010-06-26 11:13:11 -04:00
|
|
|
// If namespace.jsm is available, export symbols to the shared namespace.
|
|
|
|
// See: http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/namespace.jsm
|
2010-06-22 19:46:51 -04:00
|
|
|
let ns = {};
|
2010-06-26 11:13:11 -04:00
|
|
|
try {
|
|
|
|
Components.utils.import('resource://treestyletab-modules/namespace.jsm', ns);
|
|
|
|
/* var */ window = ns.getNamespaceFor('piro.sakura.ne.jp');
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
window = {};
|
|
|
|
}
|
2010-06-22 19:46:51 -04:00
|
|
|
if (!('setInterval' in window))
|
|
|
|
Components.utils.import('resource://treestyletab-modules/jstimer.jsm', window);
|
|
|
|
}
|
|
|
|
|
2009-04-08 05:44:44 -04:00
|
|
|
(function() {
|
2009-11-25 05:35:52 -05:00
|
|
|
const currentRevision = 5;
|
2009-04-08 05:44:44 -04:00
|
|
|
|
|
|
|
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
|
|
|
|
|
|
|
|
var loadedRevision = 'animationManager' in window['piro.sakura.ne.jp'] ?
|
|
|
|
window['piro.sakura.ne.jp'].animationManager.revision :
|
|
|
|
0 ;
|
|
|
|
var tasks = !loadedRevision ? [] : window['piro.sakura.ne.jp'].animationManager.tasks ;
|
|
|
|
if (loadedRevision && loadedRevision > currentRevision) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var Cc = Components.classes;
|
|
|
|
var Ci = Components.interfaces;
|
|
|
|
|
2009-04-08 06:35:29 -04:00
|
|
|
if (tasks.length)
|
|
|
|
window['piro.sakura.ne.jp'].animationManager.stop();
|
|
|
|
|
2009-04-08 05:44:44 -04:00
|
|
|
window['piro.sakura.ne.jp'].animationManager = {
|
|
|
|
revision : currentRevision,
|
|
|
|
|
2009-04-09 21:32:03 -04:00
|
|
|
addTask : function(aTask, aBeginningValue, aTotalChange, aDuration)
|
2009-04-08 05:44:44 -04:00
|
|
|
{
|
|
|
|
if (!aTask) return;
|
|
|
|
this.tasks.push({
|
|
|
|
task : aTask,
|
2009-04-09 21:37:29 -04:00
|
|
|
start : (new Date()).getTime(),
|
2009-04-08 05:44:44 -04:00
|
|
|
beginning : aBeginningValue,
|
2009-04-09 21:32:03 -04:00
|
|
|
change : aTotalChange,
|
|
|
|
duration : aDuration
|
2009-04-08 05:44:44 -04:00
|
|
|
});
|
2009-04-09 21:35:01 -04:00
|
|
|
if (this.tasks.length == 1)
|
|
|
|
this.start();
|
2009-04-08 05:44:44 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
removeTask : function(aTask)
|
|
|
|
{
|
|
|
|
if (!aTask) return;
|
|
|
|
var task;
|
|
|
|
for (var i in this.tasks)
|
|
|
|
{
|
|
|
|
task = this.tasks[i];
|
|
|
|
if (task.task != aTask) continue;
|
|
|
|
delete task.task;
|
|
|
|
delete task.start;
|
|
|
|
delete task.beginning;
|
2009-04-09 21:32:03 -04:00
|
|
|
delete task.change;
|
|
|
|
delete task.duration;
|
2009-04-08 05:44:44 -04:00
|
|
|
this.tasks.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!this.tasks.length)
|
|
|
|
this.stop();
|
|
|
|
},
|
|
|
|
|
2009-04-09 21:35:01 -04:00
|
|
|
start : function()
|
|
|
|
{
|
|
|
|
this.stop();
|
|
|
|
this.timer = window.setInterval(
|
|
|
|
this.onAnimation,
|
|
|
|
this.interval,
|
|
|
|
this
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2009-04-08 05:44:44 -04:00
|
|
|
stop : function()
|
|
|
|
{
|
|
|
|
if (!this.timer) return;
|
|
|
|
window.clearInterval(this.timer);
|
|
|
|
this.timer = null;
|
|
|
|
},
|
|
|
|
|
2009-04-09 21:32:03 -04:00
|
|
|
removeAllTasks : function()
|
|
|
|
{
|
|
|
|
this.stop();
|
|
|
|
this.tasks = [];
|
|
|
|
},
|
|
|
|
|
2009-04-08 05:44:44 -04:00
|
|
|
tasks : tasks,
|
|
|
|
interval : 10,
|
|
|
|
timer : null,
|
|
|
|
|
|
|
|
onAnimation : function(aSelf)
|
|
|
|
{
|
|
|
|
// task should return true if it finishes.
|
2009-04-09 21:37:29 -04:00
|
|
|
var now = (new Date()).getTime();
|
2009-11-25 05:35:52 -05:00
|
|
|
var tasks = aSelf.tasks;
|
|
|
|
aSelf.tasks = [null];
|
|
|
|
tasks = tasks.filter(function(aTask) {
|
|
|
|
if (!aTask) return false;
|
2009-04-08 06:03:17 -04:00
|
|
|
try {
|
|
|
|
return !aTask.task(
|
2009-04-08 09:43:44 -04:00
|
|
|
now - aTask.start,
|
2009-04-08 06:03:17 -04:00
|
|
|
aTask.beginning,
|
2009-04-09 21:32:03 -04:00
|
|
|
aTask.change,
|
|
|
|
aTask.duration
|
2009-04-08 06:03:17 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
}
|
2009-04-08 07:07:24 -04:00
|
|
|
return false;
|
2009-04-08 05:44:44 -04:00
|
|
|
});
|
2009-11-25 05:35:52 -05:00
|
|
|
aSelf.tasks = aSelf.tasks.slice(1).concat(tasks);
|
2009-04-08 05:44:44 -04:00
|
|
|
if (!aSelf.tasks.length)
|
|
|
|
aSelf.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2009-04-09 21:37:29 -04:00
|
|
|
|
|
|
|
if (tasks.length)
|
|
|
|
window['piro.sakura.ne.jp'].animationManager.start();
|
2009-04-08 05:44:44 -04:00
|
|
|
})();
|
2010-06-22 19:46:51 -04:00
|
|
|
|
|
|
|
if (window != this) { // work as a JS Code Module
|
2010-06-22 21:32:31 -04:00
|
|
|
this.animationManager = window['piro.sakura.ne.jp'].animationManager;
|
2010-06-22 19:46:51 -04:00
|
|
|
}
|