General-purpose functions

Summary
Returns the DOM element with the id passed.
Performs a shallow copy of an object.
A shortcut function for creating a DOM element.
Places text in a DOM element.
Removes all child elements from a DOM element.
Wikifies a passage into a DOM element.
Adds CSS styles to the document.
Displays an error message on the page.
Eases a decimal number from 0 to 1.
Parses a list of macro parameters.
Parses a list of bracketed links -- e.g.
Removes whitespace from the beginning and end of a string.

Functions

$

function $ (id)

Returns the DOM element with the id passed.

Parameters

idthe id to look up

Returns

A DOM element, or null if none with the id exist.

clone

function clone (original)

Performs a shallow copy of an object.

Parameters

originalthe object to copy

Returns

The copied object.

insertElement

function insertElement (place,
type,
id,
className,
text)

A shortcut function for creating a DOM element.  All parameters are optional.

Parameters

placethe parent element
typethe type of element to create -- e.g.  ‘div’ or ‘span’
idthe id to give the element
classNamethe CSS class to give the element
texttext to place inside the element.  This is not interpreted as HTML.

Returns

The newly created element.

insertText

function insertText (place,
text)

Places text in a DOM element.

Parameters

placethe element to add text to
texttext to insert

Returns

The newly created DOM text node.

removeChildren

function removeChildren (el)

Removes all child elements from a DOM element.

Parameters

elthe element to strip

Returns

nothing

setPageElement

function setPageElement (id,
title,
defaultText)

Wikifies a passage into a DOM element.

Parameters

idthe id of the element
titlethe title of the passage
defaultTexttext to use if the passage doesn’t exist

Returns

a DOM element, or null if none with the id exist.

See also

Wikifier

addStyle

function addStyle (source)

Adds CSS styles to the document.

Parameters

sourcethe CSS styles to add

Returns

nothing

throwError

function throwError (place,
message)

Displays an error message on the page.

Parameters

placethe place to show the error message
messagethe message to display

Returns

nothing

Math. easeInOut

Math.easeInOut = function (i)

Eases a decimal number from 0 to 1.

Parameters

ithe number to ease.  Must be between 0 and 1.

Returns

The eased value.

String. readMacroParams

Parses a list of macro parameters.

Parameters

none

Returns

An array of parameters.

String. readBracketedList

Parses a list of bracketed links -- e.g.  [[my link]].

Parameters

none

Returns

an array of link titles.

String.trim

Removes whitespace from the beginning and end of a string.

Parameters

none

Returns

The trimmed string.

function $ (id)
Returns the DOM element with the id passed.
function clone (original)
Performs a shallow copy of an object.
function insertElement (place,
type,
id,
className,
text)
A shortcut function for creating a DOM element.
function insertText (place,
text)
Places text in a DOM element.
function removeChildren (el)
Removes all child elements from a DOM element.
function setPageElement (id,
title,
defaultText)
Wikifies a passage into a DOM element.
function addStyle (source)
Adds CSS styles to the document.
function throwError (place,
message)
Displays an error message on the page.
Math.easeInOut = function (i)
Eases a decimal number from 0 to 1.
Used to display text on the page.