MediaWiki:Common.js

From IRC Wiki
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// Do Magic Here
//User Boards
function toggle_user( user_id ) {
	if( YAHOO.util.Dom.hasClass( 'user-' + user_id, 'blast-friend-selected' ) ) {
		YAHOO.util.Dom.replaceClass( 'user-' + user_id, 'blast-friend-selected', 'blast-friend-unselected' );
	} else if( YAHOO.util.Dom.hasClass( 'user-' + user_id, 'blast-friend-unselected' ) ) {
		YAHOO.util.Dom.replaceClass( 'user-' + user_id, 'blast-friend-unselected', 'blast-friend-selected' );
	}
	if( YAHOO.util.Dom.hasClass( 'user-' + user_id, 'blast-foe-selected' ) ) {
		YAHOO.util.Dom.replaceClass( 'user-' + user_id, 'blast-foe-selected', 'blast-foe-unselected' );
	} else if( YAHOO.util.Dom.hasClass( 'user-' + user_id, 'blast-foe-unselected' ) ) {
		YAHOO.util.Dom.replaceClass( 'user-' + user_id, 'blast-foe-selected', 'blast-foe-unselected' );
	}
}
function toggle_type( method, on, off ) {
	list = YAHOO.util.Dom.getElementsByClassName( ( ( method == 1 ) ? off : on ), 'div', 'blast-friends-list' );
	for( x = 0; x <= list.length - 1; x++ ) {
		el = list[x];
		if( YAHOO.util.Dom.hasClass( el, on ) || YAHOO.util.Dom.hasClass( el, off ) ) {
			if( method == 1 ) {
				YAHOO.util.Dom.replaceClass( el, off, on );
			} else {
				YAHOO.util.Dom.replaceClass( el, on, off );
			}
		}
	}
}
function toggle_friends( method ) {
	toggle_type( method, 'blast-friend-selected', 'blast-friend-unselected' );
}
function toggle_foes( method ) {
	toggle_type( method, 'blast-foe-selected', 'blast-foe-unselected' );
}
function select_all() {
	toggle_friends( 1 );
	toggle_foes( 1 );
}
function unselect_all() {
	toggle_friends( 0 );
	toggle_foes( 0 );
}
submitted = 0;
function send_messages() {
	if( submitted == 1 ) {
		return 0;
	}
	submitted = 1;
	selected = 0;
	user_ids_to = '';
	list = YAHOO.util.Dom.getElementsByClassName( 'blast-friend-selected', 'div', 'blast-friends-list' );
	for( x = 0; x <= list.length - 1; x++ ) {
		el = list[x];
		selected++;
		user_id = el.id.replace( 'user-', '' );
		user_ids_to += ( ( user_ids_to ) ? ',' : '' ) + user_id;
	}
	list = YAHOO.util.Dom.getElementsByClassName( 'blast-foe-selected', 'div', 'blast-friends-list' );
	for( x = 0; x <= list.length - 1; x++ ) {
		el = list[x];
		selected++;
		user_id = el.id.replace( 'user-', '' );
		user_ids_to += ( ( user_ids_to ) ? ',' : '' ) + user_id;
	}
	if( selected === 0 ) {
		alert( 'Please select at least one person' );
		submitted = 0;
		return 0;
	}
	if( !document.getElementById('message').value ) {
		alert( 'Please enter a message' );
		submitted = 0;
		return 0;
	}
	document.getElementById('ids').value = user_ids_to;

	document.blast.message.style.color = '#ccc';
	document.blast.message.readOnly = true;
	document.getElementById('blast-friends-list').innerHTML = 'Sending messages...';
	document.blast.submit();
}

//User Gifts
var selected_gift = 0;
function selectGift( id ) {
	// Un-select previously selected gift
	if( selected_gift ) {
		YAHOO.util.Dom.removeClass( 'give_gift_' + selected_gift, 'g-give-all-selected' );
	}
	// Select new gift
	YAHOO.util.Dom.addClass( 'give_gift_' + id, 'g-give-all-selected' );
	selected_gift = id;
}
function highlightGift( id ) {
	YAHOO.util.Dom.addClass( 'give_gift_' + id, 'g-give-all-highlight' );
}
function unHighlightGift( id ) {
	YAHOO.util.Dom.removeClass( 'give_gift_' + id, 'g-give-all-highlight' );
}
function sendGift() {
	if( !selected_gift ) {
		alert( 'Please select a gift' );
		return false;
	}
	document.gift.gift_id.value = selected_gift;
	document.gift.submit();
}
function chooseFriend( friend ) {
	window.location = wgServer + wgScript + '?title=Special:GiveGift' + '&user=' + friend;
}

/**
 * JavaScript used on Special:UpdateProfile
 * Displays the "State" dropdown menu if selected country is the United States
 */
