/* Small JS library containing stuff I use often. Author:, June 2009 License: Quadruple licensed GFDL, GPL, LGPL and Creative Commons Attribution 3.0 (CC-BY-3.0) Choose whichever license of these you like best :-)
Includes the following components: - Object enhancements (clone, merge) - String enhancements (trim, ...) - Array enhancements (JS 1.6) - Function enhancements (bind) - LAPI Most basic DOM functions: $ (getElementById), make - LAPI.Ajax Ajax request implementation, tailored for MediaWiki/WMF sites - LAPI.Browser Browser detection (general) - LAPI.DOM DOM helpers, including a cross-browser DOM parser - LAPI.WP MediaWiki/WMF-specific DOM routines - LAPI.Edit Simple editor implementation with save, cancel, preview (for WMF sites) - LAPI.Evt Event handler routines (general) - LAPI.Pos Position calculations (general)
// Global: importScript (from wiki.js, for MediaWiki:AjaxSubmit.js)
// Configuration: set this to the URL of your image server. The value is a string representation// of a regular expression. For instance, for Wikia, use "http://images\\d\\.wikia\\.nocookie\\.net".// Remember to double-escape the backslash.if (typeof (LAPI_file_store)
// Some basic routines, mainly enhancements of the String, Array, and Function objects.// Some taken from Javascript 1.6, some own.
/** Object enhancements ************/
// Note: adding these to the prototype may break other code that assumes that// has no properties at all.if (!Object.clone)
if (!Object.merge)
if (!Object.mergeSome)
if (!Object.mergeSet) /** String enhancements (Javascript 1.6) ************/
// Removes given characters from both ends of the string.// If no characters are given, defaults to removing whitespace.if (!String.prototype.trim)
// Removes given characters from the beginning of the string.// If no characters are given, defaults to removing whitespace.if (!String.prototype.trimLeft) if (!String.prototype.trimFront) String.prototype.trimFront = String.prototype.trimLeft; // Synonym
// Removes given characters from the end of the string.// If no characters are given, defaults to removing whitespace.if (!String.prototype.trimRight) if (!String.prototype.trimEnd) String.prototype.trimEnd = String.prototype.trimRight; // Synonym
/** Further String enhancements ************/
// Returns true if the string begins with prefix.if (!String.prototype.startsWith)
// Returns true if the string ends in suffixif (!String.prototype.endsWith)
// Returns true if the string contains s.if (!String.prototype.contains)
// Replace all occurrences of a string pattern by replacement.if (!String.prototype.replaceAll)
// Escape all backslashes and single or double quotes such that the result can// be used in Javascript inside quotes or double quotes.if (!String.prototype.stringifyJS)
// Escape all RegExp special characters such that the result can be safely used// in a RegExp as a literal.if (!String.prototype.escapeRE)
if (!String.prototype.escapeXML)
if (!String.prototype.decodeXML)
if (!String.prototype.capitalizeFirst)
if (!String.prototype.lowercaseFirst)
// This is actually a function on URLs, but since URLs typically are strings in// Javascript, let's include this one here, too.if (!String.prototype.getParamValue)
if (!String.getParamValue)
/** Function enhancements ************/
if (!Function.prototype.bind)
/** Array enhancements (Javascript 1.6) ************/
// Note that contrary to JS 1.6, we treat the thisObject as optional.// Don't add to the prototype, that would break for (var key in array) loops!
// Returns a new array containing only those elements for which predicate// is true.if (!Array.filter) if (!Array.select) Array.select = Array.filter; // Synonym
// Calls iterator on all elements of the arrayif (!Array.forEach)
// Returns true if predicate is true for every element of the array, false otherwiseif (!Array.every) if (!Array.forAll) Array.forAll = Array.every; // Synonym
// Returns true if predicate is true for at least one element of the array, false otherwise.if (!Array.some) if (!Array.exists) Array.exists = Array.some; // Synonym
// Returns a new array built by applying mapper to all elements.if (!Array.map)
if (!Array.indexOf)
if (!Array.lastIndexOf)
/** Additional Array enhancements ************/
if (!Array.remove)
if (!Array.contains)
if (!Array.flatten)
// Calls selector on the array elements until it returns a non-null object// and then returns that object. If selector always returns null, any also// returns null. See also Array.map.if (!Array.any)
// Return a contiguous array of the contents of source, which may be an array or pseudo-array,// basically anything that has a length and can be indexed. (E.g. live HTMLCollections, but also// Strings, or objects, or the arguments "variable".if (!Array.make)
if (typeof (window.LAPI)
if (typeof (LAPI.Browser)
if (typeof (LAPI.DOM)
if (typeof (LAPI.WP)