MediaWiki:Gadget-btm-actions.js

Fra Wikipedia, den frie encyklopædi
/**
 * Copy upper tabs (actions) to bottom
 * Works for IE6+, FF2+... (see also [[MediaWiki:Gadget-btm-actions.css]])
 *
 * Copyright:  ©2008 Maciej Jaros (pl:User:Nux, en:User:EcceNux)
 * Licencja:  GNU General Public License v2
 * https://opensource.org/licenses/gpl-license.php
 * Version: 1.0.2
 */
function copyUpperActions(output_id)
{
	var as = document.getElementById('p-cactions').getElementsByTagName('div')[0].getElementsByTagName('a');
 
	//
	// create new tabs element (bottom actions bar)
	var tabs = document.createElement('div');
	tabs.id = output_id;
	tabs.className = 'noprint';
	var stabs = document.createElement('div');
	stabs.id = 'post-'+output_id;	// for proper width:100% handling
	tabs.appendChild(stabs);
 
	//
	// copy
	for (var i=0; i<as.length; i++)
	{
		var nel = document.createElement('a');
		nel.title = as[i].title;
		nel.innerHTML = as[i].innerHTML.toLowerCase();	// not sure why is this needed
 
		// normal browser
		//nel.href = as[i].href;
		// you just got to love IE...
		nel.href = as[i].parentNode.innerHTML.replace(/^.+ href=(["'])([^"']+)\1.+$/g,'$2').replace(/&amp;/g,'&');
 
		// copy class and id from <li>
		if (as[i].parentNode.nodeName.toLowerCase()=='li')
		{
			if (as[i].parentNode.id)
			{
				nel.id = output_id + '-' + as[i].parentNode.id;
			}
			if (as[i].parentNode.className)
			{
				nel.className = as[i].parentNode.className;
			}
		}
		stabs.appendChild(nel);
	}
 
	//
	// done
	return tabs;
}
 
function copyUpperActionsInit() {
	var content = document.getElementById('content');
	if (content && content.offsetHeight>650)
	{
		var tabs;
		tabs = copyUpperActions('btm-actions');
		columnContent = document.getElementById('column-content');
		if(columnContent){
			columnContent.appendChild(tabs);
		}
	}
}
$(copyUpperActionsInit);