From 6a07ad0f56677deadeb9ef941189ab3a9130446a Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 19 Jan 2022 16:13:53 +0300 Subject: [PATCH] split button for manage::export, popup::manage --- _locales/en/messages.json | 7 +++++++ global.css | 7 +------ js/dom-on-load.js | 28 +++++++++++++++++++++++----- manage.html | 5 ++++- manage/import-export.js | 12 +++++++++--- manage/manage.css | 2 +- popup.html | 7 +++++-- popup/events.js | 2 +- popup/popup.css | 18 ++++++++++++++---- popup/popup.js | 1 + 10 files changed, 66 insertions(+), 23 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 4a88c107..58006e22 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -392,6 +392,9 @@ "message": "Export", "description": "Label for the button to export a style ('edit' page) or all styles ('manage' page)" }, + "exportCompatible": { + "message": "Export (compatible mode)" + }, "exportSavedSuccess": { "message": "File saved with success" }, @@ -1269,6 +1272,10 @@ "message": "Click to see available hotkeys", "description": "Tooltip displayed when hovering the right edge of the extension popup" }, + "popupManageSiteStyles": { + "message": "Manage site styles", + "description": "Item in the dropdown menu for the 'Manage' button in the popup that opens manager with styles applicable for current site." + }, "popupManageTooltip": { "message": "Shift-click or right-click opens manager with styles applicable for current site", "description": "Tooltip for the 'Manage' button in the popup." diff --git a/global.css b/global.css index e9f1b246..6f4613bc 100644 --- a/global.css +++ b/global.css @@ -315,6 +315,7 @@ body.resizing-v > * { margin-left: -1px !important; padding-left: .2em !important; padding-right: .2em !important; + min-width: 0 !important; } .split-btn-pedal::after { content: '\25BC'; /* down triangle */ @@ -384,12 +385,6 @@ body.resizing-v > * { padding: 4px; } -/* Firefox cannot handle fractions in font-size */ - .firefox button:not(.install) { - line-height: 13px; - padding: 3px 7px; - } - .firefox.moz-appearance-bug button:not(.install) { padding: 2px 4px; } diff --git a/js/dom-on-load.js b/js/dom-on-load.js index 634ae5dd..05e63b9a 100644 --- a/js/dom-on-load.js +++ b/js/dom-on-load.js @@ -85,20 +85,31 @@ } } + /** + * @param {PointerEvent} [event] - absent when self-invoked to hide the menu + */ function splitMenu(event) { const prevMenu = $(SPLIT_BTN_MENU); const prevPedal = (prevMenu || {}).previousElementSibling; - const pedal = event.target.closest('.split-btn-pedal'); - const entry = prevMenu && event.target.closest(SPLIT_BTN_MENU + '>*'); - if (prevMenu) prevMenu.remove(); - if (prevPedal) prevPedal.classList.remove('active'); + const pedal = event && event.target.closest('.split-btn-pedal'); + const entry = event && prevMenu && event.target.closest(SPLIT_BTN_MENU + '>*'); + if (prevMenu) { + prevMenu.remove(); + prevPedal.classList.remove('active'); + window.off('keydown', splitMenuEscape); + } if (pedal && pedal !== prevPedal) { const menu = $create(SPLIT_BTN_MENU, Array.from(pedal.attributes, ({name, value}) => name.startsWith('menu-') && $create('a', {tabIndex: 0, __cmd: name.split('-').pop()}, value) )); - menu.on('focusout', e => e.target === menu && splitMenu(e)); + window.on('keydown', splitMenuEscape); + menu.on('focusout', e => { + if (!menu.contains(e.relatedTarget)) { + setTimeout(splitMenu); + } + }); pedal.classList.toggle('active'); pedal.after(menu); moveFocus(menu, 0); @@ -112,6 +123,13 @@ } } + function splitMenuEscape(e) { + if (getEventKeyName(e) === 'Escape') { + e.preventDefault(); + splitMenu(); + } + } + function suppressFocusRingOnClick({target}) { const el = focusAccessibility.closest(target); if (el) { diff --git a/manage.html b/manage.html index 1a960c80..761404cf 100644 --- a/manage.html +++ b/manage.html @@ -328,7 +328,10 @@
- +
+ +
diff --git a/manage/import-export.js b/manage/import-export.js index 2b45a388..31afee1e 100644 --- a/manage/import-export.js +++ b/manage/import-export.js @@ -14,8 +14,11 @@ */// dom.js 'use strict'; -$('#file-all-styles').onclick = exportToFile; -$('#file-all-styles').oncontextmenu = exportToFile; +Object.assign($('#file-all-styles'), { + onclick: exportToFile, + oncontextmenu: exportToFile, + onauxclick: exportToFile, +}); $('#unfile-all-styles').onclick = () => importFromFile({fileTypeFilter: '.json'}); Object.assign(document.body, { @@ -336,9 +339,12 @@ async function importFromString(jsonString) { /** @param {MouseEvent} e */ async function exportToFile(e) { + if (e.type === 'auxclick' && !e.detail) { + return; + } e.preventDefault(); await require(['/js/storage-util']); - const keepDupSections = e.type === 'contextmenu' || e.shiftKey; + const keepDupSections = e.type === 'contextmenu' || e.shiftKey || e.detail === 'compat'; const data = [ Object.assign({ [prefs.STORAGE_KEY]: prefs.values, diff --git a/manage/manage.css b/manage/manage.css index 035ef169..79231224 100644 --- a/manage/manage.css +++ b/manage/manage.css @@ -262,7 +262,7 @@ a:hover { flex-wrap: wrap; } -#backup-buttons button { +#backup-buttons > * { margin: 0 .2rem .5rem 0; } diff --git a/popup.html b/popup.html index cef9b3d6..b83df58f 100644 --- a/popup.html +++ b/popup.html @@ -219,8 +219,11 @@