Участник:DonRumata/lowercase.js

function lowerFunc()
{
	var focus = $( document.activeElement );
	if (focus) {
		if ( focus.hasClass('CodeMirror-code') || focus.hasClass('cm-content') ) {
			focus = $( '#wpTextbox1' );
		} 
		if ( focus.is('textarea, input') ) {
			var oldText = focus.textSelection('getSelection');
			if (oldText) {
				newText = oldText.toLocaleLowerCase();
				// replace text
				focus.textSelection( 'encapsulateSelection', {
					replace: true,
					peri: newText
				} );
			}
		}
	}
}

var customizeToolbar = function() {
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'format',
        'tools': {
            'lowercase': {
                label: 'Lowercase', // or use labelMsg for a localized label, see above
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/commons/1/10/Toolbar_Format_small.png',
                action: {
                    'type': 'callback',
                    'execute': lowerFunc
                }
            }
        }
    } );
};

if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
    mw.loader.using( ['user.options', 'jquery.textSelection'], function () {
        if ( mw.user.options.get('usebetatoolbar') === 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor' ),
					$.ready
			).then( customizeToolbar );
		}
    } );
}
Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9

Portal di Ensiklopedia Dunia

Kembali kehalaman sebelumnya