Skip to content

Commit 375b2d3

Browse files
committed
refactor: standardize DOM element dataset attributes across file browser component
Standardize DOM element attribute naming across the file browser component by converting legacy custom attributes to standard HTML5 `data-*` dataset attributes. Previously, template elements mixed standard properties with proprietary, non-standard DOM attributes (such as `action`, `type`, `name`, `home`, `open-doc`, `ftp-account`, `uuid`, and `storageType`). This led to non-compliant HTML markup, required explicit `getAttribute()` and `setAttribute()` DOM calls, and increased the risk of attribute collision with future web standards. This change enforces a uniform contract using the standard HTML5 `dataset` API (`data-*`), improving rendering consistency, type predictability, and JS-to-DOM binding efficiency. * **Template Refactoring (`src/pages/fileBrowser/list.hbs`):** * Converted legacy inline attributes to standard dataset equivalents: `data-action`, `data-type`, `data-name`, `data-home`, `data-open-doc`, `data-ftp-account`, `data-uuid`, and `data-storage-type`. * Ensured boolean and string dataset values comply with template engine rendering rules. * **Script Adaptations (`src/pages/fileBrowser/fileBrowser.js`):** * Refactored event delegation and element lookup handlers to utilize standard camelCase JavaScript `dataset` properties (e.g., replacing `el.getAttribute('open-doc')` with `el.dataset.openDoc`, along with `dataset.action`, `dataset.uuid`, `dataset.type`, and `dataset.storageType`). * Simplified property checks across list selection handlers and navigation logic. * **Stylesheet Selectors (`src/pages/fileBrowser/fileBrowser.scss`):** * Updated CSS attribute selectors from `[storageType="notification"]` to `[data-storage-type="notification"]` to maintain tight visual styling coupling without relying on invalid HTML attributes. (AI generated commit message)
1 parent b2eb8f5 commit 375b2d3

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

src/pages/fileBrowser/fileBrowser.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -929,16 +929,16 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
929929
return;
930930
}
931931

932-
let action = $el.getAttribute("action") || $el.dataset.action;
932+
let action = $el.dataset.action;
933933
if (!action) return;
934934

935935
let url = $el.dataset.url;
936-
let name = $el.dataset.name || $el.getAttribute("name");
937-
const idOpenDoc = $el.hasAttribute("open-doc");
938-
const uuid = $el.getAttribute("uuid");
939-
const type = $el.getAttribute("type");
940-
const storageType = $el.getAttribute("storageType");
941-
const home = $el.getAttribute("home");
936+
let name = $el.dataset.name;
937+
const isOpenDoc = $el.dataset.openDoc != null;
938+
const uuid = $el.dataset.uuid;
939+
const type = $el.dataset.type;
940+
const storageType = $el.dataset.storageType;
941+
const home = $el.dataset.home;
942942
const isDir = ["dir", "directory", "folder"].includes(type);
943943

944944
if (!url) {
@@ -960,7 +960,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
960960
return;
961961
}
962962

963-
if (!url && action === "open" && isDir && !idOpenDoc && !isContextMenu) {
963+
if (!url && action === "open" && isDir && !isOpenDoc && !isContextMenu) {
964964
loader.hide();
965965
util.addPath(name, uuid).then((res) => {
966966
const storage = allStorages.find((storage) => storage.uuid === uuid);
@@ -975,7 +975,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
975975
}
976976

977977
if (isContextMenu) action = "contextmenu";
978-
else if (idOpenDoc) action = "open-doc";
978+
else if (isOpenDoc) action = "openDoc";
979979

980980
switch (action) {
981981
case "navigation":
@@ -988,7 +988,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
988988
if (isDir) folder();
989989
else if (!$el.hasAttribute("disabled")) file();
990990
break;
991-
case "open-doc":
991+
case "openDoc":
992992
openDoc();
993993
break;
994994
}
@@ -1046,7 +1046,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
10461046
if (appSettings.value.vibrateOnTap) {
10471047
navigator.vibrate(config.VIBRATION_TIME);
10481048
}
1049-
if ($el.getAttribute("open-doc") === "true") return;
1049+
if (isOpenDoc) return;
10501050

10511051
const deleteText =
10521052
currentDir.url === "/" ? strings.remove : strings.delete;
@@ -1399,7 +1399,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
13991399

14001400
if (IS_FILE_MODE) {
14011401
util.pushFolder(allStorages, "Select document", null, {
1402-
"open-doc": true,
1402+
openDoc: true,
14031403
});
14041404
}
14051405

@@ -1646,7 +1646,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
16461646
className="nav"
16471647
data-url={url}
16481648
data-name={displayName}
1649-
attr-action="navigation"
1649+
data-action="navigation"
16501650
attr-text={displayName}
16511651
tabIndex={-1}
16521652
></span>,

src/pages/fileBrowser/fileBrowser.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
}
55

66
.tile {
7-
&[storageType="notification"] {
7+
&[data-storage-type="notification"] {
88
background-color: rgb(153, 153, 255);
99
background-color: var(--primary-color);
1010
color: rgb(255, 255, 255);
@@ -22,11 +22,11 @@
2222
position: relative;
2323
color: rgb(65, 85, 133);
2424

25-
&[storageType]::after {
25+
&[data-storage-type]::after {
2626
position: absolute;
2727
top: 50%;
2828
left: 50%;
29-
content: attr(storageType);
29+
content: attr(data-storage-type);
3030
transform: translate(-50%, -50%);
3131
color: rgb(255, 255, 255);
3232
font-size: 0.6rem;

src/pages/fileBrowser/list.hbs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
<li
44
tabindex="1"
55
class="tile {{#isLink}}symlink{{/isLink}}"
6-
action="open"
7-
type="{{type}}"
8-
name="{{name}}"
9-
{{#home}}home="{{.}}"{{/home}}
10-
{{#open-doc}}open-doc="true"{{/open-doc}}
11-
{{#ftp-account}}ftp-account{{/ftp-account}}
6+
data-action="open"
7+
data-type="{{type}}"
8+
data-name="{{name}}"
9+
{{#home}}data-home="{{.}}"{{/home}}
10+
{{#openDoc}}data-open-doc{{/openDoc}}
11+
{{#ftpAccount}}data-ftp-account{{/ftpAccount}}
12+
{{#uuid}}data-uuid="{{uuid}}"{{/uuid}}
13+
{{#storageType}}data-storage-type="{{.}}"{{/storageType}}
1214
{{#disabled}}disabled{{/disabled}}
13-
{{#uuid}}uuid="{{uuid}}"{{/uuid}}
14-
{{#storageType}}storageType="{{.}}"{{/storageType}}
1515
>
1616
<span
1717
class="icon {{icon}} {{#uuid}}user-added-storage{{/uuid}}"
18-
{{#storageType}}storageType="{{.}}"{{/storageType}}
18+
{{#storageType}}data-storage-type="{{.}}"{{/storageType}}
1919
></span>
2020

2121
<div class="text">

0 commit comments

Comments
 (0)