From 4edc6bff1eddc780a269a86fb8b436aee5ff1201 Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Thu, 5 Jan 2023 22:49:10 -0800 Subject: [PATCH 1/2] eslint: disallow nested ternaries --- .eslintrc.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index ba5a7bbbd..de6eb9cc9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -57,7 +57,8 @@ "space-infix-ops": "error", "space-unary-ops": "error", "spaced-comment": ["error", "always", { "line": { "exceptions": ["-"] }, "block": { "balanced": true } }], - "switch-colon-spacing": "error" + "switch-colon-spacing": "error", + "no-nested-ternary": "error" }, "reportUnusedDisableDirectives": true } From 23c8717ec2e8eb2529f9bff87be9606a3489bb46 Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Thu, 5 Jan 2023 22:56:39 -0800 Subject: [PATCH 2/2] fix two nested ternaries --- modules/twinkleblock.js | 11 ++++++++++- morebits.js | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/twinkleblock.js b/modules/twinkleblock.js index 8cc6d6f2f..d94380e5d 100644 --- a/modules/twinkleblock.js +++ b/modules/twinkleblock.js @@ -1481,7 +1481,16 @@ Twinkle.block.callback.filtered_block_groups = function twinkleblockCallbackFilt } var blockSettings = Twinkle.block.blockPresetsInfo[blockPreset.value]; - var registrationRestrict = blockSettings.forRegisteredOnly ? Twinkle.block.isRegistered : blockSettings.forAnonOnly ? !Twinkle.block.isRegistered : true; + + var registrationRestrict; + if (blockSettings.forRegisteredOnly) { + registrationRestrict = Twinkle.block.isRegistered; + } else if (blockSettings.forAnonOnly) { + registrationRestrict = !Twinkle.block.isRegistered; + } else { + registrationRestrict = true; + } + if (!(blockSettings.templateName && show_template) && registrationRestrict) { var templateName = blockSettings.templateName || blockPreset.value; return { diff --git a/morebits.js b/morebits.js index 08302d282..dd446d69a 100644 --- a/morebits.js +++ b/morebits.js @@ -5981,7 +5981,15 @@ Morebits.simpleWindow.prototype = { $(this.content).find('input[type="submit"], button[type="submit"]').each(function(key, value) { value.style.display = 'none'; var button = document.createElement('button'); - button.textContent = value.hasAttribute('value') ? value.getAttribute('value') : value.textContent ? value.textContent : msg('submit', 'Submit Query'); + + if (value.hasAttribute('value')) { + button.textContent = value.getAttribute('value'); + } else if (value.textContent) { + button.textContent = value.textContent; + } else { + button.textContent = msg('submit', 'Submit Query'); + } + button.className = value.className || 'submitButtonProxy'; // here is an instance of cheap coding, probably a memory-usage hit in using a closure here button.addEventListener('click', function() {