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

Content deleted Content added
No edit summary
No edit summary
Line 25:
refIdeas: {
type: 'element',
filters: [ 'body.ns-3' ],
Line 36:
click: function ( e ) {
var text = '{{refideas\n|1=\n}}';
} );
context.fn.encapsulateSelection( {
// Try pre:multiple methods to insert text
if ( context.fn && context.fn.encapsulateSelection ) {
} );
context.fn.encapsulateSelection( {
pre: text
} );
} 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');
}
}
}
} );