summaryrefslogtreecommitdiff
path: root/src/ui/ui.js
diff options
context:
space:
mode:
authorhackademix2018-07-11 00:53:25 +0200
committerhackademix2018-07-11 00:53:25 +0200
commit842caf73408a8bf678c0308a06fe56df4a7ecb3b (patch)
tree290188bfa50a836fe03101cc2974f44c2c48cc7f /src/ui/ui.js
parent74e20bb3ebe1bba03769ef65e442468ce54a2cc9 (diff)
downloadnoscript-842caf73408a8bf678c0308a06fe56df4a7ecb3b.tar.gz
noscript-842caf73408a8bf678c0308a06fe56df4a7ecb3b.tar.xz
noscript-842caf73408a8bf678c0308a06fe56df4a7ecb3b.zip
Made preset buttons automatically sized according to their (localized) content.
Diffstat (limited to 'src/ui/ui.js')
-rw-r--r--src/ui/ui.js37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/ui/ui.js b/src/ui/ui.js
index 99943d7..927a712 100644
--- a/src/ui/ui.js
+++ b/src/ui/ui.js
@@ -187,7 +187,7 @@ var UI = (() => {
initRow(table = this.table) {
let row = table.querySelector("tr.site");
-
+ debug("initRow: ", new Error().stack);
// PRESETS
{
let presets = row.querySelector(".presets");
@@ -212,7 +212,42 @@ var UI = (() => {
clone.querySelector(".options").remove();
}
presets.appendChild(clone);
+
}
+
+
+ if (!document.getElementById("presets-sizer")) {
+ // adapt button to label if needed
+ let sizer = table.cloneNode(true);
+ sizer.id = "presets-sizer";
+ document.body.appendChild(sizer);
+ let presetWidth = sizer.querySelector("input.preset").offsetWidth;
+ let labelWidth = 0;
+ for (let l of sizer.querySelectorAll("label.preset")) {
+ let lw = l.offsetWidth;
+ debug("lw", lw);
+ if (lw > labelWidth) labelWidth = lw;
+ }
+
+ debug(`Preset: %s Label: %s`, presetWidth, labelWidth);
+ labelWidth += 16;
+ if (presetWidth < labelWidth) {
+ for (let ss of document.styleSheets) {
+ if (ss.href.endsWith("/ui.css")) {
+ for (let r of ss.cssRules) {
+ if (/input\.preset:checked.*min-width:/.test(r.cssText)) {
+ r.style.minWidth = (labelWidth) + "px";
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ sizer.style.visibility = "visible";
+ // setTimeout( () => sizer.style.display = "none");
+ }
+
}
// URL