MediaWiki:Gadget-onScreenEdit.js

try { // containerize gadget, to protect other gadgets if this one goes wrong

//created by bawolff. IF you have comments/questions/concerns/etc please talk to me //Allows people to edit the page itself in a WYSIWYG way (but no save) // //intended for people reviewing, to enable them to go over page, and cross out stuff as they check it (based on comments by Pi Zero

//if anyone wants undo/redo let me know. its really easy to add.

//not extensively tested. should work in modern browsers + MSIE 5.5 and greater.

window.onScreenEditInit = function { var cl = document.getElementsByTagName('html')[0].className; if (cl.indexOf('firefox2') !== -1) { document.designMode = 'on'; } document.getElementById('bodyContent').contentEditable = true; function btn (img, cmd, tooltip) { var foo = document.createElement('img'); foo.src = img; foo.alt = tooltip; foo.title = tooltip; foo.border = 0; foo.style.cursor = 'pointer'; foo.onclick = cmd;

return foo; } var hl; try { hl = document.queryCommandSupported('hilitecolor') ? 'hilitecolor' : 'backcolor'; } catch (e) { hl = 'hilitecolor'; //firefox supports, but doesn't support the check for support } var toolbar = document.createElement('div'); toolbar.appendChild(btn('//upload.wikimedia.org/wikipedia/commons/6/6f/Bold_icon.png', function {document.execCommand('bold', false, null)}, 'Bold'));

toolbar.appendChild(btn('//upload.wikimedia.org/wikipedia/commons/3/30/Btn_toolbar_rayer.png', function {document.execCommand('strikethrough', false, null)}, 'Cross out'));

var hilightLastColor = 'orange'; toolbar.appendChild(btn('//upload.wikimedia.org/wikipedia/commons/7/76/Button_atelier_graphique.PNG', function { hilightLastColor = prompt('Color name (or hex value). For example grey, or #aaaaaa',hilightLastColor); document.execCommand(hl, false, hilightLastColor)}, 'Highlight'));

toolbar.appendChild(btn('//upload.wikimedia.org/wikipedia/commons/thumb/b/b0/ButtonYellow.svg/22px-ButtonYellow.svg.png', function {document.execCommand(hl, false, 'yellow')}, 'Highlight yellow'));

toolbar.appendChild(btn('//upload.wikimedia.org/wikipedia/commons/thumb/9/97/ButtonRed.svg/22px-ButtonRed.svg.png', function {document.execCommand(hl, false, 'red')}, 'Highlight red'));

toolbar.appendChild(btn('//upload.wikimedia.org/wikipedia/commons/thumb/3/3c/ButtonGreen.svg/22px-ButtonGreen.svg.png', function {document.execCommand(hl, false, 'lightgreen')}, 'Highlight green'));

toolbar.appendChild(btn('//upload.wikimedia.org/wikipedia/commons/thumb/c/c1/ButtonBlue.svg/22px-ButtonBlue.svg.png', function {document.execCommand(hl, false, 'aqua')}, 'Highlight blue')); var msg = document.getElementById('firstHeading'); msg.parentNode.insertBefore(toolbar, msg);

};

window.onScreenEditInit.setup = function { //called onload if (mw.config.get('wgAction') === 'view') { //allowed on normal view + preview mw.util.addPortletLink('p-tb', 'javascript:onScreenEditInit;void%200', 'On screen edit'); } }; $(window.onScreenEditInit.setup);

} catch (e) { // containerize gadget, to protect other gadgets if this one goes wrong // ignore }