Jump to content

User:Osiris/toolbar.js

From Simple English Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Add some extra buttons in edit toolbar
var customizeToolbar = function() {
$( function() {
             if ( typeof $.fn.wikiEditor != 'undefined' ) {
                   $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
                          'section': 'help',
                   });
             }
        });

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'insert',
        'tools': {
                'Insert': {
                        label: 'En dash',
                        type: 'button',
                        icon: '/media/wikipedia/commons/2/2c/Norwegian_ndash_sign.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '–',
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'insert',
        'tools': {
                'Insert': {
                        label: 'Easy link',
                        type: 'button',
                        icon: '/media/wikipedia/commons/e/ef/Toolbar_Corchetes_Vector.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '[[',
                                        post: ']]'
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'group': 'insert',
        'tools': {
                'Insert': {
                        label: 'Category',
                        type: 'button',
                        icon: '/media/wikipedia/commons/c/c4/Toolbar_category.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '[[Category:',
                                        post: ']]\n' // text to be inserted
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'group': 'insert',
        'tools': {
                'Insert': {
                        label: 'Defaultsort key',
                        type: 'button',
                        icon: '/media/wikipedia/commons/d/dd/Toolbaricon_bolditalic_D.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '{{DEFAULTSORT:',
                                        post: '}}\n' // text to be inserted
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'group': 'insert',
        'tools': {
                'Insert': {
                        label: 'Code formatting',
                        type: 'button',
                        icon: '/media/wikipedia/commons/5/5e/Wikieditor-tt.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '<code>',
                                        post: '</code>' // text to be inserted
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'group': 'insert',
        'tools': {
                'Insert': {
                        label: 'Attribution',
                        type: 'button',
                        icon: '/media/wikipedia/commons/7/71/Toolbar_copyvio.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '{{translated page|en|{{sub' + 'st:PAGENAME}}|oldid=',
                                        post: '}}\n' // text to be inserted
                                }
                        }
                }
        }
} );
};
 
/* Check if view is in edit mode and that the required modules are available */
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.using( 'user.options', function () {
                if ( mw.user.options.get('usebetatoolbar') ) {
                        mw.loader.using( 'ext.wikiEditor', function () {
                                $(document).ready( customizeToolbar );
                        } );
                }
        } );
}