MediaWiki:Common.js/Core.js

/** Namespace constants */ var NS_MEDIA         = -2, NS_SPECIAL       = -1, NS_MAIN          = 0, NS_TALK          = 1, NS_USER          = 2, NS_USER_TALK     = 3, NS_PROJECT       = 4, NS_PROJECT_TALK  = 5, NS_IMAGE         = 6, NS_IMAGE_TALK    = 7, NS_MEDIAWIKI     = 8, NS_MEDIAWIKI_TALK = 9, NS_TEMPLATE      = 10, NS_TEMPLATE_TALK = 11, NS_HELP          = 12, NS_HELP_TALK     = 13, NS_CATEGORY      = 14, NS_CATEGORY_TALK = 15, NS_ARTICLE       = 100, NS_ARTICLE_TALK  = 101, NS_PROPOSAL      = 102, NS_PROPOSAL_TALK = 103; var DEFAULT_USER_LANGUAGE = "en", FALLBACK_USER_LANGUAGE = "en"; /**	Here users can apply display settings for navigation frames by class name. Examples: // frames with the class “user-bigbadframe” should be hidden by default myElementsDisplay["bigbadframe"] = false; // frames with the class “user-important” should be visible by default myElementsDisplay["important"] = true; var myElementsDisplay = {}; /**	Replaces the scope in a function with the object’s one. Based on definition from the Prototype framework (http://prototype.conio.net/). Function.prototype.bind = function(object) { var __method = this; return function { return __method.apply(object, arguments); } } /** Trim leading chars (or white-spaces) */ String.prototype.ltrim = function(chars) { var s = typeof chars == "undefined" ? "\s" : chars; return this.replace(new RegExp("^[" + s + "]+", "g"), ""); } /** Trim ending chars (or white-spaces) */ String.prototype.rtrim = function(chars) { var s = typeof chars == "undefined" ? "\s" : chars; return this.replace(new RegExp("[" + s + "]+$", "g"), ""); } /** Trim leading and ending white-spaces */ String.prototype.trim = function { return this.ltrim.rtrim; } /** Checks if a value exists in an array */ function inArray(val, arr) { var len = arr.length; for (var i = 0 ; i < len ; i++) { if (arr[i] === val) { return true; }	}	return false; } /** Set display mode for all elements with a given class name */ function setElementsDisplayByClassName(className, display) { var els = getElementsByClassName(document, "*", className); for (var i = 0; i < els.length; i++) { els[i].style.display = display; } } /** Hide all elements with a given class name */ function hideElementsByClassName(className) { setElementsDisplayByClassName(className, "none"); } /** Show all elements with a given class name */ function showElementsByClassName(className) { setElementsDisplayByClassName(className, ""); } /** Checks if an element belongs to a given CSS class */ function hasClass(elem, className) { return elem.className.indexOf( className ) != -1; }