“MediaWiki:Common.js”的版本间的差异

来自科学ADV中文wiki
跳到导航 跳到搜索
第80行: 第80行:
 
         if (!/^\d+$/.test(id)) return self.css('color', 'red').text('Error in outchain music data: Invalid id.');
 
         if (!/^\d+$/.test(id)) return self.css('color', 'red').text('Error in outchain music data: Invalid id.');
 
         if (!/^\d+$/.test(type)) return self.css('color', 'red').text('Error in outchain music data: Invalid type.');
 
         if (!/^\d+$/.test(type)) return self.css('color', 'red').text('Error in outchain music data: Invalid type.');
var source1 = '<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?auto=1&height=66&';
+
var source1 = '<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?auto=0&height=66&';
 
var source2 = 'type=' + type + '&id=' + id;
 
var source2 = 'type=' + type + '&id=' + id;
 
var source3 = '"></iframe>';
 
var source3 = '"></iframe>';

2020年5月25日 (一) 15:17的版本

// richtab

function richTabSetup( $content ) {
	$(".richtab > li > span > a").click(function(e) {
	    e.preventDefault();
		var richtab = $(this).closest(".richtab");
		var richtab_current = $(this).closest(".richtab > li");
		richtab.children().removeClass('active');
		richtab_current.addClass('active');
		var richtab_contents = richtab.next('.richtab-content');
		richtab_contents.children().removeClass('active');
		var richtab_index = richtab_current.prevAll().length;
	    var richtab_active_content = richtab_contents.children()[richtab_index];
	    $(richtab_active_content).addClass('active');
	})
}
mw.hook( 'wikipage.content' ).add( richTabSetup );

// 折叠支持

function makeCollapsibleMwCollapsible( $content ) {
	var $tables = $content
		.find( 'table.collapsible:not(.mw-collapsible)' )
		.addClass( 'mw-collapsible' );

	$.each( $tables, function ( index, table ) {
		// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
		if ( $( table ).hasClass( 'collapsed' ) ) {
			$( table ).addClass( 'mw-collapsed' );
			// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
		}
	} );
	if ( $tables.length > 0 ) {
		mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
			$tables.makeCollapsible();
		} );
	}
}
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );

function mwCollapsibleSetup( $collapsibleContent ) {
	var $element,
		$toggle,
		autoCollapseThreshold = 2;
	$.each( $collapsibleContent, function ( index, element ) {
		$element = $( element );
		if ( $element.hasClass( 'collapsible' ) ) {
			$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
		}
		if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
			$element.data( 'mw-collapsible' ).collapse();
		} else if ( $element.hasClass( 'innercollapse' ) ) {
			if ( $element.parents( '.outercollapse' ).length > 0 ) {
				$element.data( 'mw-collapsible' ).collapse();
			}
		}
		// because of colored backgrounds, style the link in the text color
		// to ensure accessible contrast
		$toggle = $element.find( '.mw-collapsible-toggle' );
		if ( $toggle.length ) {
			// Make the toggle inherit text color
			if ( $toggle.parent()[ 0 ].style.color ) {
				$toggle.find( 'a' ).css( 'color', 'inherit' );
			}
		}
	} );
}

mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );

// 外链音乐-网易云音乐

function outChainMusic163Setup( $content ) {
	var $players = $content
		.find( '.outchainmusic-163' )
	
	$.each( $players, function ( index, player ) {
		var id = player.dataset.id;
        var type = player.dataset.type;
        if (!/^\d+$/.test(id)) return self.css('color', 'red').text('Error in outchain music data: Invalid id.');
        if (!/^\d+$/.test(type)) return self.css('color', 'red').text('Error in outchain music data: Invalid type.');
		var source1 = '<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?auto=0&height=66&';
		var source2 = 'type=' + type + '&id=' + id;
		var source3 = '"></iframe>';
		var source = source1 + source2 + source3;
		$(player).empty().append(source);
	});
}

mw.hook( 'wikipage.content' ).add( outChainMusic163Setup );