From 906576dd17ff492d9dbeb384ac4dd21a5bb7ebd8 Mon Sep 17 00:00:00 2001 From: axunonb Date: Mon, 20 Nov 2023 20:09:21 +0100 Subject: [PATCH 1/2] Refactor and stabilize Site global javascript modules * Update Bootstrap to v5.3.2 * Avoid errors on Safari browser * Move function variables to functions * Add more code comments * Remove obsolete Polyfill.js * Modify .editor.config for javascript (use single quotes) --- .editorconfig | 3 + League/Gruntfile.js | 2 +- League/Scripts/Polyfill.js | 14 - League/Scripts/Site.ModalForm.js | 210 +- League/Scripts/Site.TempusDominusFactory.js | 10 +- .../Scripts/Site.TempusDominusFactory.min.js | 2 +- League/package-lock.json | 2944 ++++++++--------- League/package.json | 2 +- package-lock.json | 6 - 9 files changed, 1503 insertions(+), 1690 deletions(-) delete mode 100644 League/Scripts/Polyfill.js delete mode 100644 package-lock.json diff --git a/.editorconfig b/.editorconfig index 886fbd42..ea33f08a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -260,5 +260,8 @@ dotnet_style_qualification_for_property = false:suggestion dotnet_style_qualification_for_method = false:suggestion dotnet_style_qualification_for_event = false:suggestion +[*.js] +quote_style = singlequoted + # Copyright file header file_header_template = \nCopyright Volleyball League Project maintainers and contributors.\nLicensed under the MIT license.\n diff --git a/League/Gruntfile.js b/League/Gruntfile.js index f1b14855..1ca74d88 100644 --- a/League/Gruntfile.js +++ b/League/Gruntfile.js @@ -79,7 +79,7 @@ module.exports = function (grunt) { }, build: { files: { - 'wwwroot/js/site.min.js': ['Scripts/Polyfill.js', 'Scripts/Site.ModalForm.js', 'Scripts/Site.ShowPassword.js', 'node_modules/js-cookie/src/js.cookie.js'], + 'wwwroot/js/site.min.js': ['Scripts/Site.ModalForm.js', 'Scripts/Site.ShowPassword.js', 'node_modules/js-cookie/src/js.cookie.js'] } } }, diff --git a/League/Scripts/Polyfill.js b/League/Scripts/Polyfill.js deleted file mode 100644 index f52a3cae..00000000 --- a/League/Scripts/Polyfill.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Polyfill for Element.closest - */ -if (typeof (Element.prototype.closest == 'undefined')) { - Element.prototype.closest = function (property, value) { - var x = this; - while (x = x.parentElement) { - if (x[property] == value) { - return this; - } - } - return null; - } -} diff --git a/League/Scripts/Site.ModalForm.js b/League/Scripts/Site.ModalForm.js index 458b6e2a..cf9cd056 100644 --- a/League/Scripts/Site.ModalForm.js +++ b/League/Scripts/Site.ModalForm.js @@ -1,7 +1,13 @@ // All scripts go into the same namespace +'use strict'; if (Site === undefined) { var Site = {}; } +// Define all undefined variables as empty objects +if (bootstrap === undefined) bootstrap = {}; +if (JL === undefined) JL = {}; +if (URLSearchParams === undefined) URLSearchParams = {}; +if (AbortController === undefined) AbortController = {}; /* Handling of forms inside Bootstrap 5 modals */ Site.ModalForm = function () { @@ -16,25 +22,14 @@ Site.ModalForm = function () { 'modal-form-error-occurred': 'Ups... ein Fehler ist aufgetreten. Bitte nochmals versuchen.' } }; - function getLocalized(key) { - const locale = document.documentElement.lang; - const fbLocale = locale.split('-')[0]; - if (translations[locale]) { - return translations[locale][key]; - } else if (translations[fbLocale]) { - return translations[fbLocale][key]; - } else if (translations['en']) { - return translations['en'][key]; - } - } let submittingElement; // create a dynamic DIV element and insert it as first child of BODY const modalContainer = document.createElement('div'); - modalContainer.id = 'modal-container-' + Math.random().toString(36).substring(2, 16); + modalContainer.id = `modal-container-${Math.random().toString(36).substring(2, 16)}`; document.body.insertAdjacentElement('afterbegin', modalContainer); - + // see also: modalFullTemplate const modalDialogTemplate = `