User:Polygnotus/Scripts/WikiEditorToolbar.js: Difference between revisions

Content deleted Content added
No edit summary
use OOUI
 
(11 intermediate revisions by the same user not shown)
Line 1:
//I should be able to combine these
//colours are weird in dark mode
 
//https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization
 
// <nowiki>
Line 23 ⟶ 25:
},
refIdeas: {
type: 'element',
filters: [ 'body.ns-1' ],
element: function ( context ) {
var button = new OO.ui.ButtonInputWidget( {
label: '',
icon: 'lightbulb',
title: 'refideas'
} );
button.connect( null, {
click: function ( e ) {
var text = '{{refideas\n|1=\n}}';
var textarea = context.$textarea[0];
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var currentText = textarea.value;
textarea.value = currentText.substring(0, start) + text + currentText.substring(end);
textarea.selectionStart = textarea.selectionEnd = start + text.length;
textarea.focus();
$(textarea).trigger('input');
$('#wpSummary').val('Added {{refideas}} template');
}
} );
return button.$element;
}
},
wpPolicy: {
type: 'element',
refIdeas: {
type: ' element',: function ( context ) {
var button = new OO.ui.ButtonInputWidget( {
filters: [ 'body.ns-3' ],
label: 'ReadThis',
element: function ( context ) {
icon: 'articles'
var button = new OO.ui.ButtonInputWidget( {
label: '', } );
button.connect( null, {
icon: 'lightbulb',
title click: 'refideas'function ( e ) {
var policy = prompt('Enter Wikipedia policy/guideline abbreviation (e.g., NPOV, V, RS):');
 
if (policy !== null && policy.trim() !== '') {
} );
var text = '== [[WP:' + policy.trim() + ']] ==\nPlease read [[WP:' + policy.trim() + ']], thanks and have a nice day, ~~~~';
button.connect( null, {
context.$textarea.textSelection('encapsulateSelection', {
click: function ( e ) {
var text = '{{refideas\n|1=\n}}'; pre: text
});
// Try multiple methods to insert text }
if ( context.fn && context.fn.encapsulateSelection ) {}
context.fn.encapsulateSelection( { } );
pre:return textbutton.$element;
} );
} else if ( context.$textarea ) {
// Direct textarea manipulation
var textarea = context.$textarea[0];
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var currentText = textarea.value;
textarea.value = currentText.substring(0, start) + text + currentText.substring(end);
textarea.selectionStart = textarea.selectionEnd = start + text.length;
textarea.focus();
// Trigger change event
$(textarea).trigger('input');
} else {
// Fallback - try to find the textarea
var $textarea = $('#wpTextbox1');
if ( $textarea.length ) {
var textarea = $textarea[0];
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var currentText = textarea.value;
textarea.value = currentText.substring(0, start) + text + currentText.substring(end);
textarea.selectionStart = textarea.selectionEnd = start + text.length;
textarea.focus();
$textarea.trigger('input');
}
},
}
} );
return button.$element;
}
},
wpPolicy: {
label: 'WP Policy',
filters: [ 'body.ns-3' ],
type: 'button',
icon: 'article',
action: {
type: 'callback',
execute: function( context ) {
var policy = prompt('Enter Wikipedia policy/guideline abbreviation (e.g., NPOV, V, RS):');
if (policy !== null && policy.trim() !== '') {
var text = '== [[WP:' + policy.trim() + ']] ==\nPlease read [[WP:' + policy.trim() + ']], thanks and have a nice day, ~~~~';
context.$textarea.textSelection('encapsulateSelection', {
pre: text
});
}
}
}
},
 
 
exlinkInBody: {
labeltype: 'ExternalLinkInBodyelement',
filters: [ 'body.ns-3' ],
typeelement: 'button',function ( context ) {
icon: var button = new OO.ui.ButtonInputWidget( {
src label: '//upload.wikimedia.org/wikipedia/commons/0/05/IUCN_EX.svgExternalLinkInBody',
icon: '//upload.wikimedia.org/wikipedia/commons/0/05/IUCN_EX.svg'
width: 26,
height:} 26);
} button.connect( null, {
action click: function ( e ) {
var text = '{{subst:' + 'User:Polygnotus/Templates/exlink}} ~~' + '~~';
type: 'encapsulate',
context.$textarea.textSelection('encapsulateSelection', {
options: {
pre: '{{subst:' + 'User pre:Polygnotus/Templates/exlink}} ~~' + '~~',text
});
}
} );
return button.$element;
}
},
uwSpam: {
labeltype: 'UW-Spamelement',
filters: [ 'body.ns-3' ],
typeelement: 'button',function ( context ) {
var button = new OO.ui.ButtonInputWidget( {
icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/No-spam.svg',
action label: {'Uw-Spam',
icon: '//upload.wikimedia.org/wikipedia/commons/c/c8/No-spam.svg'
type: 'encapsulate',
options:} {);
button.connect( null, pre: '{{subst:' + 'uw-spam}} ~~' + '~~',
} click: function ( e ) {
var text = '{{subst:' + 'uw-spam}} ~~' + '~~';
context.$textarea.textSelection('encapsulateSelection', {
pre: text
});
}
} );
return button.$element;
}
},