Bläddra i källkod

chore: remove jQuery library

rugk 1 månad sedan
förälder
incheckning
df04d3692e
8 ändrade filer med 27 tillägg och 35 borttagningar
  1. 1 1
      .github/copilot-instructions.md
  2. 1 1
      .jshintrc
  3. 0 2
      js/.istanbul.yml
  4. 0 1
      js/common.js
  5. 0 1
      js/jquery-3.7.1.js
  6. 8 9
      js/legacy.js
  7. 15 17
      js/privatebin.js
  8. 2 3
      lib/Configuration.php

+ 1 - 1
.github/copilot-instructions.md

@@ -38,7 +38,7 @@
 
 
 - **No explicit build step** for PHP. The web app is served directly from source.
 - **No explicit build step** for PHP. The web app is served directly from source.
   - This means **composer directory** need to be comitted (_except_ of big optional dependences like Google Cloud like GCS support or similar!)
   - This means **composer directory** need to be comitted (_except_ of big optional dependences like Google Cloud like GCS support or similar!)
-- **For JavaScript:** There is no webpack/bundler step for release; browser JS is written in compatible ES6+ syntax, except in `legacy.js` (which must be designed to run cleanly even on ancient IE4 or Netscape to display the error message that a browser upgrade is necessary). We are trying to avoid jQuery in any new code and would like to eventually drop use of jQuery. We are considering modularizing the JS logic, but need to ensure to do so in a way that will work both in the browser as well as for node JS driven unit tests.
+- **For JavaScript:** There is no webpack/bundler step for release; browser JS is written in compatible ES6+ syntax, except in `legacy.js` (which must be designed to run cleanly even on ancient IE4 or Netscape to display the error message that a browser upgrade is necessary). We dropped use of jQuery. We are considering modularizing the JS logic, but need to ensure to do so in a way that will work both in the browser as well as for node JS driven unit tests.
 
 
 ### Run
 ### Run
 
 

+ 1 - 1
.jshintrc

@@ -19,7 +19,7 @@
     "strict": true,
     "strict": true,
     "undef": true,
     "undef": true,
     "unused": true,
     "unused": true,
