MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1275: | Строка 1275: | ||
// wiki import end | // wiki import end | ||
(function($, mw) { | |||
const COOKIE = 'ss14_wikiTheme'; | const COOKIE = 'ss14_wikiTheme'; | ||
| Строка 1311: | Строка 1311: | ||
const $form = $('<form>'); | const $form = $('<form>'); | ||
[ | |||
{ key: 'light', label: 'Светлая (beta)' }, | { key: 'light', label: 'Светлая (beta)' }, | ||
{ key: 'normal', label: 'Стандартная' }, | { key: 'normal', label: 'Стандартная' }, | ||
{ key: 'dark', label: 'Тёмная' }, | { key: 'dark', label: 'Тёмная' }, | ||
{ key: 'ss14', label: 'Space Station 14' } | { key: 'ss14', label: 'Space Station 14' } | ||
] | ].forEach(opt => { | ||
const $wr = $('<div>', { class: 'theme-client-prefs-radio' }); | const $wr = $('<div>', { class: 'theme-client-prefs-radio' }); | ||
const $inp = $('<input>', { | const $inp = $('<input>', { | ||
type: 'radio', | type: 'radio', | ||
name: 'theme-selection', | name: 'theme-selection', | ||
id: `theme-value-${opt.key}`, | id: `theme-value-${opt.key}`, | ||
value: opt.key, | value: opt.key, | ||
checked: opt.key === currentTheme | checked: opt.key === currentTheme | ||
}); | }); | ||
const $lbl = $('<label>', { | const $lbl = $('<label>', { | ||
for: `theme-value-${opt.key}`, | for: `theme-value-${opt.key}`, | ||
text: opt.label | text: opt.label | ||
}); | }); | ||
$wr.append($inp, $lbl); | $wr.append($inp, $lbl); | ||
| Строка 1352: | Строка 1351: | ||
mw.themeUtils = { loadTheme, saveTheme, applyTheme, initThemeMenu }; | mw.themeUtils = { loadTheme, saveTheme, applyTheme, initThemeMenu }; | ||
function createSettingsDropdown() { | |||
const | const currentTheme = loadTheme(); | ||
const $dropdown = $('<div>', { class: 'theme-dropdown' }); | const $dropdown = $('<div>', { class: 'theme-dropdown' }); | ||
const $details = $('<details>', { id: 'theme-preferences-details', class: 'theme-dropdown-details' }); | const $details = $('<details>', { id: 'theme-preferences-details', class: 'theme-dropdown-details' }); | ||
| Строка 1363: | Строка 1360: | ||
const $window = $('<div>', { id: 'theme-preferences', class: 'theme-window' }).hide(); | const $window = $('<div>', { id: 'theme-preferences', class: 'theme-window' }).hide(); | ||
const $header = $('<div>', { id: 'theme-preferences__header', class: 'theme-window__header', text: 'Параметры' }); | const $header = $('<div>', { | ||
const $content = $('<div>', { id: 'theme-preferences__content', class: 'theme-window__content' }); | id: 'theme-preferences__header', | ||
$window.append( | class: 'theme-window__header', | ||
text: 'Параметры' | |||
}); | |||
$window.append($header); | |||
const $content = $('<div>', { | |||
id: 'theme-preferences__content', | |||
class: 'theme-window__content' | |||
}); | |||
$window.append($content); | |||
initThemeMenu($content | initThemeMenu($content); | ||
$dropdown.append($details, $window); | $dropdown.append($details, $window); | ||
| Строка 1373: | Строка 1379: | ||
const $cover = $('#menus-cover'); | const $cover = $('#menus-cover'); | ||
$details.on('toggle', function() { | $details.on('toggle', function() { | ||
const isOpen = $(this).prop('open'); | const isOpen = $(this).prop('open'); | ||
| Строка 1380: | Строка 1387: | ||
} | } | ||
}); | }); | ||
$(document).on('click', function(e) { | $(document).on('click', function(e) { | ||
const | const inside = $(e.target).closest('.theme-window, .theme-dropdown-summary').length; | ||
if (! | if (!inside && $details.prop('open')) { | ||
$details.removeAttr('open'); | $details.removeAttr('open'); | ||
if ($cover.length) { | if ($cover.length) { $cover.css('display', 'none'); } | ||
} | } | ||
}); | }); | ||
} | |||
$(function() { | |||
applyTheme(loadTheme()); | |||
createSettingsDropdown(); | |||
}); | }); | ||
}(jQuery, mediaWiki)); | |||
} | |||