User:Gryllida/js/weAddCommentButton.js

/* Author : Svetlana Tkachenko svetlana@members.fsf.org Licence: GPLv3+ Description: [beta] adds inline comments to drafts during draft review TODO: [ ]

technical details of customizing the toolbar snippets of code for common additions to the toolbar
 * http://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar customization
 * http://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar customization/Library



mw.loader.using(['mediawiki.api'], function {	"use strict";	var encapsulateMyLink= function(prefix, postfix, offset){		var cursorPos = $( '#wpTextbox1' ).textSelection( 'getCaretPosition', { startAndEnd: true } );		$( '#wpTextbox1' ).focus;        $.wikiEditor.modules.toolbar.fn.doAction( $( '#wpTextbox1' ).data( 'wikiEditor-context' ), {'type': 'encapsulate','options': {'pre': prefix,'peri': '','post': postfix} }, $( '#wpTextbox1' ));		$( '#wpTextbox1' ).textSelection( 'setSelection', { start: cursorPos[ 1 ]+offset, end: cursorPos[ 1 ]+offset} );	};	var customizeToolbar = function {		$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { 'section': 'main', 'group': 'insert', 'tools': { 'addInlineComment': { label: 'Add an inline comment', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Symbol_comment.svg/23px-Symbol_comment.svg.png', 'action': { 'type': 'callback', execute: function(context){ encapsulateMyLink(" ", " ( )", 13); }					},				}			}		});	};	/* 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 ) {		mw.loader.using( 'user.options' ).then( function { // This can be the string "0" if the user disabled the preference (T54542) if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) { $.when(					mw.loader.using( 'ext.wikiEditor' ), $.ready				).then( customizeToolbar ); }		} );	} });