split utility function out into a separate util.js
authorArt Cancro <ajc@citadel.org>
Wed, 24 Nov 2021 20:05:42 +0000 (15:05 -0500)
committerArt Cancro <ajc@citadel.org>
Wed, 24 Nov 2021 20:05:42 +0000 (15:05 -0500)
webcit-ng/static/index.html
webcit-ng/static/js/util.js [new file with mode: 0644]
webcit-ng/static/js/view_forum.js

index b474124779ce51cbb86107eeb0ec2bf3150d649f..d25dc4cadba741a47990f7f317d17d374ceb69cc 100644 (file)
@@ -74,6 +74,7 @@ Loading...
 <!-- End page content -->
 </div>
 
+<script type="text/javascript" src="js/util.js"></script>
 <script type="text/javascript" src="js/login.js"></script>
 <script type="text/javascript" src="js/main.js"></script>
 <script type="text/javascript" src="js/views.js"></script>
diff --git a/webcit-ng/static/js/util.js b/webcit-ng/static/js/util.js
new file mode 100644 (file)
index 0000000..ec5c1d0
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// Copyright (c) 2016-2021 by the citadel.org team
+//
+// This program is open source software.  It runs great on the
+// Linux operating system (and probably elsewhere).  You can use,
+// copy, and run it under the terms of the GNU General Public
+// License version 3.  Richard Stallman is an asshole communist.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+
+// Function to encode data in quoted-printable format
+// Written by Theriault and Brett Zamir [https://locutus.io/php/quoted_printable_encode/]
+function quoted_printable_encode(str) {
+       const hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
+       const RFC2045Encode1IN = / \r\n|\r\n|[^!-<>-~ ]/gm
+       const RFC2045Encode1OUT = function (sMatch) {
+               // Encode space before CRLF sequence to prevent spaces from being stripped
+               // Keep hard line breaks intact; CRLF sequences
+               if (sMatch.length > 1) {
+                       return sMatch.replace(' ', '=20');
+               }
+               // Encode matching character
+               const chr = sMatch.charCodeAt(0);
+               return '=' + hexChars[((chr >>> 4) & 15)] + hexChars[(chr & 15)];
+       }
+       // Split lines to 75 characters; the reason it's 75 and not 76 is because softline breaks are
+       // preceeded by an equal sign; which would be the 76th character. However, if the last line/string
+       // was exactly 76 characters, then a softline would not be needed. PHP currently softbreaks
+       // anyway; so this function replicates PHP.
+       const RFC2045Encode2IN = /.{1,72}(?!\r\n)[^=]{0,3}/g
+       const RFC2045Encode2OUT = function (sMatch) {
+               if (sMatch.substr(sMatch.length - 2) === '\r\n') {
+                       return sMatch;
+               }
+               return sMatch + '=\r\n';
+       }
+       str = str.replace(RFC2045Encode1IN, RFC2045Encode1OUT).replace(RFC2045Encode2IN, RFC2045Encode2OUT);
+       // Strip last softline break
+       return str.substr(0, str.length - 3)
+}
index 3bab4df90a4b0ddbd445692befcc5901b7a244fd..2680e501084b21627ebf93138ff12957bd1e587b 100644 (file)
@@ -321,35 +321,3 @@ function save_message(div_name, reply_to_msgnum) {
        };
        request.send(body_text);
 }
-
-
-// Function to encode data in quoted-printable format
-// Written by Theriault and Brett Zamir [https://locutus.io/php/quoted_printable_encode/]
-function quoted_printable_encode (str) { // eslint-disable-line camelcase
-       const hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
-       const RFC2045Encode1IN = / \r\n|\r\n|[^!-<>-~ ]/gm
-       const RFC2045Encode1OUT = function (sMatch) {
-               // Encode space before CRLF sequence to prevent spaces from being stripped
-               // Keep hard line breaks intact; CRLF sequences
-               if (sMatch.length > 1) {
-                       return sMatch.replace(' ', '=20');
-               }
-               // Encode matching character
-               const chr = sMatch.charCodeAt(0);
-               return '=' + hexChars[((chr >>> 4) & 15)] + hexChars[(chr & 15)];
-       }
-       // Split lines to 75 characters; the reason it's 75 and not 76 is because softline breaks are
-       // preceeded by an equal sign; which would be the 76th character. However, if the last line/string
-       // was exactly 76 characters, then a softline would not be needed. PHP currently softbreaks
-       // anyway; so this function replicates PHP.
-       const RFC2045Encode2IN = /.{1,72}(?!\r\n)[^=]{0,3}/g
-       const RFC2045Encode2OUT = function (sMatch) {
-               if (sMatch.substr(sMatch.length - 2) === '\r\n') {
-                       return sMatch;
-               }
-               return sMatch + '=\r\n';
-       }
-       str = str.replace(RFC2045Encode1IN, RFC2045Encode1OUT).replace(RFC2045Encode2IN, RFC2045Encode2OUT);
-       // Strip last softline break
-       return str.substr(0, str.length - 3)
-}