User:Od1n/global.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* globals mw, $ */
(function () {
'use strict';
// version partielle de l'objet "page" présent dans [[:fr:Utilisateur:Od1n/common.js]]
var page = {
action: mw.config.get('wgAction'),
special: mw.config.get('wgCanonicalSpecialPageName'),
};
page.isEdit = page.action === 'edit' || page.action === 'submit';
//--------------------------------------------------------------------------
// Sécurité anti-publication accidentelle
//--------------------------------------------------------------------------
function blockEnter(input) {
if (!input) {
return;
}
// "beforeinput" est recommandé mais n'est pas implémenté dans tous les navigateurs
var eventType = ('onbeforeinput' in input) ? 'beforeinput' : 'keypress';
input.addEventListener(eventType, function (e) {
if (e.key === 'Enter') {
e.preventDefault();
alert('Bloqué la publication accidentelle avec la touche Entrée\xA0!');
}
});
}
if (page.isEdit) {
$(function ($) { // eslint-disable-line no-unused-vars
blockEnter(document.getElementById('wpSummary'));
});
} else if (page.special === 'Movepage' || page.action === 'delete') {
$(function ($) { // eslint-disable-line no-unused-vars
blockEnter(document.querySelector('#wpReason input'));
});
}
})();