Jump to content

User:Js/6tabs-vector.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function sixTabs() {

if (!window.sixTabsNames) {
	sixTabsNames = {
		'edit'       : 'commons/d/d9/Btn_edit.png',
		'viewsource' : 'commons/7/75/Page_white.png',
		'history'    : 'commons/thumb/2/26/Clock_simple.svg/20px-Clock_simple.svg.png',
		'addsection' : '+'
	};
}

//unselected left tab: append edit & hist
var	main = $('#left-navigation li:not(.selected)').slice(0,1).css('opacity','0.9');
if (!main.hasClass('new')) {
	var url = main.find('a').attr('href');
	dup('history'); dup('edit');
}
function dup(type) {
	var tab = main.clone(true).attr('id', main.attr('id')+'-'+type)
 		.insertAfter(main).css('opacity','0.6');
	tab.find('a').attr('href', url+'?action='+type).attr('title', type).removeAttr('accesskey');
	nameTab(tab, type);
}

//selected left tab:
main = $('#left-navigation li.selected').removeClass('selected');
if (main.hasClass('new')) { //... join with ca-edit on new page
	if ($('#ca-edit').hide().hasClass('selected')) { main.addClass('selected'); }
} else { //...join with ca-view ("Read"), copying href in case of FlaggedRevs
	if ($('#ca-view').hide().hasClass('selected')) { main.addClass('selected'); }
	main.find('a').attr('href', $('#ca-view').find('a').attr('href'));
}
//move existing tabs next to selected
function mv(id) {
	nameTab($('#ca-'+id).insertAfter(main), id);
}
mv('addsection'); mv('history'); mv('edit'); mv('viewsource'); mv('current');

function nameTab(tab, type) {
	var name = sixTabsNames[type] || type;
	if (!name) return;
	tab = tab.find('a').empty();
	if (/\.(png|svg|gif)$/.test(name)) 
		$('<img>')
		.attr('src','//upload.wikimedia.org/wikipedia/'+name)
		.attr('width','18').appendTo(tab);
	else tab.text(name);
}

}//

if (mw.config.get('skin')=='vector' && mw.config.get('wgNamespaceNumber')>=0) {
	$(sixTabs);
}