Участник:INSAR/quoter.js

Материал из Викицитатника
var toolbarAddCloseSectionButton = function() {
  // To add a group to an existing toolbar section:
  $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    'section': 'main',
    'groups': {
      'extra': {
        'tools': {
          'noai': {
            'label': 'Оформление с помощью шаблона Q',
            'type': 'button',
            'icon': '//upload.wikimedia.org/wikipedia/commons/4/4a/Norwegian_template_sign.png',
            'action': {
              'type': 'encapsulate',
              'options': {
                'pre': "{{Q|",
                'peri': 'Цитата',
                'post': "}}"
              }
            }
          }
        }
      }
    }
  } );
  $('#wikiEditor-ui-toolbar .section-main').prepend($('#wikiEditor-ui-toolbar .group-extra'));
};

$( function() {
    if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
      if ($('body').hasClass('ns-0')) {
            mw.loader.using( 'user.options', function () {
                    if ( mw.user.options.get('usebetatoolbar') ) {
                            mw.loader.using( 'ext.wikiEditor', function () {
                                    toolbarAddCloseSectionButton();
                            } );
                    }
            } );
      }
    }
} );