var countries = new Array();
countries[0] = {
	country: 'United States',
	name: 'State',
	sections: [
		'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado',
		'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho',
		'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
		'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
		'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada',
		'New Hampshire', 'New Jersey', 'New Mexico', 'New York',
		'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon',
		'Pennsylvania', 'Puerto Rico', 'Rhode Island', 'South Carolina',
		'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia',
		'Washington', 'Washington, D.C.', 'West Virginia', 'Wisconsin', 'Wyoming'
	]
};
function displaySection( id, country, section ) {
	country_id = -1;
	for( x = 0; x <= countries.length-1; x++ ) {
		if( country == countries[x].country ) {
			country_id = x;
		}
	}
	section_select = '';
	if( countries[country_id] ) {
		document.getElementById( id + '_label' ).innerHTML = countries[country_id].name;
		section_select += '<select class="profile-form" name="' + id + '" id="' + id + '"><option></option>';
		for( x = 0; x <= countries[country_id].sections.length-1; x++ ) {
			section_select += '<option value="' + countries[country_id].sections[x] + '"' +
				( ( countries[country_id].sections[x] == section ) ? ' selected="selected"' : '' ) + '>' + countries[country_id].sections[x] + '</option>';
		}
		section_select += '</select>';
	}
	document.getElementById( id + '_form' ).innerHTML = section_select;
}

/**
 * JavaScript functions used by UserProfile
 */
var posted = 0;
function send_message() {
	if( document.getElementById('message').value && !posted ) {
		posted = 1;
		sajax_request_type = 'POST';
		sajax_do_call( 'wfSendBoardMessage', [
			document.getElementById('user_name_to').value,
			encodeURIComponent( document.getElementById('message').value ),
			document.getElementById('message_type').value,
			10 ], function( originalRequest ) {
				document.getElementById('user-page-board').innerHTML = originalRequest.responseText;
				posted = 0;
				document.getElementById('message').value = '';
			}
		);
	}
}
function delete_message( id ) {
	if( confirm( 'Are you sure you want to delete this message?' ) ) {
		sajax_request_type = 'POST';
		sajax_do_call( 'wfDeleteBoardMessage', [ id ], function( originalRequest ) {
			window.location.reload();
		} );
	}
}
var numReplaces = 0;
var replaceID = 0;
var replaceSrc = '';
var oldHtml = '';
function showUploadFrame() {
	document.getElementById( 'upload-container' ).style.display = 'block';
	document.getElementById( 'upload-container' ).style.visibility = 'visible';
}
function uploadError( message ) {
	document.getElementById('mini-gallery-' + replaceID).innerHTML = oldHtml;
	document.getElementById('upload-frame-errors').innerHTML = message;
	document.getElementById('imageUpload-frame').src = 'index.php?title=Special:MiniAjaxUpload&wpThumbWidth=75';
	document.getElementById( 'upload-container' ).style.display = 'block';
	document.getElementById( 'upload-container' ).style.visibility = 'visible';
}
function textError( message ) {
	document.getElementById( 'upload-frame-errors' ).innerHTML = message;
	document.getElementById( 'upload-frame-errors' ).style.display = 'block';
	document.getElementById( 'upload-frame-errors' ).style.visibility = 'visible';
}
function completeImageUpload() {
	document.getElementById( 'upload-frame-errors' ).style.display = 'none';
	document.getElementById( 'upload-frame-errors' ).style.visibility = 'hidden';
	document.getElementById('upload-frame-errors').innerHTML = '';
	oldHtml = document.getElementById('mini-gallery-' + replaceID).innerHTML;
	for( x = 7; x > 0; x-- ) {
		document.getElementById('mini-gallery-' + ( x ) ).innerHTML =
			document.getElementById('mini-gallery-' + ( x - 1 ) ).innerHTML.replace( 'slideShowLink(' + ( x - 1 ) + ')','slideShowLink(' + ( x ) + ')' );
	}
	document.getElementById('mini-gallery-0').innerHTML = '<a><img height="75" width="75" src="http://images.wikia.com/common/wikiany/images/ajax-loader-white.gif" alt="" /></a>';
	if( document.getElementById( 'no-pictures-containers' ) ) {
		document.getElementById( 'no-pictures-containers' ).style.display = 'none';
		document.getElementById( 'no-pictures-containers' ).style.visibility = 'hidden';
	}
	document.getElementById( 'pictures-containers' ).style.display = 'block';
	document.getElementById( 'pictures-containers' ).style.visibility = 'visible';
}
function uploadComplete( imgSrc, imgName, imgDesc ) {
	replaceSrc = imgSrc;
	document.getElementById('upload-frame-errors').innerHTML = '';
	var idOffset = -1 - numReplaces;
	document.getElementById('mini-gallery-0').innerHTML = '<a href=\"' + __image_prefix + imgName + '\">' + replaceSrc + '</a>';
	numReplaces += 1;
	document.getElementById('imageUpload-frame').src = 'index.php?title=Special:MiniAjaxUpload&wpThumbWidth=75&extra=' + numReplaces;
}
function slideShowLink( id ) {
	window.location = 'Image:' + id;
}
function doHover( divID ) {
	$El(divID).setStyle('backgroundColor', '#4B9AF6');
}
function endHover( divID ) {
	$El(divID).setStyle('backgroundColor', '');
}

/**
 * JavaScript for UserRelationship
 * Used on Special:ViewRelationshipRequests
 */
function requestResponse( response, id ) {
	document.getElementById( 'request_action_' + id ).style.display = 'none';
	document.getElementById( 'request_action_' + id ).style.visibility = 'hidden';
	sajax_request_type = 'POST';
	sajax_do_call( 'wfRelationshipRequestResponse', [ response, id ], function( request ) {
		document.getElementById( 'request_action_' + id ).innerHTML = request.responseText;
		YAHOO.widget.Effects.Appear( 'request_action_' + id, { duration:2.0 } );
	} );
}