From feba4de1d60886850bfed365d498a5078f55efa7 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 14 Apr 2022 17:12:56 +0200 Subject: [PATCH] make gallery linkable --- copyparty/web/baguettebox.js | 1 + copyparty/web/browser.html | 1 + copyparty/web/browser.js | 119 +++++++++++++++++++++++++---------- 3 files changed, 89 insertions(+), 32 deletions(-) diff --git a/copyparty/web/baguettebox.js b/copyparty/web/baguettebox.js index 25be1e1a..d70958dd 100644 --- a/copyparty/web/baguettebox.js +++ b/copyparty/web/baguettebox.js @@ -539,6 +539,7 @@ window.baguetteBox = (function () { if (overlay.style.display === 'none') return; + sethash(''); unbind(document, 'keydown', keyDownHandler); unbind(document, 'keyup', keyUpHandler); unbind(document, 'fullscreenchange', onFSC); diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index e81fc54a..c036f670 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -153,6 +153,7 @@ document.documentElement.setAttribute("class", localStorage.theme || dtheme); + {%- if js %} diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 794897db..db357459 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -58,7 +58,7 @@ ebi('op_up2k').innerHTML = ( '
parallel uploads:\n' + ' \n' + ' \n' + - ' \n' + + ' \n' + ' \n' + ' \n' + ' \n' + @@ -74,7 +74,7 @@ ebi('op_up2k').innerHTML = ( ' \n' + ' \n' + ' +
 \n' + ' \n' + ' \n' + @@ -1593,25 +1593,62 @@ function autoplay_blocked(seek) { } +function scan_hash(v) { + if (!v) + return null; + + var m = /^#([ag])(f-[0-9a-f]{8,16})(&.+)?/.exec(v + ''); + if (!m) + return null; + + var mtype = m[1], + id = m[2], + ts = null; + + if (m.length > 3) { + m = /^&[Tt=0]*([0-9]+[Mm:])?0*([0-9]+)[Ss]?$/.exec(m[3]); + if (m) { + ts = parseInt(m[1] || 0) * 60 + parseInt(m[2] || 0); + } + } + + return [mtype, id, ts]; +} + + function eval_hash() { var v = hash0; hash0 = null; if (!v) return; - if (v.indexOf('#af-') === 0) { - var id = v.slice(2).split('&'); - if (id[0].length < 10) - return; + var media = scan_hash(v); + if (media) { + var mtype = media[0], + id = media[1], + ts = media[2]; - if (id.length == 1) - return play(id[0]); + if (mtype == 'a') { + if (!ts) + return play(id); - var m = /^[Tt=0]*([0-9]+[Mm:])?0*([0-9]+)[Ss]?$/.exec(id[1]); - if (!m) - return play(id[0]); + return play(id, false, ts); + } - return play(id[0], false, parseInt(m[1] || 0) * 60 + parseInt(m[2] || 0)); + if (mtype == 'g') { + if (!thegrid.en) + ebi('griden').click(); + + var t = setInterval(function () { + if (!thegrid.bbox) + return; + + clearInterval(t); + var im = QS('#ggrid a[ref="' + id + '"]'); + im.click(); + im.scrollIntoView(); + }, 50); + } } if (v.indexOf('#q=') === 0) { @@ -2950,6 +2987,9 @@ var thegrid = (function () { return '' + (idx + 1) + ' / ' + r.bbox.length + ' -- ' + esc(uricom_dec(h.split('/').pop())[0]) + ''; + }, + onChange: function (i) { + sethash('g' + r.bbox[i].imageElement.getAttribute('ref')); } })[0]; }; @@ -2963,10 +3003,6 @@ var thegrid = (function () { }); ebi('wtgrid').onclick = ebi('griden').onclick; - setTimeout(function () { - import_js('/.cpr/baguettebox.js', r.bagit); - }, 1); - return r; })(); @@ -4045,18 +4081,38 @@ var treectl = (function () { html = html.join('\n'); set_files_html(html); - filecols.set_style(); - showfile.mktree(); - mukey.render(); - reload_tree(); - reload_browser(); - tree_scrollto(); - if (res.acct) { - acct = res.acct; - have_up2k_idx = res.idx; - apply_perms(res.perms); - fileman.render(); + function asdf() { + filecols.set_style(); + showfile.mktree(); + mukey.render(); + reload_tree(); + reload_browser(); + tree_scrollto(); + if (res.acct) { + acct = res.acct; + have_up2k_idx = res.idx; + apply_perms(res.perms); + fileman.render(); + } } + + var m = scan_hash(hash0), + url = null; + + if (m) { + url = ebi(m[1]); + if (url) { + url = url.href; + var mt = m[0] == 'a' ? 'audio' : /\.(webm|mkv)($|\?)/i.exec(url) ? 'video' : 'image' + if (mt == 'image') { + url += url.indexOf('?') < 0 ? '?cache' : '&cache'; + console.log(url); + new Image().src = url; + } + } + } + + if (url) setTimeout(asdf, 1); else asdf(); } r.hydrate = function () { @@ -4069,12 +4125,9 @@ var treectl = (function () { } r.gentab(get_evpath(), ls0); - reload_browser(); pbar.onresize(); vbar.onresize(); - mukey.render(); showfile.addlinks(); - thegrid.setdirty(); setTimeout(eval_hash, 1); }; @@ -4173,14 +4226,16 @@ function apply_perms(newperms) { perms = newperms || []; var a = QS('#ops a[data-dest="up2k"]'); + var suf = 'multithreaded, and file timestamps are preserved, but it uses more CPU than the basic uploader'; if (have_up2k_idx) { a.removeAttribute('data-perm'); - a.setAttribute('tt', 'up2k: upload files (if you have write-access) or toggle into the search-mode to see if they exist somewhere on the server'); + a.setAttribute('tt', 'up2k: upload files (if you have write-access) or toggle into the search-mode to see if they exist somewhere on the server$N$Nuploads are resumable, ' + suf); } else { a.setAttribute('data-perm', 'write'); - a.setAttribute('tt', 'up2k: upload files with resume support (close your browser and drop the same files in later)'); + a.setAttribute('tt', 'up2k: upload files with resume support (close your browser and drop the same files in later)$N$N' + suf); } + a.style.display = ''; tt.att(QS('#ops')); var axs = [],