User:Supadawg/util.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Supadawg/util. |
function createXMLHTTP( method, uri, callback, options )
{
var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest()
: window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP")
: null;
if ( xmlhttp ) {
xmlhttp.onreadystatechange = callback;
xmlhttp.open( method, uri, true );
if ( options && options.headers )
for ( var key in options.headers )
xmlhttp.setRequestHeader( key, options.headers[key] );
var body = null;
if ( options && options["body"] )
body = options["body"];
xmlhttp.send( body );
}
return xmlhttp;
}
function createNode( parent, type, attrs, options )
{
var doc = (options && options.doc) ? options.doc : document;
var node = doc.createElement( type );
for ( var attr in attrs )
node.setAttribute( attr, attrs[attr] );
if ( parent )
node = parent.appendChild( node );
return node;
}
function insertAfter( newNode, node )
{
if ( node.nextSibling )
node.parentNode.insertBefore( newNode, node.nextSibling );
else
node.parentNode.appendChild( newNode );
}
function clearChildren( node )
{
while ( node.childNodes.length > 0 )
node.removeChild( node.childNodes[0] );
}
function removeNode( node )
{
if ( node.parentNode )
node.parentNode.removeChild( node );
}
// Prototype JavaScript framework, version 1.4.0
// (c) 2005 Sam Stephenson <sam@conio.net>
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}