Просмотр исходного кода

fix: resolve ESLint errors after jQuery removal

- Replace optional chaining (?.) with explicit null check — ecmaVersion
  is 2018, optional chaining requires ES2020
- Extract TopNav event binding into bindEvents() — init() had 70
  statements exceeding the max-statements limit of 60

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
rugk 1 месяц назад
Родитель
Сommit
cdbade05f5
1 измененных файлов с 35 добавлено и 25 удалено
  1. 35 25
      js/privatebin.js

+ 35 - 25
js/privatebin.js

@@ -4650,29 +4650,14 @@ window.PrivateBin = (function () {
          * @name   TopNav.init
          * @name   TopNav.init
          * @function
          * @function
          */
          */
-        me.init = function () {
-            attach = document.getElementById('attach');
-            burnAfterReading = document.getElementById('burnafterreading');
-            burnAfterReadingOption = document.getElementById('burnafterreadingoption');
-            cloneButton = document.getElementById('clonebutton');
-            customAttachment = document.getElementById('customattachment');
-            expiration = document.getElementById('expiration');
-            fileRemoveButton = document.getElementById('fileremovebutton');
-            fileWrap = document.getElementById('filewrap');
-            formatter = document.getElementById('formatter');
-            newButton = document.getElementById('newbutton');
-            openDiscussion = document.getElementById('opendiscussion');
-            openDiscussionOption = document.getElementById('opendiscussionoption');
-            password = document.getElementById('password');
-            passwordInput = document.getElementById('passwordinput');
-            rawTextButton = document.getElementById('rawtextbutton');
-            downloadTextButton = document.getElementById('downloadtextbutton');
-            retryButton = document.getElementById('retrybutton');
-            sendButton = document.getElementById('sendbutton');
-            qrCodeLink = document.getElementById('qrcodelink');
-            emailLink = document.getElementById('emaillink');
-
-            // bootstrap template drop down
+        /**
+         * bind all navigation event listeners
+         *
+         * @name   TopNav.bindEvents
+         * @private
+         * @function
+         */
+        function bindEvents() {
             const languageDropdown = document.getElementById('language');
             const languageDropdown = document.getElementById('language');
             if (languageDropdown) {
             if (languageDropdown) {
                 languageDropdown.querySelectorAll('ul.dropdown-menu li a').forEach(link => {
                 languageDropdown.querySelectorAll('ul.dropdown-menu li a').forEach(link => {
@@ -4680,7 +4665,6 @@ window.PrivateBin = (function () {
                 });
                 });
             }
             }
 
 
-            // bootstrap template drop down
             const templateDropdown = document.getElementById('template');
             const templateDropdown = document.getElementById('template');
             if (templateDropdown) {
             if (templateDropdown) {
                 templateDropdown.querySelectorAll('ul.dropdown-menu li a').forEach(link => {
                 templateDropdown.querySelectorAll('ul.dropdown-menu li a').forEach(link => {
@@ -4760,6 +4744,31 @@ window.PrivateBin = (function () {
                     });
                     });
                 }
                 }
             }
             }
+        }
+
+        me.init = function () {
+            attach = document.getElementById('attach');
+            burnAfterReading = document.getElementById('burnafterreading');
+            burnAfterReadingOption = document.getElementById('burnafterreadingoption');
+            cloneButton = document.getElementById('clonebutton');
+            customAttachment = document.getElementById('customattachment');
+            expiration = document.getElementById('expiration');
+            fileRemoveButton = document.getElementById('fileremovebutton');
+            fileWrap = document.getElementById('filewrap');
+            formatter = document.getElementById('formatter');
+            newButton = document.getElementById('newbutton');
+            openDiscussion = document.getElementById('opendiscussion');
+            openDiscussionOption = document.getElementById('opendiscussionoption');
+            password = document.getElementById('password');
+            passwordInput = document.getElementById('passwordinput');
+            rawTextButton = document.getElementById('rawtextbutton');
+            downloadTextButton = document.getElementById('downloadtextbutton');
+            retryButton = document.getElementById('retrybutton');
+            sendButton = document.getElementById('sendbutton');
+            qrCodeLink = document.getElementById('qrcodelink');
+            emailLink = document.getElementById('emaillink');
+
+            bindEvents();
 
 
             // initiate default state of checkboxes
             // initiate default state of checkboxes
             changeBurnAfterReading();
             changeBurnAfterReading();
@@ -5720,7 +5729,8 @@ window.PrivateBin = (function () {
          */
          */
         function handleRevealButtonClick() {
         function handleRevealButtonClick() {
             const element = this;
             const element = this;
-            const passwordInput = element.closest('.input-group')?.querySelector('.input-password');
+            const inputGroup = element.closest('.input-group');
+            const passwordInput = inputGroup ? inputGroup.querySelector('.input-password') : null;
             if (!passwordInput) {
             if (!passwordInput) {
                 return;
                 return;
             }
             }