From 633ff601e557a06212daf81d3e3dad3a00170e31 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 14 May 2022 00:13:06 +0200 Subject: [PATCH] perf + ux --- copyparty/web/browser.css | 1 + copyparty/web/browser.js | 63 +++++++++++---------------------------- copyparty/web/md2.js | 15 ++-------- copyparty/web/mde.js | 10 ++----- copyparty/web/util.js | 2 +- 5 files changed, 25 insertions(+), 66 deletions(-) diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index 5cd0e8ff..af8ec40b 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -260,6 +260,7 @@ html.bz { --btn-1-bg: #ba2959; --btn-1-fg: #fff; --btn-1h-fg: #000; + --txt-sh: a; --u2-tab-1-fg: var(--fg-max); --u2-tab-1-bg: var(--bg); diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 3311cb5e..347768a3 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -1589,8 +1589,8 @@ function evau_error(e) { // chromish for 40x var xhr = new XHR(); xhr.open('HEAD', eplaya.src, true); - xhr.onreadystatechange = function () { - if (this.readyState != XHR.DONE || this.status < 400) + xhr.onload = xhr.onerror = function () { + if (this.status < 400) return; err = this.status == 403 ? e403 : this.status == 404 ? e404 : @@ -2179,9 +2179,6 @@ var fileman = (function () { var dst = base + uricom_enc(f[0].inew.value, false); function rename_cb() { - if (this.readyState != XHR.DONE) - return; - if (this.status !== 200) { var msg = this.responseText; toast.err(9, 'rename failed:\n' + msg); @@ -2194,7 +2191,7 @@ var fileman = (function () { var xhr = new XHR(); xhr.open('GET', f[0].src + '?move=' + dst, true); - xhr.onreadystatechange = rename_cb; + xhr.onload = xhr.onerror = rename_cb; xhr.send(); } }; @@ -2225,13 +2222,10 @@ var fileman = (function () { toast.inf(0, esc('deleting ' + (vps.length + 1) + ' items\n\n' + vp)); xhr.open('GET', vp + '?delete', true); - xhr.onreadystatechange = delete_cb; + xhr.onload = xhr.onerror = delete_cb; xhr.send(); } function delete_cb() { - if (this.readyState != XHR.DONE) - return; - if (this.status !== 200) { var msg = this.responseText; toast.err(9, 'delete failed:\n' + msg); @@ -2336,13 +2330,10 @@ var fileman = (function () { var dst = get_evpath() + vp.split('/').pop(); xhr.open('GET', vp + '?move=' + dst, true); - xhr.onreadystatechange = paste_cb; + xhr.onload = xhr.onerror = paste_cb; xhr.send(); } function paste_cb() { - if (this.readyState != XHR.DONE) - return; - if (this.status !== 200) { var msg = this.responseText; toast.err(9, 'paste failed:\n' + msg); @@ -2508,7 +2499,7 @@ var showfile = (function () { xhr.ts = Date.now(); xhr.open('GET', url.split('?')[0] + '?raw', true); xhr.onprogress = loading; - xhr.onloadend = load_cb; + xhr.onload = xhr.onerror = load_cb; xhr.send(); }; @@ -2774,7 +2765,7 @@ var thegrid = (function () { if (l) return setln(parseInt(l)); - var t = lfiles.tHead.rows[0].cells; + var t = ebi('files').tHead.rows[0].cells; for (var a = 0; a < t.length; a++) if (t[a].getAttribute('name') == s) { t[a].click(); @@ -2797,6 +2788,9 @@ var thegrid = (function () { wintitle(); } + lfiles = ebi('files'); + gfiles = ebi('gfiles'); + var vis = has(perms, "read"); gfiles.style.display = vis && r.en ? '' : 'none'; lfiles.style.display = vis && !r.en ? '' : 'none'; @@ -3522,16 +3516,13 @@ document.onkeydown = function (e) { var xhr = new XHR(); xhr.open('POST', '/?srch', true); xhr.setRequestHeader('Content-Type', 'text/plain'); - xhr.onreadystatechange = xhr_search_results; + xhr.onload = xhr.onerror = xhr_search_results; xhr.ts = Date.now(); xhr.q_raw = ebi('q_raw').value; xhr.send(JSON.stringify({ "q": xhr.q_raw, "n": cap })); } function xhr_search_results() { - if (this.readyState != XHR.DONE) - return; - if (this.status !== 200) { var msg = this.responseText; if (msg.indexOf('
') === 0)
@@ -3862,15 +3853,12 @@ var treectl = (function () {
 		xhr.rst = rst;
 		xhr.ts = Date.now();
 		xhr.open('GET', dst + '?tree=' + top + (r.dots ? '&dots' : ''), true);
-		xhr.onreadystatechange = recvtree;
+		xhr.onload = xhr.onerror = recvtree;
 		xhr.send();
 		enspin('#tree');
 	}
 
 	function recvtree() {
-		if (this.readyState != XHR.DONE)
-			return;
-
 		if (!xhrchk(this, "could not list subfolders:\n\nerror ", "404, folder not found"))
 			return;
 
@@ -4030,7 +4018,7 @@ var treectl = (function () {
 		xhr.hpush = hpush;
 		xhr.ts = Date.now();
 		xhr.open('GET', xhr.top + '?ls' + (r.dots ? '&dots' : ''), true);
-		xhr.onreadystatechange = recvls;
+		xhr.onload = xhr.onerror = recvls;
 		xhr.send();
 		if (hpush && !no_tree)
 			get_tree('.', xhr.top);
@@ -4054,9 +4042,6 @@ var treectl = (function () {
 	}
 
 	function recvls() {
-		if (this.readyState != XHR.DONE)
-			return;
-
 		if (!xhrchk(this, "could not list files in folder:\n\nerror ", "404, folder not found"))
 			return;
 
@@ -4703,7 +4688,7 @@ var settheme = (function () {
 		showfile.setstyle();
 
 		var html = [], itheme = ax.indexOf(theme.charAt(0)) * 2 + (light ? 1 : 0),
-			names = ['classic dark', 'classic light', 'flat dark', 'flat light', 'vice', 'hotdog stand'];
+			names = ['classic dark', 'classic light', 'pm-monokai', 'flat light', 'vice', 'hotdog stand'];
 
 		for (var a = 0; a < themes; a++)
 			html.push('/, ""));
 
@@ -400,7 +394,7 @@ function run_savechk(lastmod, txt, btn, ntry) {
     var xhr = new XHR();
     xhr.open('GET', url, true);
     xhr.responseType = 'text';
-    xhr.onreadystatechange = savechk_cb;
+    xhr.onload = xhr.onerror = savechk_cb;
     xhr.lastmod = lastmod;
     xhr.txt = txt;
     xhr.btn = btn;
@@ -409,9 +403,6 @@ function run_savechk(lastmod, txt, btn, ntry) {
 }
 
 function savechk_cb() {
-    if (this.readyState != XHR.DONE)
-        return;
-
     if (this.status !== 200)
         return toast.err(0, 'Error!  The file was NOT saved.\n\n' + this.status + ": " + (this.responseText + '').replace(/^
/, ""));
 
diff --git a/copyparty/web/mde.js b/copyparty/web/mde.js
index e81a98c1..bb70cacb 100644
--- a/copyparty/web/mde.js
+++ b/copyparty/web/mde.js
@@ -117,7 +117,7 @@ function save(mde) {
         var xhr = new XHR();
         xhr.open('POST', url, true);
         xhr.responseType = 'text';
-        xhr.onreadystatechange = save_cb;
+        xhr.onload = xhr.onerror = save_cb;
         xhr.btn = save_btn;
         xhr.mde = mde;
         xhr.txt = txt;
@@ -133,9 +133,6 @@ function save(mde) {
 }
 
 function save_cb() {
-    if (this.readyState != XHR.DONE)
-        return;
-
     if (this.status !== 200)
         return toast.err(0, 'Error!  The file was NOT saved.\n\n' + this.status + ": " + (this.responseText + '').replace(/^
/, ""));
 
@@ -173,7 +170,7 @@ function save_cb() {
     var xhr = new XHR();
     xhr.open('GET', url, true);
     xhr.responseType = 'text';
-    xhr.onreadystatechange = save_chk;
+    xhr.onload = xhr.onerror = save_chk;
     xhr.btn = this.save_btn;
     xhr.mde = this.mde;
     xhr.txt = this.txt;
@@ -182,9 +179,6 @@ function save_cb() {
 }
 
 function save_chk() {
-    if (this.readyState != XHR.DONE)
-        return;
-
     if (this.status !== 200)
         return toast.err(0, 'Error!  The file was NOT saved.\n\n' + this.status + ": " + (this.responseText + '').replace(/^
/, ""));
 
diff --git a/copyparty/web/util.js b/copyparty/web/util.js
index 799f7ffc..5d4e616f 100644
--- a/copyparty/web/util.js
+++ b/copyparty/web/util.js
@@ -316,7 +316,7 @@ function clmod(el, cls, add) {
 
     var n2 = n1.replace(re, ' ') + (add ? ' ' + cls : '');
 
-    if (!n1 == !n2)
+    if (n1 == n2)
         return false;
 
     el.className = n2;