跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
MediaWiki帮助
中医百科
搜索
搜索
登录
个人工具
登录
深色模式
查看“MediaWiki:Gadget-ExcerptTree.js”的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
清除缓存
常规
链入页面
相关更改
特殊页面
页面信息
页面值
←
MediaWiki:Gadget-ExcerptTree.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
/** * ExcerptTree enables navigation of excerpt trees * Documentation: https://www.mediawiki.org/wiki/ExcerptTree * License: GNU General Public License (http://www.gnu.org/licenses/gpl.html) * Author: Sophivorus */ var ExcerptTree = { /** * Initialization script */ init: function () { $( '.ExcerptTree' ).show(); $( '.ExcerptTree li' ).each( ExcerptTree.addChildren ); }, addChildren: function () { var node = $( this ), title = $( node ).children( 'a' ).text(); ExcerptTree.getContent( title ).done( function ( data ) { if ( data.query.pages[0].missing ) { return; } var content = data.query.pages[0].revisions[0].slots.main.content; names = mw.config.get( 'excerpt-templates' ) || [ 'Excerpt' ], regexp = new RegExp( '{{ *(?:' + names.join( '|' ) + ') *\\| *([^}]+) *}}', 'gi' ), matches = [ ...content.matchAll( regexp ) ]; if ( matches.length ) { ExcerptTree.addButton( node ); var list = $( '<ul>' ).hide().data( 'virgin', true ); matches.forEach( function ( match ) { var params = match[1].split( '|' ).filter( function ( param ) { return /=/.test( param ) === false; // Remove all named params } ); var title = params[0].split( '#' )[0]; title = title.charAt(0).toUpperCase() + title.slice(1); // Capitalize the title var section = params[0].split( '#' )[1] || params[1]; var text = section ? title + ' § ' + section : title; var href = mw.util.getUrl( ( section ? title + '#' + section : title ) ); var link = $( '<a>', { 'href': href } ).text( text ); var item = $( '<li>' ).html( link ); list.append( item ); } ); node.append( list ); } } ); }, /** * Add a clickable right-arrow to the given node */ addButton: function ( node ) { var button = $( '<span>' ).text( '►' ).css( { 'cursor': 'pointer', 'position': 'absolute', 'left': '-1em' } ); node.css( { 'list-style': 'none', 'position': 'relative' } ).prepend( button ); button.click( node, ExcerptTree.toggleChildren ); }, toggleChildren: function ( event ) { var node = event.data, button = $( node ).children( 'span' ), list = $( node ).children( 'ul' ), virgin = list.data( 'virgin' ); list.toggle(); if ( virgin ) { list.data( 'virgin', false ); list.children( 'li' ).each( ExcerptTree.addChildren ); button.text( '▼' ); } else { if ( list.is( ':visible' ) ) { button.text( '▼' ); } else { button.text( '►' ); } } }, getContent: function ( title ) { var api = new mw.Api(); return api.get( { titles: title, action: 'query', formatversion: 2, prop: 'revisions', rvprop: 'content', rvslots: 'main', redirects: true } ); } }; mw.loader.using( 'mediawiki.api', ExcerptTree.init );
该页面使用的模板:
Template:*(?:' + names.join( '
(
查看源代码
)
返回
MediaWiki:Gadget-ExcerptTree.js
。
开关有限宽度模式