Fix snowfall plugin #434

This commit is contained in:
the-djmaze 2022-06-13 21:21:51 +02:00
parent a8eee1dbcf
commit ab2a81cd9b
3 changed files with 23 additions and 33 deletions

View file

@ -4,7 +4,7 @@ class SnowfallOnLoginScreenPlugin extends \RainLoop\Plugins\AbstractPlugin
{ {
const const
NAME = 'Snowfall on login screen', NAME = 'Snowfall on login screen',
VERSION = '2.0', VERSION = '2.1',
CATEGORY = 'Fun', CATEGORY = 'Fun',
DESCRIPTION = 'Snowfall on login screen (just for fun).'; DESCRIPTION = 'Snowfall on login screen (just for fun).';

View file

@ -1,12 +1,17 @@
if (!/iphone|ipod|ipad|android/i.test(navigator.userAgent)) if (!/iphone|ipod|ipad|android/i.test(navigator.userAgent))
{ {
document.addEventListener('DOMContentLoaded', () => { if (window.snowFall && window.rl)
if (window.snowFall && window.rl && !rl.settings.get('Auth'))
{ {
window.snowFall.snow(document.getElementsByTagName('body'), { let body = document.body;
addEventListener('sm-show-screen', e => {
if ('login' == e.detail) {
window.snowFall.snow(body, {
shadow: true, round: true, minSize: 2, maxSize: 5 shadow: true, round: true, minSize: 2, maxSize: 5
}); });
} else if (body.snow) {
body.snow.clear();
} }
}); });
} }
}

View file

@ -47,7 +47,7 @@
*/ */
// Paul Irish requestAnimationFrame polyfill // Paul Irish requestAnimationFrame polyfill
(function(window) { (window => {
var lastTime = 0; var lastTime = 0;
var vendors = ['webkit', 'moz']; var vendors = ['webkit', 'moz'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@ -57,11 +57,10 @@
} }
if (!window.requestAnimationFrame) if (!window.requestAnimationFrame)
window.requestAnimationFrame = function(callback, element) { window.requestAnimationFrame = callback => {
var currTime = new Date().getTime(); var currTime = new Date().getTime();
var timeToCall = window.Math.max(0, 16 - (currTime - lastTime)); var timeToCall = window.Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() { callback(currTime + timeToCall); }, var id = window.setTimeout(() => callback(currTime + timeToCall), timeToCall);
timeToCall);
lastTime = currTime + timeToCall; lastTime = currTime + timeToCall;
return id; return id;
}; };
@ -70,7 +69,7 @@
window.cancelAnimationFrame = function(id) { window.cancelAnimationFrame = function(id) {
clearTimeout(id); clearTimeout(id);
}; };
}(window)); })(window);
var snowFall = (function(){ var snowFall = (function(){
function jSnow(){ function jSnow(){
@ -248,28 +247,14 @@ var snowFall = (function(){
cancelAnimationFrame(snowTimeout); cancelAnimationFrame(snowTimeout);
} }
}; };
}; }
return{ return{
snow : function(elements, options){ snow : (elements, options) => {
if(typeof(options) === 'string'){ if(typeof(options) === 'string'){
if(elements.length > 0){
for(var i = 0; i < elements.length; i++){
if(elements[i].snow){
elements[i].snow.clear();
}
}
}else{
elements.snow.clear(); elements.snow.clear();
}
}else{
if(elements.length > 0){
for(var i = 0; i < elements.length; i++){
new jSnow().snow(elements[i], options);
}
}else{ }else{
new jSnow().snow(elements, options); new jSnow().snow(elements, options);
} }
} }
}
}; };
})(); })();