MediaWiki:Gadget-flashAnchored.js

来自Terraria Wiki
跳到导航 跳到搜索

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
window.onhashchange = function() {
	try{
	var hash = decodeURI(window.location.hash.replace(/\./g,'\\.'));
	flash($(hash));
	}catch(e){}
}

if (window.location.hash.length > 0) {
	window.onhashchange();
} 




function findFlashable($element) {
	var flashable = [ 'tr', 'h1', 'h2', 'h3', 'h4', 'h5', 'li', 'div' ];

	if ($.inArray($element.prop('tagName'), flashable) < 0) { 
		var $newElement;

		$.each(flashable, function(_, val) {
			$newElement = $element.closest(val);

			if ($newElement.length > 0) {
				return false;
			}
		});

		return $newElement;
	}

	return $element;
}

function flash($element) {
	// Check if the element is suitable for flashing, otherwise find a suitable parent 
	$element = findFlashable($element);

	// Reset any existing flashed elements
	$('.flash-anchored').removeClass("flash-anchored");

	$element.addClass("flash-anchored");
}