-    "jquery": true,
+    "jquery": false,
     "browser": true,
     "browser": true,
     "predef": {
     "predef": {
       "after": true,
       "after": true,

+ 0 - 2
js/.istanbul.yml

@@ -1,7 +1,5 @@
 ---
 ---
 instrumentation:
 instrumentation:
-  excludes:
-    - jquery-3.7.1.js
   baseline-file: ../tst/log/js-coverage-baseline.json
   baseline-file: ../tst/log/js-coverage-baseline.json
 reporting:
 reporting:
   dir: ../tst/log/js-coverage-report
   dir: ../tst/log/js-coverage-report

+ 0 - 1
js/common.js

@@ -26,7 +26,6 @@ global.fs = require('fs');
 global.WebCrypto = require('@peculiar/webcrypto').Crypto;
 global.WebCrypto = require('@peculiar/webcrypto').Crypto;
 
 
 // application libraries to test
 // application libraries to test
-global.$ = global.jQuery = require('./jquery-3.7.1');
 global.zlib = require('./zlib').zlib;
 global.zlib = require('./zlib').zlib;
 require('./prettify');
 require('./prettify');
 global.prettyPrint = window.PR ? window.PR.prettyPrint : function() {};
 global.prettyPrint = window.PR ? window.PR.prettyPrint : function() {};

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 1
js/jquery-3.7.1.js


+ 8 - 9
js/legacy.js

@@ -13,7 +13,6 @@
 /**
 /**
  * IMPORTANT NOTICE FOR DEVELOPERS:
  * IMPORTANT NOTICE FOR DEVELOPERS:
  * The logic in this file is intended to run in legacy browsers. Avoid any use of:
  * The logic in this file is intended to run in legacy browsers. Avoid any use of:
- * - jQuery (doesn't work in older browsers)
  * - ES5 or newer in general
  * - ES5 or newer in general
  * - const/let, use the traditional var declarations instead
  * - const/let, use the traditional var declarations instead
  * - async/await or Promises, use traditional callbacks
  * - async/await or Promises, use traditional callbacks
@@ -68,26 +67,26 @@
             'Spider',
             'Spider',
             'scraper',
             'scraper',
             'Scraper',
             'Scraper',
-            
+
             // Search Engines
             // Search Engines
             'Mediapartners-Google',
             'Mediapartners-Google',
             'BingPreview',
             'BingPreview',
             'Yahoo! Slurp',
             'Yahoo! Slurp',
-            
+
             // SEO & Analytics
             // SEO & Analytics
             'Screaming Frog',
             'Screaming Frog',
-            
+
             // Social Media
             // Social Media
             'facebookexternalhit',
             'facebookexternalhit',
-            
+
             // AI & LLM
             // AI & LLM
             'ChatGPT-User',
             'ChatGPT-User',
             'anthropic-ai',
             'anthropic-ai',
-            
+
             // Security Scanners
             // Security Scanners
             'CensysInspect',
             'CensysInspect',
             'Shodan',
             'Shodan',
-            
+
             // Other Common Crawlers
             // Other Common Crawlers
             '80legs',
             '80legs',
             'ia_archiver',
             'ia_archiver',
@@ -171,7 +170,7 @@
          * @private
          * @private
          * @name   Check.isBadBot
          * @name   Check.isBadBot
          * @function
          * @function
-         * @return {bool}
+         * @return {Boolean}
          */
          */
         function isBadBot() {
         function isBadBot() {
             // check whether a bot user agent part can be found in the current
             // check whether a bot user agent part can be found in the current
@@ -262,7 +261,7 @@
          *
          *
          * @name   Check.getStatus
          * @name   Check.getStatus
          * @function
          * @function
-         * @return {bool}
+         * @return {Boolean}
          */
          */
         me.getStatus = function()
         me.getStatus = function()
         {
         {

+ 15 - 17
js/privatebin.js

@@ -397,7 +397,6 @@ window.PrivateBin = (function () {
         /**
         /**
          * text range selection
          * text range selection
          *
          *
-         * @see    {@link https://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse}
          * @name   Helper.selectText
          * @name   Helper.selectText
          * @function
          * @function
          * @param  {HTMLElement} element
          * @param  {HTMLElement} element
@@ -405,13 +404,12 @@ window.PrivateBin = (function () {
         me.selectText = function (element) {
         me.selectText = function (element) {
             let range, selection;
             let range, selection;
 
 
-            // MS
-            if (document.body.createTextRange) {
-                range = document.body.createTextRange();
-                range.moveToElementText(element);
-                range.select();
-            } else if (window.getSelection) {
+            if (window.getSelection) {
                 selection = window.getSelection();
                 selection = window.getSelection();
+                if (!selection) {
+                    console.warn('window.getSelection() returned null, could not get any select text');
+                    return;
+                }
                 range = document.createRange();
                 range = document.createRange();
                 range.selectNodeContents(element);
                 range.selectNodeContents(element);
                 selection.removeAllRanges();
                 selection.removeAllRanges();
@@ -1875,7 +1873,7 @@ window.PrivateBin = (function () {
          * alertType (see array), $element, args, icon
          * alertType (see array), $element, args, icon
          * If it returns true, the own processing will be stopped so the message
          * If it returns true, the own processing will be stopped so the message
          * will not be displayed. Otherwise it will continue.
          * will not be displayed. Otherwise it will continue.
-         * As an aditional feature it can return q jQuery element, which will
+         * As an aditional feature it can return a HTMLElement, which will
          * then be used to add the message there. Icons are not supported in
          * then be used to add the message there. Icons are not supported in
          * that case and will be ignored.
          * that case and will be ignored.
          * Pass 'null' to reset/delete the custom handler.
          * Pass 'null' to reset/delete the custom handler.
@@ -1893,7 +1891,7 @@ window.PrivateBin = (function () {
         /**
         /**
          * init status manager
          * init status manager
          *
          *
-         * preloads jQuery elements
+         * preloads HTMLElements
          *
          *
          * @name   Alert.init
          * @name   Alert.init
          * @function
          * @function
@@ -2141,7 +2139,7 @@ window.PrivateBin = (function () {
         /**
         /**
          * init status manager
          * init status manager
          *
          *
-         * preloads jQuery elements
+         * preloads HTMLElements
          *
          *
          * @name   PasteStatus.init
          * @name   PasteStatus.init
          * @function
          * @function
@@ -2280,7 +2278,7 @@ window.PrivateBin = (function () {
         /**
         /**
          * init status manager
          * init status manager
          *
          *
-         * preloads jQuery elements
+         * preloads HTMLElements
          *
          *
          * @name   Prompt.init
          * @name   Prompt.init
          * @function
          * @function
@@ -2345,8 +2343,8 @@ window.PrivateBin = (function () {
          *
          *
          * @name   Editor.supportTabs
          * @name   Editor.supportTabs
          * @function
          * @function
-         * @param  {Event} event
-         * @this $message (but not used, so it is jQuery-free, possibly faster)
+         * @param  {KeyboardEvent} event
+         * @this message
          */
          */
         function supportTabs(event) {
         function supportTabs(event) {
             // support disabling tab support using [Esc] and [Ctrl]+[m]
             // support disabling tab support using [Esc] and [Ctrl]+[m]
@@ -2547,7 +2545,7 @@ window.PrivateBin = (function () {
         /**
         /**
          * init editor
          * init editor
          *
          *
-         * preloads jQuery elements
+         * preloads HTMLElements and binds events
          *
          *
          * @name   Editor.init
          * @name   Editor.init
          * @function
          * @function
@@ -3372,7 +3370,7 @@ window.PrivateBin = (function () {
         /**
         /**
          * initiate
          * initiate
          *
          *
-         * preloads jQuery elements
+         * preloads HTMLElements
          *
          *
          * @name   AttachmentViewer.init
          * @name   AttachmentViewer.init
          * @function
          * @function
@@ -3484,7 +3482,7 @@ window.PrivateBin = (function () {
          * @name   DiscussionViewer.handleNotification
          * @name   DiscussionViewer.handleNotification
          * @function
          * @function
          * @param  {string} alertType
          * @param  {string} alertType
-         * @return {bool|jQuery}
+         * @return {Boolean|HTMLElement}
          */
          */
         me.handleNotification = function (alertType) {
         me.handleNotification = function (alertType) {
             // ignore loading messages
             // ignore loading messages
@@ -3712,7 +3710,7 @@ window.PrivateBin = (function () {
         /**
         /**
          * initiate
          * initiate
          *
          *
-         * preloads jQuery elements
+         * preloads HTML elements
          *
          *
          * @name   DiscussionViewer.init
          * @name   DiscussionViewer.init
          * @function
          * @function

+ 2 - 3
lib/Configuration.php

@@ -118,11 +118,10 @@ class Configuration
             'js/bootstrap-3.4.1.js'  => 'sha512-oBTprMeNEKCnqfuqKd6sbvFzmFQtlXS3e0C/RGFV0hD6QzhHV+ODfaQbAlmY6/q0ubbwlAM/nCJjkrgA3waLzg==',
             'js/bootstrap-3.4.1.js'  => 'sha512-oBTprMeNEKCnqfuqKd6sbvFzmFQtlXS3e0C/RGFV0hD6QzhHV+ODfaQbAlmY6/q0ubbwlAM/nCJjkrgA3waLzg==',
             'js/bootstrap-5.3.8.js'  => 'sha512-BkZvJ5rZ3zbDCod5seWHpRGg+PRd6ZgE8Nua/OMtcxqm8Wtg0PqwhUUXK5bqvl3oclMt5O+3zjRVX0L+L2j7fA==',
             'js/bootstrap-5.3.8.js'  => 'sha512-BkZvJ5rZ3zbDCod5seWHpRGg+PRd6ZgE8Nua/OMtcxqm8Wtg0PqwhUUXK5bqvl3oclMt5O+3zjRVX0L+L2j7fA==',
             'js/dark-mode-switch.js' => 'sha512-BhY7dNU14aDN5L+muoUmA66x0CkYUWkQT0nxhKBLP/o2d7jE025+dvWJa4OiYffBGEFgmhrD/Sp+QMkxGMTz2g==',
             'js/dark-mode-switch.js' => 'sha512-BhY7dNU14aDN5L+muoUmA66x0CkYUWkQT0nxhKBLP/o2d7jE025+dvWJa4OiYffBGEFgmhrD/Sp+QMkxGMTz2g==',
-            'js/jquery-3.7.1.js'     => 'sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==',
             'js/kjua-0.10.0.js'      => 'sha512-BYj4xggowR7QD150VLSTRlzH62YPfhpIM+b/1EUEr7RQpdWAGKulxWnOvjFx1FUlba4m6ihpNYuQab51H6XlYg==',
             'js/kjua-0.10.0.js'      => 'sha512-BYj4xggowR7QD150VLSTRlzH62YPfhpIM+b/1EUEr7RQpdWAGKulxWnOvjFx1FUlba4m6ihpNYuQab51H6XlYg==',
-            'js/legacy.js'           => 'sha512-RQEo1hxpNc37i+jz/D9/JiAZhG8GFx3+SNxjYnI7jUgirDIqrCSj6QPAAZeaidditcWzsJ3jxfEj5lVm7ZwTRQ==',
+            'js/legacy.js'           => 'sha512-pRofxsrf5UItjiP22Dcjh3FAcBjF/n7h8U9/W5xqJk17U0N2U1oajhXypq/omo9jhwS1iVGOhWrRepoPeFns+w==',
             'js/prettify.js'         => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==',
             'js/prettify.js'         => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==',
-            'js/privatebin.js'       => 'sha512-6PFjuvKnCOL4WSvbMyTdXlxGqnX9uaeG9aLktkvvrTmtwAn3eOvASE4DkJbQHe12gyrjy1okRwuIgjXRavxkqA==',
+            'js/privatebin.js'       => 'sha512-t6/mD1j71AXFsvNABUyVrYDKWhBoyaBTZqcnwMEgSQ+qqpbbqYjqsklgPhUbsXBTEjdYsIBAG2asiIPpQ94F0A==',
             'js/purify-3.4.1.js'     => 'sha512-280a/Vb6fVFsYaeRrkuDp4EDmdYlt2XS+dlDEO/U9qljPrAraA2bIzHTNmP+9dpwPDDwTML+RS+h5iaagPwTzA==',
             'js/purify-3.4.1.js'     => 'sha512-280a/Vb6fVFsYaeRrkuDp4EDmdYlt2XS+dlDEO/U9qljPrAraA2bIzHTNmP+9dpwPDDwTML+RS+h5iaagPwTzA==',
             'js/showdown-2.1.0.js'   => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',
             'js/showdown-2.1.0.js'   => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',
             'js/zlib-1.3.2.js'       => 'sha512-RAhJgxg9siMIA8ky4c10Rc2zUgnK80olHB8Tt1IOYWY4Eh1WmrviQkDn+sgBlb38ZHq3tzufGC41kP360gmosQ==',
             'js/zlib-1.3.2.js'       => 'sha512-RAhJgxg9siMIA8ky4c10Rc2zUgnK80olHB8Tt1IOYWY4Eh1WmrviQkDn+sgBlb38ZHq3tzufGC41kP360gmosQ==',

Vissa filer visades inte eftersom för många filer har ändrats