페미위키:개선요청의 토론 주제

3번째 줄: 3번째 줄:
그래서 시각편집기에 다음 동영상에서 보시는 것과 같은 메뉴가 추가되는 스크립트(붙임 1번)를 만들었습니다(동영상을 찍고 스크립트를 좀 더 수정해서 살짝 다르긴 합니다).
그래서 시각편집기에 다음 동영상에서 보시는 것과 같은 메뉴가 추가되는 스크립트(붙임 1번)를 만들었습니다(동영상을 찍고 스크립트를 좀 더 수정해서 살짝 다르긴 합니다).
<embedvideo service="vimeo">216290546</embedvideo>해당 스크립트를 [[미디어위키:common.js]]에 추가 요청드립니다.<br>{{글 숨김|붙임 1번}}
<embedvideo service="vimeo">216290546</embedvideo>해당 스크립트를 [[미디어위키:common.js]]에 추가 요청드립니다.<br>{{글 숨김|붙임 1번}}
<pre>function addCommentTemplateTool() {
<pre>//시각편집기에 {{주}} 입력 툴 넣기
//command name for registeration
function addCommentTemplateToolToVisualEditor() {
function commentTemplate() {}
  //'주'틀을 입력해 주는 커맨드 만들기
  function commentTemplate() {}
  function CommentTemplate() {
    CommentTemplate.parent.call( this, 'commentTemplate' );
  }
  OO.inheritClass( CommentTemplate, ve.ui.Command );


//Create and register command
  CommentTemplate.prototype.execute = function( surface ) {
function CommentTemplate() {
    var surfaceModel = surface.getModel(),
CommentTemplate.parent.call( this, 'commentTemplate' );
      //선택된 것이 있으면 뒤로 이동하고 틀을 추가
}
      widget = surfaceModel.getFragment().collapseToEnd().insertContent(
OO.inheritClass( CommentTemplate, ve.ui.Command );
      [
        {
          type: 'mwTransclusionInline',
          attributes: {
            mw: {
              parts: [
                {
                  template: {
                    target: {
                      href: '틀:주',
                      wt: ''
                    }
                  }
                }
              ]
            }
          }
        },
      { type: '/mwTransclusionInline' }
      ]
    );
    return true;
  };
  //만든 커맨드 등록
  ve.ui.commandRegistry.register( new CommentTemplate() );


CommentTemplate.prototype.execute = function( surface ) {
  //등록된 커맨드를 실행하는 툴 (메뉴) 만들기
var surfaceModel = surface.getModel(),
  function CommentTemplateTool() {
doc = surfaceModel.getDocument();
    CommentTemplateTool.parent.apply( this, arguments );
  }
var widget = surfaceModel.getFragment().collapseToEnd().insertContent(
  OO.inheritClass( CommentTemplateTool, ve.ui.Tool );
  [
    {
      type: 'mwTransclusionInline',
      attributes: {
        mw: {
          parts: [
            {
              template: {
                target: {
                  href: '틀:주',
                  wt: '주'
                }
              }
            }
          ]
        }
      }
    },
{ type: '/mwTransclusionInline' }
  ]
);
return true;
};


ve.ui.commandRegistry.register( new CommentTemplate() );
  CommentTemplateTool.static.name = 'commentTemplate';
  CommentTemplateTool.static.group = 'object';
  CommentTemplateTool.static.title = '부연 설명';
  CommentTemplateTool.static.icon = 'reference';
  CommentTemplateTool.static.commandName = 'commentTemplate';
  CommentTemplateTool.static.modelClasses = ve.ui.toolFactory.lookup('reference').static.modelClasses;
  CommentTemplateTool.static.autoAddToCatchall = false;


//Create, register and insert tool
  CommentTemplateTool.prototype.onUpdateState = function() {
function CommentTemplateTool() {
    CommentTemplateTool.parent.prototype.onUpdateState.apply( this, arguments );
CommentTemplateTool.parent.apply( this, arguments );
    this.setActive( false );
}
  };
OO.inheritClass( CommentTemplateTool, ve.ui.Tool );


CommentTemplateTool.static.name = 'commentTemplate';
  //만든 툴 등록
CommentTemplateTool.static.group = 'object';
  ve.ui.toolFactory.register( CommentTemplateTool );
CommentTemplateTool.static.title = '부연 설명';
 
CommentTemplateTool.static.icon = 'reference';
  //등록된 툴을 메뉴에 넣기
CommentTemplateTool.static.commandName = 'commentTemplate';
  var toolbarGroups = ve.init.mw.Target.static.toolbarGroups;
CommentTemplateTool.static.modelClasses = ve.ui.toolFactory.lookup('reference').static.modelClasses;
  toolbarGroups[ 4 ].include.push( 'commentTemplate' );
CommentTemplateTool.static.autoAddToCatchall = false;
 
 
  //기존 툴 레이블 변경
CommentTemplateTool.prototype.onUpdateState = function() {
  toolbarGroups[ 4 ].label='각주';
CommentTemplateTool.parent.prototype.onUpdateState.apply( this, arguments );
  ve.ui.toolFactory.lookup('reference').static.title='출처';
this.setActive( false );
  ve.ui.toolFactory.lookup('reference/existing').static.title='출처 재사용';
};
 
ve.ui.toolFactory.register( CommentTemplateTool );
var toolbarGroups = ve.init.mw.Target.static.toolbarGroups;
toolbarGroups[ 4 ].label='각주';
toolbarGroups[ 4 ].include.push( 'commentTemplate' );
ve.ui.toolFactory.lookup('reference').static.title='출처';
ve.ui.toolFactory.lookup('reference/existing').static.title='출처 재사용';
}
}
//Initialize
mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init' ).done( function() {
mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init' ).done( function() {
mw.libs.ve.addPlugin( function() {
  mw.libs.ve.addPlugin( function() {
mw.loader.using( [ 'ext.visualEditor.core' ] ).done( function() {
    mw.loader.using( [ 'ext.visualEditor.core' ] ).done( function() {
addCommentTemplateTool();
        addCommentTemplateToolToVisualEditor();
} );
    } );
} );
  } );
} );
} );


