( function( $, mw ) { $( function() {
var $dialog = null;
var api = null;
var init = function() {
$dialog = $( '<div id="noteTA-dialog" />' );
$dialog.html( '<div class="mw-ajax-loader" style="margin-top: 48px;" />' );
$dialog.dialog( {
title: wgULS( '字词转换', '字詞轉換' )
} );
api = new mw.Api();
run();
}, run = function() {
var wikitext = '';
var $dom = $( '#noteTA' );
var collapse = true;
var $noteTAtitle = $dom.find( '#noteTA-title' );
if ( $noteTAtitle.length ) {
var titleConv = decodeURIComponent( $noteTAtitle.attr( 'data-noteta-code' ).replace(/\+/g, '%20') );
var titleDesc = $noteTAtitle.attr( 'data-noteta-desc' );
if ( titleDesc ) {
titleDesc = '(' + decodeURIComponent( titleDesc.replace(/\+/g, '%20') ) + ')';
} else {
titleDesc = '';
}
wikitext += '<span style="float: right;">{{edit|' + mw.config.get( 'wgPageName' ) + '|section=0}}</span>\n';
wikitext += '; 本文使用[[Help:中文维基百科的繁简、地区词处理#條目標題|标题手工转换]]\n';
wikitext += '* 转换标题为:-{D|' + titleConv + '}-' + titleDesc + '\n';
wikitext += '* 实际标题为:-{' + mw.config.get( 'wgPageName' ) + '}-;当前显示为:-{' + titleConv + '}-\n';
}
var $noteTAgroups = $dom.find( '#noteTA-group > *[id^="noteTA-group-"]' );
if ( $noteTAgroups.length > 1 ) {
collapse = true;
}
$noteTAgroups.each( function() {
var $this = $( this );
if ( $this.hasClass( 'noteTA-missing' ) ) {
wikitext += '; 本文使用的公共转换组“' + $this.attr( 'data-noteta-group' ) + '”尚未创建\n';
wikitext += '* {{edit|Template:CGroup/' + $this.attr( 'data-noteta-group' ) + '|创建公共转换组“' + $this.attr( 'data-noteta-group' ) + '”}}\n';
} else {
wikitext += '{{CGroup/' + $this.attr( 'data-noteta-group' ) + '}}\n';
}
} );
var $noteTAlocal = $dom.find( '#noteTA-local' );
if ( $noteTAlocal.length ) {
collapse = true;
wikitext += '<span style="float: right;">{{edit|' + mw.config.get( 'wgPageName' ) + '|section=0}}</span>\n';
wikitext += '; 本文使用[[Help:中文维基百科的繁简、地区词处理#控制自动转换的代碼|全文手工转换]]\n';
var $noteTAlocals = $noteTAlocal.children( '*[id^="noteTA-local-"]' );
$noteTAlocals.each( function() {
var $this = $( this );
var localConv = decodeURIComponent( $this.attr( 'data-noteta-code' ).replace(/\+/g, '%20') );
var localDesc = $this.attr( 'data-noteta-desc' );
if ( localDesc ) {
localDesc = '(' + decodeURIComponent( localDesc.replace(/\+/g, '%20') ) + ')';
} else {
localDesc = '';
}
wikitext += '* -{D|' + localConv + '}-' + localDesc + '当前显示为:-{' + localConv + '}-\n';
} );
}
// Maybe move to a template
wikitext += '----\n';
wikitext += '; [[Help:中文维基百科的繁简、地区词处理|字词转换]]说明\n';
wikitext += ': 字詞轉換是中文维基的一項自動轉換,目的是通過-{zh-hans:计算机程序; zh-hant:電腦程式}-自動消除繁简、地区词等不同<strong>用字模式</strong>的差異,以達到閱讀方便。字詞轉換包括全局轉換和手動轉換,本說明所使用的标题转换和全文转换技術,都屬於手動轉換。\n';
wikitext += ': 如果您想对我们的字词转换系统提出一些改进建议,或者提交应用面更广的转换([[中文维基百科]]全站乃至[[MediaWiki]]软件),或者报告转换系统的错误,请前往[[Wikipedia:字词转换请求或候选]]发表您的意见。\n';
var parse = function() {
api.post( {
action: 'parse',
title: 'Template:CGroup/-',
text: wikitext,
prop: 'text',
variant: mw.config.get( 'wgUserVariant' )
}, {
ok: function( results ) {
$dialog.html( results.parse.text['*'] );
if ( collapse ) {
$dialog.find( '.mw-collapsible' ).makeCollapsible();
$dialog.find( '.mw-collapsible-toggle a' ).on( 'click.mw-collapse', function( e ) {
setTimeout( function() {
$( this ).parent( '.mw-collapsible' ).find( '.mw-collapsible-content' ).promise().done( function() {
$dialog.dialog( 'option', 'position', 'center' );
} );
}, 100 );
} );
}
$dialog.dialog( 'option', 'width', Math.round( $( window ).width() * 0.8 ) );
$dialog.css( 'max-height', Math.round( $( window ).height() * 0.8 ) + 'px' );
$dialog.dialog( 'option', 'position', 'center' );
},
err: parse
} );
};
parse();
};
$( '#noteTA-topicon' )
.css( 'cursor', 'pointer' )
.click( function() {
if ( $dialog == null ) {
init();
} else {
$dialog.dialog( 'open' );
}
} );
} ); } )( jQuery, mediaWiki );