From 346ed469c82355a97609a2eba173b2ba8450a1c7 Mon Sep 17 00:00:00 2001 From: df Date: Thu, 4 Mar 2021 15:08:15 +0000 Subject: [PATCH] Make use of unique element IDs for img consistent --- CONTROL/control | 2 +- webif/html/browse/script.js | 42 ++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/CONTROL/control b/CONTROL/control index f82741c..852869c 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,7 +1,7 @@ Package: webif Priority: optional Section: web -Version: 1.4.9-2 +Version: 1.4.9-3 Architecture: mipsel Maintainer: af123@hpkg.tv Depends: tcpfix,webif-channelicons(>=1.1.27),lighttpd(>=1.4.39-1),jim(>=0.79),jim-pack(>=0.79),jim-oo(>=0.77),jim-sqlite3(>=0.77),jim-cgi(>=0.7-2),jim-binary(>=0.76),service-control(>=2.3),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.2.8),hmt(>=2.0.10),ssmtp,cron-daemon(>=1.18.3-3),at(>=3.1.18),anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.1.13),webif-charts(>=1.2-1),stripts(>=1.4.2),tmenu(>=1.21-2),ffmpeg(>=2.8),id3v2,multienv(>=1.6),tcpping(>=1.1),e2fsprogs,wireless-tools(>=29-1),dbupdate,recmon(>=2.0.7),hwctl,nugget(>=0.98),sqlite3(>=3.15.1),jim-xconv,zip(>=3.0-1),wget diff --git a/webif/html/browse/script.js b/webif/html/browse/script.js index d0548be..5269fa0 100755 --- a/webif/html/browse/script.js +++ b/webif/html/browse/script.js @@ -10,6 +10,18 @@ var plugins = { dmenu_prepare: {} }; +// pattern matches directory path prefix +var pathre = /.*\/|\.[^.]*$/g; + +// IDs of size, img elements for folders use RFC4648 s5 encoding of name +function folderID(folder) +{ + return btoa(escape(folder)) + .replace(/\+/g, '-') + .replace(/\//g, '_') + .replace(/=/g, ''); +} + function blockpage(msg) { if (!msg) @@ -115,21 +127,11 @@ function epginfo_callback(data, status, xhr) function insert_folder_size(folder, size) { // folder = folder.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1'); - // ID of size element is ID + RFC4648 s5 encoding of folder name - folder = "ID" + - btoa(escape(folder)) - .replace(/\+/g, '-') - .replace(/\//g, '_') - .replace(/=/g, ''); + size += (size.search(/\d$/) == -1 ? 'iB' : ' bytes'); + folder = folderID(folder); //console.log("Folder: (%s) = (%s)", folder, size); - if (size.search(/\d$/) == -1) - size += 'iB'; - else - size += ' bytes'; - if (folder == "") - $('#dirsize').text(' (' + size + ')'); - else - $('#' + folder).text(' (' + size + ')'); + $(folder == "" ? '#dirsize' : '#ID' + folder) + .text(' (' + size + ')'); } function folder_size_callback(data, status, xhr) @@ -141,11 +143,9 @@ function folder_size_callback(data, status, xhr) function set_folder_new(folder, cnt) { - folder = folder.replace(/ /g, ''); - folder = folder.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1'); //console.log("Folder: (%s) = (%s)", folder, cnt); left = cnt > 99 ? 11 : (cnt > 9 ? 14 : 17); - $('#img' + folder) + $('#img' + folderID(folder)) .attr('src', '/img/Folder_New.png') .next('span.foldernum') .css('left', left + 'px') @@ -164,10 +164,8 @@ function new_folder_callback(data, status, xhr) function set_folder__(folder) { - folder = folder.replace(/ /g, ''); - folder = folder.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1'); //console.log("Folder: (%s)", folder); - $('#img' + folder + ' ~ span.folderu').show(); + $('#img' + folderID(folder) + ' ~ span.folderu').show(); } function __folder_callback(data, status, xhr) @@ -264,7 +262,7 @@ var $confirm; // Populated after DOM is loaded. function confirm_action(action, callback, file, type, id) { - var bfile = file.replace(/.*\/|\.[^.]*$/g, ''); + var bfile = file.replace(pathre, ''); $confirm.dialog('option', 'buttons', { 'Yes': function() { $(this).dialog('close'); callback(file, type, id); }, @@ -437,7 +435,7 @@ var menuclick = function(action, el, pos) { var file = $(el).parent().prevAll('a.bf').last().attr('file'); var efile = encodeURIComponent(file); - var bfile = file.replace(/.*\/|\.[^.]*$/g, ''); + var bfile = file.replace(pathre, ''); bfile = bfile.replace(/[\x00-\x1f]+/g, ''); var type = $(el).attr('type'); var id = $(el).attr('did');