Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

User:MDAWaffe/List Manipulation

This article is a ROUGH DRAFT. The author is still working on this document, so please do not edit this without the author's permission. The content within this article may not yet be verified or valid. This information is subject to change.

AJAX response from server

  • Simple things: (-1, 0, 1) = (current_user_can't, what the hell was that?, go ahead)
  • More complicated things: (-1, 0, whitespace free xml that makes liberal use of CDATA). Manipulating the DOM is nice and all, but innerHTML is fast.


The listMan "class".


string theListId : Specifies the id of the list element.



HTMLElement theList 
The HTMLElement object of the list in question. Determined by theListId parameter. Typcially a tbody, ul or ol.
string ajaxRespEl 
The id of the element into which any AJAX response feedback will be written. Defaults to 'ajax-response'.
string inputData 
stores the part of the URL query passed to the server corresponding to the data from the submitted form. Determined by the grabInputs method.
array clearInputs 
An array of form input element ids (strings) that are reset after the form data is submitted. selects are set to their first option. The values of all other inputs are set to the empty string. Automatically populated by grabInputs.
bool topAdder 
Whether new list items are added to the top or bottom. Defaults to 0 (bottom).
bool showLink 
If set to true, a link to the anchor of the newly added item will be displayed. Defaults to true.
string alt 
If the list has items with alternating classes, this property stores the name of that CSS class. Set to 0 to work with lists without alternating classes. Defaults to 'alternate'. Note: construct all alternating lists such that the first and all subsequent odd items are assigned the alternate class.
int recolorPos 
Used internally to determine which items need recoloring after addition/deletion.
string reg_color 
A six digit hex value prefixed by a '#' specifying the background color of the regular (non-alternate) list items.
string alt_color 
A six digit hex value prefixed by a '#' specifying the background color of the alternate list items.
function addComplete, delComplete and dimComplete 
Function run when AJAX call is successful.


string listType 
'table' or 'list'.
array listItems 
an array of the ids of the list items.


bool aTrap 
Whether or not an AJAX call has happend in the last 300 milliseconds. Prevents problems with double clicking, etc.


The "scope" of these methods may change in the future.


bool ajaxAdder(string what, string where) 
Creates something(s) of type what from the data contained in the input elements that are descendents of the HTML element with id equal to where. The new item(s) are then added to the list. The addComplete function will be run after all the items have been added and before the list is recolored. Items being added to the list that already exist in the list will be moved from their initial position to the beginning or end of the list (depending on topAdder. Returns false on success (to block traditional form submission), true on failure.
bool ajaxUpdater(string what, string where) 
A wrapper for ajaxAdder. Tthis function is specifically designed to edit an item's data rather than create a new item. Returns false on success, true on failure.
bool ajaxDelete(string what, string id) 
Deletes the item of type what and with element id what-id, then removes that item from the list. The delComplete function will be run after all the item has been deleted and removed, and before the list is recolored. Returns false on success, true on failure.
bool ajaxDimmer(string what, string id, string dimClass) 
Toggles some piece of information about an item and then toggles the list item's membership in the CSS class specified by dimClass. Again, the item is of type what and has element id what-id. The dimComplete function will be run after all the item has been dimmed. Returns false on success, true on failure.

Public (non-AJAX)

HTMLElement makeEl(string rawHTML) 
Converts the text of rawHTML into an HTML element appropriate for insertion into the list.
void addListItem(string rawHTML, int totalNumber) 
Adds the rawHTML to the list. The totalNumber parameter specifies how many items are being added "at once" in this set.
void removeListItem(string id, bool noFade) 
Fades the item with element id specified by id from red and then deletes it. If noFode==true, the item is simply deleted without fading.
void replaceListItem(string id, string rawHTML) 
Replaces list item identified by id with rawHTML. Also used internally to first remove and then replace an item.
void dimItem(string id, string dimClass, bool noFade) 
Toggles the membership in the CSS class dimClass of the list item identified by id and fades from yellow.
void grabInputs( string container) 
Used internally to grab the input values of the form elements within container (specified by an id). Looks only for text, password, textarea, hidden, and select form elements. Also populates clearInputs with the ids of all of these elements excluding hidden elements.

Other Functions

bool deleteSomething(what, id, string message) 
Wrapper for theList.ajaxDelete that also asks the user to confirm the deletion by responding to message.
bool dimSomething(what, id, dimClass) 
Wrapper for theList.ajaxDimmer.
bool killSubmit(string code, event e) 
Evaluates the JS specified by code. If the JS evaluates to false the form is not submitted. Should be bound to elements' onkeypress or onclick event handlers.
string getNodeValue(DOM Object tree, string tagName) 
Returns the nodeValue of the first child of the first element with tag name tagName that is a descendant of tree.
function encloseFunc(function func, [mixed arg]) 
Returns a reference to func optionally evaluated at arg.