Mediawiki>Bhsd |
imported>Irukaza |
第1行: |
第1行: |
| // 直接由ResourceLoader调用,因此不可使用ES6语法
| | <includeonly><span title="{{{2|}}}" class="heimu">{{{1}}}</span></includeonly><noinclude>{{ 萌百嵌入| 模 板: 黑幕}}</noinclude> |
| "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}}
| |