From 183b52e11d69027b8f1447395fcb2aea7c9347be Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 7 Mar 2022 01:47:59 +0300 Subject: [PATCH] add year selector in popup search --- _locales/en/messages.json | 2 +- js/dlg/config-dialog.js | 16 ++--- js/dom.js | 11 ++++ js/localization.js | 5 +- popup/popup.css | 4 +- popup/search.css | 27 ++++++--- popup/search.html | 19 +++--- popup/search.js | 121 +++++++++++++++++++++++++------------- 8 files changed, 129 insertions(+), 76 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e302037b..b7c45fd6 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1434,7 +1434,7 @@ "description": "Text for label that shows the number of times a search result was installed during last week" }, "searchStyleQueryHint": { - "message": "Search style names case-insensitively:\nsome words - all words in any order\n\"some phrase\" - this exact phrase without quotes\n2020 - a year like this also shows styles updated in 2020", + "message": "Search style names (case-sensitively if an uppercase letter is used):\nsome words - all these words in any order\n\"some phrase\" - this exact phrase without quotes\n/foo.*bar/i - regular expression without spaces (use \\s instead)", "description": "Tooltip shown for the text input in the popup's inline style finder" }, "searchStylesAll": { diff --git a/js/dlg/config-dialog.js b/js/dlg/config-dialog.js index 9e539301..945ba046 100644 --- a/js/dlg/config-dialog.js +++ b/js/dlg/config-dialog.js @@ -255,18 +255,10 @@ async function configDialog(style) { case 'dropdown': case 'image': // TODO: a image picker input? - children = [ - $create('.select-resizer.config-value', [ - va.input = $create('select', { - va, - onchange: updateVarOnChange, - }, - va.options.map(o => - $create('option', {value: o.name}, o.label))), - $create('SVG:svg.svg-icon.select-arrow', - $create('SVG:use', {'xlink:href': '#svg-icon-select-arrow'})), - ]), - ]; + va.input = $create('select', {va, onchange: updateVarOnChange}, + va.options.map(o => $create('option', {value: o.name}, o.label))); + children = [$.fancySelect(va.input)]; + children[0].classList.add('config-value'); break; case 'range': diff --git a/js/dom.js b/js/dom.js index 77b19290..f83da6a6 100644 --- a/js/dom.js +++ b/js/dom.js @@ -27,6 +27,17 @@ Object.assign(EventTarget.prototype, { $.root = document.documentElement; $.rootCL = $.root.classList; +$.dummies = { + select: $create('.select-resizer', + $create('SVG:svg.svg-icon.select-arrow', + $create('SVG:use', {'xlink:href': '#svg-icon-select-arrow'}))), +}; +$.fancySelect = el => { + const res = $.dummies.select.cloneNode(true); + if (el.parentNode) el.replaceWith(res); + res.prepend(el); + return res; +}; // Makes the focus outline appear on keyboard tabbing, but not on mouse clicks. const focusAccessibility = { diff --git a/js/localization.js b/js/localization.js index af020069..b99b972f 100644 --- a/js/localization.js +++ b/js/localization.js @@ -29,7 +29,7 @@ Object.assign(t, { ')', /(?!\b|\s|$)/, ].map(rx => rx.source || rx).join(''), 'gu'), - SELECTOR: '[i18n], template', + SELECTOR: '[i18n], template, select', HTML(html) { return typeof html !== 'string' @@ -49,6 +49,9 @@ Object.assign(t, { t.createTemplate(node); continue; } + if (node.localName === 'select' && (node.nextElementSibling || {}).localName !== 'svg') { + $.fancySelect(node); + } const attr = node.getAttribute('i18n'); if (!attr) continue; for (const part of attr.split(',')) { diff --git a/popup/popup.css b/popup/popup.css index 46b92d6c..82600261 100644 --- a/popup/popup.css +++ b/popup/popup.css @@ -624,11 +624,11 @@ a:hover .svg-icon { fill: transparent; stroke: currentColor; } -html:not(.styles-last) #popup-options .split-btn-menu { +html:not(.styles-last):not(.search-results-shown) #popup-options .split-btn-menu { bottom: 0; transform: translateY(-20px); /* global button style: 13(font) * 1.2(line) + 4(pad) + 2(border) */ } -html:not(.styles-last) .split-btn-pedal::after { +html:not(.styles-last):not(.search-results-shown) .split-btn-pedal::after { border-top: var(--side) solid transparent; border-bottom: calc(var(--side) * 1.3) solid currentColor; vertical-align: top; diff --git a/popup/search.css b/popup/search.css index a35f6471..53fd7115 100644 --- a/popup/search.css +++ b/popup/search.css @@ -2,7 +2,7 @@ This file is loaded dynamically when the inline search is invoked. So don't put main popup's stuff here. */ -body.search-results-shown { +.search-results-shown body { overflow-y: auto; overflow-x: hidden; } @@ -288,35 +288,39 @@ search-result-meta [data-type="rating"][data-class="none"] dd { flex-direction: row; text-align: center; word-break: keep-all; + line-height: 24px; + font-size: 16px; } - .search-results-nav[data-type="top"] { padding-top: 1em; margin-bottom: 1em; } - .search-results-nav[data-type="bottom"] { margin-top: -1em; margin-bottom: 1em; } - +.search-results-nav label { + vertical-align: middle; + -moz-user-select: none; + user-select: none; +} +.search-results-nav [data-type="page"] { + font-weight: bold; +} #search-results .search-results-nav button { background: none; border: none; - padding: 0 1rem; + padding: 0 .5rem; margin: 0 .5rem; - font-size: 150%; - line-height: 24px; + font-size: 18px; vertical-align: middle; cursor: pointer; } - #search-results .search-results-nav button:disabled { cursor: auto; opacity: .25; pointer-events: none; } - #search-results .search-results-nav button:not(:disabled):hover { text-shadow: 0 1px 4px rgba(0, 0, 0, .5); } @@ -338,3 +342,8 @@ search-result-meta [data-type="rating"][data-class="none"] dd { margin-right: .5em; flex: 1 1 0; } + +#search-years { + text-align: center; + width: 100%; +} diff --git a/popup/search.html b/popup/search.html index 3e451830..74cc597c 100644 --- a/popup/search.html +++ b/popup/search.html @@ -3,17 +3,15 @@