1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-08 02:49:56 +00:00
TiddlyWiki5/plugins/tiddlywiki/confetti/startup.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-01-15 21:41:54 +00:00
/*\
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() {
2023-01-16 19:45:05 +00:00
$tw.confettiManager = new $tw.ConfettiManager();
2023-01-15 21:41:54 +00:00
$tw.rootWidget.addEventListener("tm-confetti-launch",function(event) {
var paramObject = event.paramObject || {},
2023-01-16 11:05:10 +00:00
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);
});
2023-01-15 21:41:54 +00:00
options.origin = {
x: paramObject.originX && $tw.utils.parseNumber(paramObject.originX),
y: paramObject.originY && $tw.utils.parseNumber(paramObject.originY)
};
2023-01-16 11:05:10 +00:00
extractBooleanParameter("disableForReducedMotion");
var delay = paramObject.delay ? $tw.utils.parseNumber(paramObject.delay) : 0;
2023-01-16 19:45:05 +00:00
$tw.confettiManager.launch(delay,options);
2023-01-15 21:41:54 +00:00
});
2023-01-15 21:59:07 +00:00
$tw.rootWidget.addEventListener("tm-confetti-reset",function(event) {
2023-01-16 19:45:05 +00:00
$tw.confettiManager.reset();
2023-01-15 21:41:54 +00:00
});
};
})();