From c6f0ff875a9dbf3111a9df14521802da49c4a3ff Mon Sep 17 00:00:00 2001 From: ZoruaFox <96456728+ZoruaFox@users.noreply.github.com> Date: Wed, 4 Oct 2023 22:51:47 +0800 Subject: [PATCH] refactor(Ding.js): pull code from Qiuwen upstream --- src/Gadgets/Compatibility/Ding/Ding.js | 32 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/Gadgets/Compatibility/Ding/Ding.js b/src/Gadgets/Compatibility/Ding/Ding.js index 609e8cb..3d34f20 100644 --- a/src/Gadgets/Compatibility/Ding/Ding.js +++ b/src/Gadgets/Compatibility/Ding/Ding.js @@ -3,6 +3,7 @@ * _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}' * * @base + * @base * @source */ /** @@ -12,36 +13,45 @@ * | All changes should be made in the repository, | * | otherwise they will be lost. | * +--------------------------------------------------------+ - * | Changes to this page affect many users. | - * | Please discuss changes at Talk page before editing. | + * | Changes to this page may affect many users. | + * | Please discuss changes at talk page before editing. | * +--------------------------------------------------------+ */ /* */ -'use strict'; - window.DingExposedInterface = function ding() { var dingMain = function dingMain(message) { var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'info'; var ttl = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3600; var persist = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; if (!document.querySelector('#ding')) { - document.body.insertAdjacentHTML('afterbegin', '
'); + var dingDiv = document.createElement('div'); + dingDiv.id = 'ding'; + dingDiv.className = 'noprint'; + document.body.insertAdjacentElement('afterbegin', dingDiv); } var dingElement = document.querySelector('#ding'); var previousMessage = dingElement.lastChild; if (previousMessage) { var previousMessageStyle = previousMessage.style; - previousMessageStyle.transform = 'translateY(-130%)'; + previousMessageStyle.transform = 'translateY(125%)'; setTimeout(function () { previousMessage.remove(); }, 500); } - dingElement.insertAdjacentHTML('beforeend', "
").concat(message, "
")); + var dingInnerElement = document.createElement('div'); + // The following classes are used here: + // * ding_inner + // * ding_info + // * ding_success + // * ding_warning + dingInnerElement.className = "ding_inner ding_".concat(type); + dingInnerElement.innerHTML = message; + dingElement.insertAdjacentElement('beforeend', dingInnerElement); var noticeElement = dingElement.lastChild; var noticeElementStyle = noticeElement.style; if (persist) { - noticeElement === null || noticeElement === void 0 ? void 0 : noticeElement.addEventListener('click', function () { - noticeElementStyle.transform = 'translateY(-130%)'; + noticeElement === null || noticeElement === void 0 || noticeElement.addEventListener('click', function () { + noticeElementStyle.transform = 'translateY(125%)'; setTimeout(function () { noticeElement.remove(); }, 500); @@ -52,10 +62,10 @@ window.DingExposedInterface = function ding() { }, 10); if (ttl !== 'long') { setTimeout(function () { - noticeElementStyle.transform = 'translateY(-130%)'; + noticeElementStyle.transform = 'translateY(125%)'; }, ttl + 10); setTimeout(function () { - noticeElement === null || noticeElement === void 0 ? void 0 : noticeElement.remove(); + noticeElement === null || noticeElement === void 0 || noticeElement.remove(); }, ttl + 510); } };