User:Derik/javascript

From MediaWiki
Revision as of 09:38, 23 March 2009 by Derik (talk | contribs) (New page: Hopefully this sandbox will eventually represent a documentation of the useful bits of our javascript; mediawiki-originated, cribbed from wikia and other sites, and original. It is my fe...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Hopefully this sandbox will eventually represent a documentation of the useful bits of our javascript; mediawiki-originated, cribbed from wikia and other sites, and original.


It is my fervent wish that by documenting it thus, redundant code can be minimized.


A-F

[edit]
<a href="/wiki/User:Derik/javascript#addClickHandler.28_element.2C_handlerFunction_.29|addClickHandler( element, handlerFunction ) ]]
IN: wikibits.js - Same as addHandler() (below) but a neater markup specific to click events.

addHandler( element, event, handlerFunction )
IN: wikibits.js - bind an elevent to an element. Same as hoolEvent() but on an element-level rather than window-level.
addHandler( elementNode, 'keydown', refreshSearch );
addOnloadHook(functionName)
IN: wikibits.js - Adds a function to an array of functions that will be executed once the page is fully loaded.
To add the function "initSearch()", the format is addOnloadHook(initSearch);
changeText(el, newText)
IN: wikibits.js - replaces the inner text of an element el with the newText provided
Note: This function uses the element.innerText attribute to perform this replacement. It may mangle HTML?


escapeQuotes(text)
IN: wikibits.js - Just what you'd expect, escapes quotes with backslashes.

escapeQuotesHTML(text)
IN: wikibits.js - Just what you'd expect, escapes quotes with HTML entities.

G-M

[edit]
getElementsByClassName(node, tagName, classNameObj)
IN: wikibits.js - returns an array of element nodes with the class found in classNameObj within the element node. tagName can also be used, or set to '*' to match all HTML tags. classNameObj can (apparently) be either an array (with multiple classes) or a string All variables are required.
Example: getElementsByClassName(document, 'sup', Array('reference')); — retrieve all elements anyehere on the page. Example: getElementsByClassName(document.getElementById('content'), 'a', 'new'); — retrieve all red links within the page-content area only.
getFirstHeading()
IN: Monacobook.js - Returns an element handle for the first H1 ont he page with a class 'firstHeading'. (The page title)
Note: Based on showEras() from Wookiepedia, but our implementation is cleaner!


hookEvent(hookName, hookFunct)
IN: wikibits.js - binds a function to a window-level event by hookName, where hookName is the common javascrit-internal name for that event-- minus the leading "on."
To bind the function "updateSearch()" to execution when a onkeydown event occurs, the format is hookEvent(keydown, updateSearch);
injectSpinner( element, idString );
IN: wikibits.js - Inserts an "in progress" spinner after the provided element for Ajax-y goodness. You can remove it later with removeSpinner()
Note: The spinner graphic is very gay.


insertTags(tagOpen, tagClose, sampleText)
IN: wikibits.js - Adds text to the edit window (when in edit mode) at the point of the cursor.
tagOpen = add before selected text, tagClose = add after the selected text, sampleText = text to wedge between the two. (example content the user will change.)
To simply insert a tag, format is insertTags('disambig',,);
jsMsg( message, className )
IN: wikibits.js - Pops a notice box up at the top of the page. Functions just like you'd think...


N-S

[edit]
redirectToFragment(anchorName);
IN: wikibits.js - scrolls the window to an anchor anchorName.
You will never use this, ever, it's part of the redirect-to-subsection mechanism, which isn't currently(Jan-14-09) working on the site. I'm only documenting so I can go back later and figure out why it's not working, since we seem to have code related it installed.
removeSpinner( idString );
IN: wikibits.js - removes the "in progress" spinner added by injectSpinner()

showFactions( idString );
IN: Monacobook.js - Looks for an element with the provided idString, then clones it into the first heading and changes its display mode to "block." (Used to display faction symbols.)
Note: Based on showEras() from Wookiepedia.



T-Z

[edit]
toggle_element_activation(disable,enable)
IN: wikibits.js - given two html element id strings (not the elements themselves!,) disables the first element and enables the second. (Used for complicated forms.)

toggle_element_check(check, uncheck)
IN: wikibits.js - given two element id strings that refer to checkboxes, checks the first element and unchecks the second. (Used for complicated forms.)

toggleVisibility(_levelId, _otherId, _linkId)
IN: wikibits.js - toggles the element element in and out of visibility while alternately hiding/inlining the second two elements. Used for the "enhanced" version of the Special:RecentChanges page.

_-9

[edit]