Wookieepedia:API

This is a documentation of the Wookieepedia reusable JavaScript file (MediaWiki:Functions.js). This file is site-independent and can be used on any Wikia wiki.

Plugging it in

 * Copy MediaWiki:Functions.js to your wiki.
 * Add the following to your MediaWiki:Common.js:

document.write(' ');


 * Add the following call to your first onload hook:

initFunctionsJS;

ContentLoader
Used by: requestComboFill, doPreload

This class encapsulates different implementations of XMLHttpRequest, hiding their complexities behind a (slightly) simpler API.

The primary purpose of the ContentLoader class is to fetch web pages as text (either HTML text or wikitext, which can be obtained on MediaWiki by adding the "action=raw" parameter). It can be also used to do POST requests, although on MediaWiki the usefulness of this feature is dubious.

Subject to the Same Origin Policy, which is hardcoded in modern web browsers (can only be used on the same wiki/subdomain, not across Wikia).

Even though slightly more high-level than XMLHttpRequest, it's still fairly low-level and should only be used by advanced users.

Constructor
constructor ContentLoader;

Creates a new ContentLoader object.

Public fields
[get] boolean cache;

Specifies whether caching is enabled. Default: true.

[set] function callback;

The function that gets called after the data arrive from the HTTP server. When it is called, "this" is the ContentLoader object. State can be stored and retrieved using its global fields. Usually, the code that sends the request creates new fields in the ContentLoader object to store the state, which is then retrieved in the callback.

[get] string text;

Used in the callback function to retrieve the HTML code or plaintext of the retrieved page.

[get] Document document;

Used in the callback function as the root element of the DOM tree if the retrieved page is an XML document.

Public methods
void enableCache(boolean cache = true);

Enables or disables caching. If the user calls this method, it must be done before send.

void send(string url, string postdata = null, string contentType = 'application/x-www-form-urlencoded');

Sends an HTTP request to the server and immediately returns without waiting for it to complete. When the request arrives, the callback function will be called.

The "url" parameter can be either an absolute address (http://starwars.wikia.com/index.php?...) or a relative address (/index.php?...). The relative form is preferred for the sake of portability.

ClassTester
Used by: getElementsByClass, getParentByClass

Tests HTML DOM elements, determining if they belong to the specified CSS class.

Constructor
constructor ClassTester(string className);

Creates a new ClassTester object testing for a specific class name.

Public methods
boolean isMatch(Element e);

Returns a value indicating if the specified DOM element belongs to the CSS class.