var customizeToolbar = function () {
//위키편집기에 {{주}} 입력 툴 넣기
/* 왠지 작동 안함
var addCommentTemplateToolToWikiEditor = function () {
$( '#wpTextbox1' ).on( 'wikiEditor-toolbar-buildSection-main', function( event, section ) {
  //툴바에 {{주|}}로 감싸주는 툴 추가
delete section.groups.insert.tools.reference["labelMsg"];
  $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section.groups.insert.tools.reference.label = '출처';
    'section': 'main',
} );*/
    'group': 'insert',
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    'tools': {
'section': 'main',
      'comment': {
'group': 'insert',
        label: '부연 설명',
'tools': {
        type: 'button',
'comment': {
        icon: {},
label: '부연 설명',
        offset: [2, -1798],
type: 'button',
        action: {
icon: {
          type: 'encapsulate',
sv: 'insert-reference.png'
          options: {
},
            pre: "{{주|",
offset:{
            peri: "여기에 각주 내용을 적어 주세요",
sv: [2, -1798]
            post: "}}"
},
          }
action: {
        }
type: 'encapsulate',
      }
options: {
    }
pre: "{{주|",
  } );
post: "}}"
}
}
}
}
} );
};
};
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
mw.loader.using( 'user.options' ).then( function () {
  mw.loader.using( 'user.options' ).then( function () {
if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
    if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
$.when(
      $.when(
mw.loader.using( 'ext.wikiEditor.toolbar' ), $.ready
        mw.loader.using( 'ext.wikiEditor.toolbar' ), $.ready
).then( customizeToolbar );
      ).then( addCommentTemplateToolToWikiEditor );
}
    }
} );
  } );
}
}


//위키편집기 기존 메뉴 이름 바꾸기(왠지 작동 안함)
//https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization#Modifying_things
// $( '#wpTextbox1' ).on( 'wikiEditor-toolbar-buildSection-main', function( event, section ) {
//  console.log('on wikiEditor-toolbar-buildSection-main');
//  delete section.groups.insert.tools.reference.labelMsg;
//  section.groups.insert.tools.reference.label = '출처';
//  //배열 내용은 확인해보면 바뀌어 있는데 정작 메뉴는 바뀌지 않습니다.
// } );
</pre>{{글 숨김 끝}}
</pre>{{글 숨김 끝}}


(6/13 추가)원본편집기 편집 도구 모음에도 추가했습니다.
(6/13 추가)원본편집기 편집 도구 모음에도 추가했습니다.