1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-16 06:44:50 +00:00
TiddlyWiki5/plugins/tiddlywiki/confetti/startup.js
jeremy@jermolene.com 5b9f464f26 Add confetti widget
2023-01-16 19:45:05 +00:00

56 lines
1.7 KiB
JavaScript

/*\
title: $:/plugins/tiddlywiki/confetti/startup.js
type: application/javascript
module-type: startup
Setup the root widget event handlers
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
// Export name and synchronous status
exports.name = "confetti";
exports.platforms = ["browser"];
exports.after = ["startup"];
exports.synchronous = true;
// Install the root widget event handlers
exports.startup = function() {
$tw.confettiManager = new $tw.ConfettiManager();
$tw.rootWidget.addEventListener("tm-confetti-launch",function(event) {
var paramObject = event.paramObject || {},
options = {},
extractNumericParameter = function(name) {
options[name] = paramObject[name] && $tw.utils.parseNumber(paramObject[name]);
},
extractListParameter = function(name) {
options[name] = paramObject[name] && $tw.utils.parseStringArray(paramObject[name]);
},
extractBooleanParameter = function(name) {
options[name] = paramObject[name] && paramObject[name] === "yes";
};
$tw.utils.each("particleCount angle spread startVelocity decay gravity drift ticks scalar zIndex".split(" "),function(name) {
extractNumericParameter(name);
});
$tw.utils.each("colors shapes".split(" "),function(name) {
extractListParameter(name);
});
options.origin = {
x: paramObject.originX && $tw.utils.parseNumber(paramObject.originX),
y: paramObject.originY && $tw.utils.parseNumber(paramObject.originY)
};
extractBooleanParameter("disableForReducedMotion");
var delay = paramObject.delay ? $tw.utils.parseNumber(paramObject.delay) : 0;
$tw.confettiManager.launch(delay,options);
});
$tw.rootWidget.addEventListener("tm-confetti-reset",function(event) {
$tw.confettiManager.reset();
});
};
})();