add props parameter to helpPopup.show

This commit is contained in:
tophf 2021-12-26 13:05:37 +03:00
parent 9e2ceff264
commit 40abc64c2c
3 changed files with 18 additions and 10 deletions

View File

@ -113,9 +113,10 @@ function createBeautifyUI(scope, options) {
}, },
}, t(scope.length === 1 ? 'undo' : 'undoGlobal')), }, t(scope.length === 1 ? 'undo' : 'undoGlobal')),
]), ]),
])); ]),
{
$('#help-popup').className = 'wide'; className: 'wide',
});
$('.beautify-options').onchange = ({target}) => { $('.beautify-options').onchange = ({target}) => {
const value = target.type === 'checkbox' ? target.checked : target.selectedIndex > 0; const value = target.type === 'checkbox' ? target.checked : target.selectedIndex > 0;

View File

@ -27,8 +27,9 @@ function StyleSettings() {
$create('button', {onclick: helpPopup.close}, t('confirmClose')), $create('button', {onclick: helpPopup.close}, t('confirmClose')),
createInfo({title: t('autosaveNotice')}), createInfo({title: t('autosaveNotice')}),
]), ]),
])); ]), {
$('#help-popup').className = 'style-settings-popup'; className: 'style-settings-popup',
});
moveFocus(ui, 0); moveFocus(ui, 0);
function textToList(text) { function textToList(text) {

View File

@ -7,19 +7,26 @@
const helpPopup = { const helpPopup = {
show(title = '', body) { /**
* @param {string} title - plain text
* @param {string|Node} body - Node, html or plain text
* @param {Node} [props] - DOM props for the popup element
* @returns {Element} the popup
*/
show(title = '', body, props) {
const div = $('#help-popup'); const div = $('#help-popup');
const contents = $('.contents', div); const contents = $('.contents', div);
div.style = '';
div.className = ''; div.className = '';
contents.textContent = ''; contents.textContent = '';
Object.assign(div, props);
if (body) { if (body) {
contents.appendChild(typeof body === 'string' ? t.HTML(body) : body); contents.appendChild(typeof body === 'string' ? t.HTML(body) : body);
} }
$('.title', div).textContent = title; $('.title', div).textContent = title;
$('.dismiss', div).onclick = helpPopup.close; $('.dismiss', div).onclick = helpPopup.close;
window.on('keydown', helpPopup.close, true); window.on('keydown', helpPopup.close, true);
// reset any inline styles div.style.display = 'block';
div.style = 'display: block';
helpPopup.originalFocus = document.activeElement; helpPopup.originalFocus = document.activeElement;
return div; return div;
}, },
@ -172,8 +179,7 @@ function createHotkeyInput(prefId, {buttons = true, onDone}) {
/* exported showCodeMirrorPopup */ /* exported showCodeMirrorPopup */
function showCodeMirrorPopup(title, html, options) { function showCodeMirrorPopup(title, html, options) {
const popup = helpPopup.show(title, html); const popup = helpPopup.show(title, html, {className: 'big'});
popup.classList.add('big');
let cm = popup.codebox = CodeMirror($('.contents', popup), Object.assign({ let cm = popup.codebox = CodeMirror($('.contents', popup), Object.assign({
mode: 'css', mode: 'css',