( function( $, mw ) { $( function() {
var api = null;
var init = function( hash ) {
var $dialog = $( '<div class="noteTA-dialog" />' );
$dialog.html( '<div class="mw-ajax-loader" style="margin-top: 48px;" />' );
$dialog.dialog( {
title: wgULS( '字词转换', '字詞轉換' )
} );
api = new mw.Api();
run( $dialog, hash );
return $dialog;
}, run = function( $dialog, hash ) {
var wikitext = '';
var $dom = $( '#noteTA-' + hash );
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' ).replace( /_/g, ' ' ) + '}-;当前显示为:-{' + titleConv + '}-\n';
}
var $noteTAgroups = $dom.find( '.noteTA-group > *[data-noteta-group]' );
if ( $noteTAgroups.length > 1 ) {
collapse = true;
}
$noteTAgroups.each( function() {
var $this = $( this );
if ( $this.attr( 'data-noteta-group' ) == '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( '*[data-noteta-code]' );
$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 += '{{noteTA/footer}}';
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' ).on( 'click.mw-collapse', function( e ) {
var $collapsibleContent = $( this ).parent( '.mw-collapsible' ).find( '.mw-collapsible-content' );
setTimeout( function() {
$collapsibleContent.promise().done( function() {
$dialog.dialog( 'option', 'position', 'center' );
} );
}, 0 );
} );
}
$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' )
.each( function() {
var $dialog = null;
var $this = $( this );
var hash = $this.attr( 'id' ).replace( /^noteTA-topicon-/, '' );
$this.click( function() {
if ( $dialog === null ) {
$dialog = init( hash );
} else {
$dialog.dialog( 'open' );
}
} );
} );
} ); } )( jQuery, mediaWiki );