User:Indic-TechCom/Script/AddColonButton.js

From Meta, a Wikimedia project coordination wiki

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*
    This scipt add a extra icon button in WikiEditor to add colon.

    @Author [[User:Jayprakash12345]]
    @OwnBy [[meta:Indic-TechCom]]
*/
var AddColonButton = function () {

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'insert',
        'tools': {
            'AddColonButton': {
                label: 'Add Colon',
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Colon.svg/22px-Colon.svg.png',
                action: {
                    type: 'encapsulate',
                    options: {
                        pre: ":"
                    }
                }
            }
        }
    } );
};

var HashColonButtonForWikt = function () {

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'insert',
        'tools': {
            'HashColonButtonForWikt': {
                label: 'Add #:{{எ. கா.}}',
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Colon.svg/22px-Colon.svg.png',
                action: {
                    type: 'encapsulate',
                    options: {
                        pre: "#:{{எ. கா.}}"
                    }
                }
            }
        }
    } );
};
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
	
	// For talk pages
	if( mw.config.get('wgNamespaceNumber') %2 !== 0 ) {
	        $.when( mw.loader.using( 'ext.wikiEditor' ), $.ready)
	         .then( AddColonButton );
	}

	// Request from tawikt for main pages to add :# button	
	if( mw.config.get('wgNamespaceNumber') %2 === 0 && mw.config.get('wgDBname') === 'tawiktionary' ) {
	        $.when( mw.loader.using( 'ext.wikiEditor' ), $.ready)
	         .then( HashColonButtonForWikt );
	}
	
}