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

Content deleted Content added
Created page with '// Add Templates section to 2010 wikitext editor // Place this code in your common.js file $(document).ready(function() { // Only run on edit pages with the 2010 wikitext editor if (mw.config.get('wgAction') === 'edit' && $('#wpTextbox1').length) { // Create the Templates section var templatesSection = $('<div>') .attr('id', 'templates-section') .css({ 'border': '1px solid #a2a9b1',...'
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1:
// Add Templates section to 2010WikiEditor wikitext2010 editortoolbar
// Place this code in your common.js file
 
// Check if we're editing a page
$(document).ready(function() {
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
// Only run on edit pages with the 2010 wikitext editor
// Add a hook handler
if (mw.config.get('wgAction') === 'edit' && $('#wpTextbox1').length) {
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
// CreateAdd the Templates toolbar section
$textarea.wikiEditor( 'addToToolbar', {
var templatesSection = $('<div>')
.attr('id',sections: 'templates-section'){
.css( templates: {
'border': '1px solid #a2a9b1 type: 'toolbar',
'margin' label: '10px 0Templates',
'padding': '10px',}
'background-color': '#f8f9fa'}
} });
// Add sectiona titlegroup for warning templates
$textarea.wikiEditor( 'addToToolbar', {
var sectionTitle = $('<h3>')
.text(section: 'Templatestemplates'),
.css(groups: {
'margin'warnings: '0 0 10px 0',{
'font-size' label: '14pxWarning templates',
'font-weight': 'bold'}
});
} );
// CreateAdd the uw-3rr button
$textarea.wikiEditor( 'addToToolbar', {
var uw3rrButton = $('<button>')
.attr(section: 'typetemplates', 'button')
.text(group: '{{uw-3rr}}warnings'),
.css(tools: {
'marginuw-3rr': '5px',{
'padding' label: '5px{{uw-3rr}} - 3RR 10pxwarning',
'background-color' type: '#0645adbutton',
'color' oouiIcon: 'whitealert',
'border' action: 'none',{
'border-radius' type: '3pxencapsulate',
'cursor' options: 'pointer'{
pre: '{{uw-3rr})}'
.hover( }
function() { $(this).css('background-color', '#0b0080'); },
function() { $(this).css('background-color', '#0645ad'); }
);}
} );
} );
// Add click handler to insert template
}
uw3rrButton.click(function() {
var textArea = $('#wpTextbox1')[0];
var template = '{{uw-3rr}}';
// Get current cursor position
var startPos = textArea.selectionStart;
var endPos = textArea.selectionEnd;
// Insert template at cursor position
var textBefore = textArea.value.substring(0, startPos);
var textAfter = textArea.value.substring(endPos);
textArea.value = textBefore + template + textAfter;
// Set cursor position after the inserted template
textArea.selectionStart = textArea.selectionEnd = startPos + template.length;
// Focus back on the text area
textArea.focus();
});
// Assemble the section
templatesSection.append(sectionTitle);
templatesSection.append(uw3rrButton);
// Insert the section above the edit form
$('#editform').before(templatesSection);
}
});