]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/static/js/util.js
Major change to the javascript forum view. We now wait for all messages to be loaded...
[citadel.git] / webcit-ng / static / js / util.js
index ec5c1d062729fcdbbe8c8fcc14686a47c36f0fe7..eba84e238fa4d819acce6a4c98ca684ffd0effed 100644 (file)
@@ -42,3 +42,52 @@ function quoted_printable_encode(str) {
        // Strip last softline break
        return str.substr(0, str.length - 3)
 }
+
+
+// Generate a random string of the specified length
+// Useful for generating one-time-use div names
+function randomString(length) {
+       var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghiklmnopqrstuvwxyz'.split('');
+       var str = '';
+
+       if (!length) {
+               length = Math.floor(Math.random() * chars.length);
+       }
+       for (var i = 0; i < length; i++) {
+               str += chars[Math.floor(Math.random() * chars.length)];
+       }
+       return str;
+}
+
+
+// string escape for html display
+function escapeHTML(text) {
+       'use strict';
+       return text.replace(/[\"&<>]/g, function (a) {
+               return {
+                       '"': '&quot;',
+                       '&': '&amp;',
+                       '<': '&lt;',
+                       '>': '&gt;'
+               }[a];
+       });
+}
+
+
+// string escape for html display
+function escapeHTMLURI(text) {
+       'use strict';
+       return text.replace(/./g, function (a) {
+               return '%' + a.charCodeAt(0).toString(16);
+       });
+}
+
+
+// string escape for JavaScript string
+//
+function escapeJS(text) {
+       'use strict';
+       return text.replace(/[\"\']/g, function (a) {
+               return '\\' + a ;
+       });
+}