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

Content deleted Content added
No edit summary
No edit summary
Line 159:
templateTools[buttonId] = {
labeltype: displayTitle'element',
typeelement: 'button',function() {
action: { return $('<a>')
type: .attr('encapsulatehref', '#')
options: { .addClass('tool tool-button')
pre: templateSyntax.text(displayTitle)
} .click(function(e) {
e.preventDefault();
// Get the textarea
const textarea = $('#wpTextbox1')[0];
if (textarea) {
// Insert the template syntax at cursor position
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const text = textarea.value;
textarea.value = text.substring(0, start) + templateSyntax + text.substring(end);
// Move cursor to end of inserted text
textarea.selectionStart = textarea.selectionEnd = start + templateSyntax.length;
textarea.focus();
}
});
}
};