Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
(8 intermediate revisions by the same user not shown) | |||
Line 139:
if (favoriteTemplates && favoriteTemplates.length > 0) {
//
$textarea.wikiEditor( 'addToToolbar', {
sections: {
Line 149:
} );
//
section: 'favorite-templates',▼
groups: {▼
favorites: {▼
label: 'My Favorites'▼
}▼
}▼
} );▼
// Add
for (const template of favoriteTemplates) {
const buttonId = createButtonId(template.title);
Line 165 ⟶ 158:
const displayTitle = template.title.replace(/^Template:/, '');
'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))
▲ } );
}
// Then add the group with all tools
$textarea.wikiEditor( 'addToToolbar', {
▲ section: 'favorite-templates',
▲ groups: {
▲ 'favorites': {
▲ }
▲ }
▲ } );
console.log(`Added ${favoriteTemplates.length} favorite template buttons to toolbar`);
|