LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-noteTA.js”的版本间差异
跳转到导航
跳转到搜索
小 |
小 |
||
第17行: | 第17行: | ||
var parse = function() { |
var parse = function() { |
||
api.get({ action: 'parse', contentmodel: 'wikitext', text: wikitext, prop: 'text', variant: mw.config.get( 'wgUserVariant' ), formatversion:2 }) |
|||
api.get({ |
|||
.then( function( results ) { |
|||
$dialog.html( results.parse.text ); |
|||
text: wikitext, |
|||
prop: 'text', |
|||
variant: mw.config.get( 'wgUserVariant' ) |
|||
}).then( function( results ) { |
|||
$dialog.html( results.parse.text['*'] ); |
|||
$dialog.dialog( 'option', 'width', Math.round( $( window ).width() * 0.8 ) ); |
$dialog.dialog( 'option', 'width', Math.round( $( window ).width() * 0.8 ) ); |
||
$dialog.dialog( 'option', 'position', 'center' ); |
$dialog.dialog( 'option', 'position', 'center' ); |
2020年9月8日 (二) 09:10的最新版本
// <nowiki> var noteTAViewer = function() { var api = new mw.Api(); var init = function() { var $dialog = $( '<div class="noteTA-dialog" />' ) .html( '<div class="mw-ajax-loader" style="margin-top: 48px;" />' ); $dialog.dialog( {title: wgULS( '字词转换', '字詞轉換' )} ); run( $dialog ); return $dialog; }; var run = function( $dialog ) { var wikitext = '', $dom = $( '.noteTA' ), actualTitle = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ); var parse = function() { api.get({ action: 'parse', contentmodel: 'wikitext', text: wikitext, prop: 'text', variant: mw.config.get( 'wgUserVariant' ), formatversion:2 }) .then( function( results ) { $dialog.html( results.parse.text ); $dialog.dialog( 'option', 'width', Math.round( $( window ).width() * 0.8 ) ); $dialog.dialog( 'option', 'position', 'center' ); $dialog.find( '.mw-collapsible' ).makeCollapsible(); }); }; var $noteTAtitle = $dom.find( '.noteTA-title' ), editlink = '<span style="float:right">[{{plainlinks|{{fullurl:' + actualTitle + '|action=edit}} 编辑}}]</span>'; if ( $noteTAtitle.length ) { var titleConv = $noteTAtitle.attr( 'data-noteta-code' ), titleDesc = $noteTAtitle.attr( 'data-noteta-desc' ); titleDesc = titleDesc ? '(' + titleDesc + ')' : ''; wikitext += '; 本文使用标题手工转换。' + editlink + '\n' + '* 转换标题为:-{D|' + titleConv + '}-' + titleDesc + '\n' + '* 实际标题为:-{R|' + actualTitle + '}-;当前显示为:-{|' + titleConv + '}-\n'; } var $noteTAgroups = $dom.find( '.noteTA-group > div' ); if( $noteTAgroups.length ) { $noteTAgroups.each( function() { var $this = $( this ), groupName = $this.attr( 'data-noteta-group' ); wikitext += '; {{#invoke:cGroupViewer|dialog|' + groupName + '}}\n'; }); } var $noteTAlocal = $dom.find( '.noteTA-local' ); if ( $noteTAlocal.length ) { wikitext += '; 本文使用全文手工转换。' + editlink + '\n'; var $noteTAlocals = $noteTAlocal.children(); $noteTAlocals.each( function() { var $this = $( this ), localConv = $this.attr( 'data-noteta-code' ), localDesc = $this.attr( 'data-noteta-desc' ); localDesc = localDesc ? '(' + localDesc + ')' : ''; wikitext += '# -{D|' + localConv + '}-' + localDesc + ' 当前显示为:-{' + localConv + '}-\n'; }); } parse(); }; var $this = $( '#mw-indicator-noteTA, #mw-mobile-noteTA' ), $dialog = null; $this.click( function() { if ( $dialog === null ) { $dialog = init(); } else { $dialog.dialog( 'open' ); } }); $(window).on('resize', function() { $dialog.dialog( 'option', 'width', Math.round( $( window ).width() * 0.8 ) ); }); }; mw.hook('wikipage.content').add( function ( $content ) { if( $( '#mw-indicator-noteTA, #mw-mobile-noteTA' ).length ) { noteTAViewer(); } }); // </nowiki>