跳转到内容

User:燃灯/foldRef.js

维基百科,自由的百科全书

这是本页的一个历史版本,由燃灯留言 | 贡献2018年9月24日 (一) 23:59 (维护清理)编辑。这可能和当前版本存在着巨大的差异。

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
importStylesheet( 'User:燃灯/foldRef.css' );
$(function() {
	
	// for article space only 
	if (mw.config.get('wgNamespaceNumber') !== 0) {
		return;
	}
	
	// target at the following classes / IDs
	var toFold = $('.reflist, .refbegin, #references-NoteFoot');
	
	// if greater than 80% of the viewport height, fold the references
	var viewPortHeight = window.innerHeight;
	for (i = 0; i < toFold.length; i++){
		var currentToFoldElement = $(toFold[i]);
		if (currentToFoldElement.height() > viewPortHeight * 0.8) {
			var newRefFolder = $('<div class="rd-ref-folded"></div>');
			newRefFolder.insertBefore(currentToFoldElement);
			currentToFoldElement.appendTo(newRefFolder);
			
			// add an expand button at the bottom
			newRefFolder.after('<div class="rd-ref-expand-button">展开</div>');
		}
	}
	
	// attach event listener to the expand buttons
	$('.rd-ref-expand-button').click( function(){
		$(this).parent('.rd-ref-folded').removeClass('rd-ref-folded');
		$(this).remove();
		});
});