Stackedit/public/res/extensions/workingIndicator.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
2013-05-29 19:55:23 +00:00
"jquery",
2013-06-22 23:48:57 +00:00
"underscore",
"classes/Extension",
2013-11-16 18:09:33 +00:00
"crel"
], function ($, _, Extension, crel) {
2013-05-29 19:55:23 +00:00
2013-06-22 23:48:57 +00:00
var workingIndicator = new Extension("workingIndicator", "Working Indicator");
2013-05-29 19:55:23 +00:00
2013-11-07 23:10:38 +00:00
var $bodyElt;
var $workingIndicatorElt;
2013-11-16 18:09:33 +00:00
var intervalId;
workingIndicator.onAsyncRunning = function (isRunning) {
2013-08-22 00:19:59 +00:00
$bodyElt.toggleClass("working", isRunning);
$workingIndicatorElt.toggleClass("show", isRunning);
2013-11-16 18:09:33 +00:00
if(isRunning) {
animate();
intervalId = setInterval(animate, 200);
}
else {
clearInterval(intervalId);
}
2013-08-22 00:19:59 +00:00
};
2013-11-16 18:09:33 +00:00
var indicatorElts = [];
var loop = 0;
function animate() {
indicatorElts[loop].className = '';
loop = (loop + 1) % 3;
indicatorElts[loop].className = 'highlighted';
}
workingIndicator.onReady = function () {
2013-08-22 00:19:59 +00:00
$bodyElt = $(document.body);
$workingIndicatorElt = $(".working-indicator");
2013-11-16 18:09:33 +00:00
for (var i = 0; i < 3; i++) {
indicatorElts.push(crel('div'));
}
$workingIndicatorElt.append(indicatorElts);
2013-05-29 19:55:23 +00:00
};
return workingIndicator;
2013-05-27 19:45:33 +00:00
});