MediaWiki:Common.js
MediaWiki interface page
More actions
Poznámka: Po zveřejnění musíte vyprázdnit cache vašeho prohlížeče, jinak změny neuvidíte.
- Firefox / Safari: Při kliknutí na Aktualizovat držte Shift nebo stiskněte Ctrl-F5 nebo Ctrl-R (na Macu ⌘-R)
- Google Chrome: Stiskněte Ctrl-Shift-R (na Macu ⌘-Shift-R)
- Edge: Při kliknutí na Aktualizovat držte Ctrl nebo stiskněte Ctrl-F5.
mw.hook('wikipage.content').add(function ($c) {
var $ph = $c.find('.private-placeholder');
if ($ph.length > 1) {
$ph.slice(1).remove();
}
});
// Mini toolbar pro formátování textu v parametrech šablon (VisualEditor)
(function () {
function wrapSelection(input, before, after) {
const s = input.selectionStart, e = input.selectionEnd;
const val = input.value, sel = val.slice(s, e);
input.value = val.slice(0, s) + before + sel + after + val.slice(e);
const pos = s + before.length + sel.length + after.length;
input.focus();
input.setSelectionRange(pos, pos);
}
function wrapEachLine(input, prefix) {
const s = input.selectionStart, e = input.selectionEnd;
const val = input.value, sel = val.slice(s, e);
const wrapped = (sel || '').split('\n').map(l => (l ? prefix + l : l)).join('\n');
input.value = val.slice(0, s) + wrapped + val.slice(e);
const pos = s + wrapped.length;
input.focus();
input.setSelectionRange(pos, pos);
}
function addToolbarNear(input) {
const $input = $(input);
// najdi pole (field) – co nejvýš, ale v rámci dialogu
const $field =
$input.closest('.ve-ui-mwParameterPage-field').length ?
$input.closest('.ve-ui-mwParameterPage-field') :
$input.closest('.oo-ui-layout'); // fallback
if (!$field.length || $field.data('privateToolbar')) return;
const $bar = $('<div class="private-mini-toolbar" />');
function btn(label, title, handler) {
$('<button type="button" class="pmt-btn" />')
.text(label).attr('title', title).on('click', () => handler(input))
.appendTo($bar);
}
btn('B', "Tučné ('''...''')", el => wrapSelection(el, "'''", "'''"));
btn('I', "Kurzíva (''...'' )", el => wrapSelection(el, "''", "''"));
btn('H2', 'Nadpis H2', el => wrapSelection(el, '== ', ' =='));
btn('•', 'Seznam (odrážky)', el => wrapEachLine(el, '* '));
btn('[]', 'Odkaz [[...]]', el => {
const s = el.selectionStart, e = el.selectionEnd;
const val = el.value, sel = val.slice(s, e) || 'Cíl';
// [[Cíl|text]] pokud je něco vybráno; jinak jen [[Cíl]]
if (sel && sel !== 'Cíl') wrapSelection(el, '[[', '|' + sel + ']]');
else wrapSelection(el, '[[Cíl]]', '');
});
// vlož lištu těsně před widget s textareou
const $widget = $input.closest('.oo-ui-widget');
($widget.length ? $widget : $field).before($bar);
$field.data('privateToolbar', true);
}
// Delegovaný listener: když zaostří textarea v dialogu šablony, přidej lištu
$(document).on(
'focusin',
'.ve-ui-mwTemplateDialog textarea.oo-ui-inputWidget-input:not(.oo-ui-element-hidden)',
function () { addToolbarNear(this); }
);
})();