LLWiki正在建设中,欢迎加入我们!
MediaWiki:Gadget-stickyHeading.js
跳转到导航
跳转到搜索
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
// 直接由ResourceLoader调用,因此不可使用ES6语法 "use strict"; /*global mw, $*/ const nsid = mw.config.get( 'wgNamespaceNumber' ), pagename = mw.config.get('wgPageName'), contentModel = mw.config.get( 'wgPageContentModel' ), skin = mw.config.get('skin'), gadgets = mw.gadgets || {}, stickyHeading = gadgets.stickyHeading || {}, ns = stickyHeading.namespace || [], mode = stickyHeading.mode, collapse = (stickyHeading.collapse !== false); if ( (ns.includes( nsid ) || nsid % 2 === 1 || pagename == "LLWiki:互助客棧") && contentModel == 'wikitext' && ((skin == 'vector' && mode != 'mobile') || (skin == 'minerva' && mode != 'desktop')) ) { mw.hook( 'wikipage.content' ).add(function( $content ) { console.log('Hook: wikipage.content, 开始添加粘性章节标题'); $content.addClass( 'stickyHeading' ); const headings = $content.find( '.mw-parser-output > h2' ); headings.toArray().reverse().forEach(function(ele) { $('<div>').addClass( 'section-container' ).insertBefore(ele) .append( $(ele).nextAll( ':not(.section-container, #toc)' ).add(ele) ); }); if (!collapse || skin == 'minerva') { return; } $content.addClass( 'collapseHeading' ); const icon = $('<i class="mw-ui-icon-before mw-ui-icon-small mw-ui-icon mw-ui-icon-collapse"></i>'); headings.prepend( icon ).on('click', function(e) { if ( $(e.target).is('a') ) { return; } const self = $(this); self.nextAll().toggleClass( 'sec-hide' ); self.children().first().toggleClass( 'mw-ui-icon-collapse mw-ui-icon-expand' ); }); }); } // [[category:作为模块的小工具]] [[category:讨论工具]] [[category:桌面版小工具]] [[category:手机版小工具]] [[category:默认开启的小工具]] // {{DEFAULTSORT:stickyHeading.js}}