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

Content deleted Content added
No edit summary
No edit summary
 
Line 160:
templateTools[buttonId] = {
type: 'element',
element: $(function(syntax, title'<button>') {
return.addClass('tool function(tool-button') {
return $.text('<button>'displayTitle)
.addClasscss('tool tool-button'){
'padding': '4px .text(title)8px',
'margin': .css({'2px',
'paddingborder': '4px1px solid 8px#a2a9b1',
'marginborder-radius': '2px',
'borderbackground': '1px solid #a2a9b1f8f9fa',
'border-radiuscursor': '2pxpointer',
'backgroundfont-size': '#f8f9fa11px',
'cursorfont-family': 'pointersans-serif',
'font-size': '11px',})
'font-family': 'sans-serif'.hover(
function() { $(this).css('background', '#eaecf0'); }),
function() { $(this).hovercss('background', '#f8f9fa'); }
function() { $(this).css('background', '#eaecf0'); },
.click((function(syntax) { $(this).css('background', '#f8f9fa'); }
return function(e) ){
e.clickpreventDefault(function(e) {;
// Get the e.preventDefault();textarea
const textarea = // Get the textarea$('#wpTextbox1')[0];
if const (textarea) = $('#wpTextbox1')[0];{
if// (textarea)Insert {the template syntax at cursor position
const start = // Insert the template syntax at cursor positiontextarea.selectionStart;
const startend = textarea.selectionStartselectionEnd;
const endtext = textarea.selectionEndvalue;
textarea.value = text.substring(0, start) const+ textsyntax =+ textareatext.valuesubstring(end);
// Move cursor to textarea.valueend =of text.substring(0, start) + syntax +inserted text.substring(end);
textarea.selectionStart = textarea.selectionEnd = //start Move+ cursor to end of inserted textsyntax.length;
textarea.selectionStart = textarea.selectionEnd = start + syntax.lengthfocus();
}
textarea.focus() };
})(templateSyntax))
});
};
})(templateSyntax, displayTitle)
};
}