1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-08 02:49:56 +00:00
TiddlyWiki5/plugins/tiddlywiki/confetti/confetti-manager.js
jeremy@jermolene.com 5b9f464f26 Add confetti widget
2023-01-16 19:45:05 +00:00

51 lines
1.0 KiB
JavaScript

/*\
title: $:/plugins/tiddlywiki/confetti/confetti-manager.js
type: application/javascript
module-type: global
Confetti manager
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var confetti = require("$:/plugins/tiddlywiki/confetti/confetti.js");
function ConfettiManager() {
this.outstandingTimers = [];
}
ConfettiManager.prototype.launch = function (delay,options) {
var self = this;
if(delay > 0) {
var id = setTimeout(function() {
var p = self.outstandingTimers.indexOf(id);
if(p !== -1) {
self.outstandingTimers.splice(p,1);
} else {
console.log("Confetti Manager Error: Cannot find previously stored timer ID");
debugger;
}
confetti(options);
},delay);
this.outstandingTimers.push(id);
} else {
confetti(options);
}
};
ConfettiManager.prototype.reset = function () {
$tw.utils.each(this.outstandingTimers,function(id) {
clearTimeout(id);
});
this.outstandingTimers = [];
confetti.reset();
};
exports.ConfettiManager = ConfettiManager;
})();