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

Content deleted Content added
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 139:
if (favoriteTemplates && favoriteTemplates.length > 0) {
// First, add the section
$textarea.wikiEditor( 'addToToolbar', {
sections: {
'favorite-templates': {
labeltype: 'Favorite Templatestoolbar',
label: 'Favorite Templates'
}
}
} );
// Create the tools object for the buttons
const templateTools = {};
Line 149 ⟶ 159:
templateTools[buttonId] = {
labeltype: displayTitle'element',
actionelement: {$('<button>')
type: .addClass('encapsulatetool tool-button',)
options: {.text(displayTitle)
pre: templateSyntax.css({
} 'padding': '4px 8px',
} 'margin': '2px',
'border': '1px solid #a2a9b1',
'border-radius': '2px',
'background': '#f8f9fa',
'cursor': 'pointer',
'font-size': '11px',
'font-family': 'sans-serif'
})
.hover(
function() { $(this).css('background', '#eaecf0'); },
function() { $(this).css('background', '#f8f9fa'); }
)
.click((function(syntax) {
return 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) + syntax + text.substring(end);
// Move cursor to end of inserted text
textarea.selectionStart = textarea.selectionEnd = start + syntax.length;
textarea.focus();
}
};
})(templateSyntax))
};
}
// AddThen add the Templates sectiongroup with all tools at once
$textarea.wikiEditor( 'addToToolbar', {
section: 'mainfavorite-templates',
groups: {
'favorite-templatesfavorites': {
label: 'Favorite Templates',
tools: templateTools
}