Static Public Member Functions | |
String | escapeHtml (String s, Boolean quot_too) |
Replace: less-than, greater-than, and ampersand with their html parameters. | |
Object | setTimeout (Window win, Function func, Number millis) |
On platforms that only support window.setTimeout of String, not Function, simulate Function support. | |
Node | ownerDocument (Node node) |
Function to emulate node.ownerDocument in a non-compliant environment (such as IE5.0 Win). | |
Boolean | isDocumentComplete (Document doc) |
Returns true if the document (defaults to current) is complete (finished loading). | |
Array | getAttributeNodes (Node node) |
On W3-compliant systems, just returns node.attributes (which supports both by-number and by-name indexing). | |
String | getInnerText (Node node) |
innerText is a convenient node member, but not part of the standard DOM . | |
void | setInnerText (Node node, String text) |
Setting innerText. | |
String | getInnerHTML (Node node) |
innerHTML is non-standard, but is available as a gettable and settable member variable in Mozilla, IE, and Opera 7. | |
void | setInnerHTML (Node node, String html) |
Set innerHTML. | |
String | getOuterHTML (Node node) |
IE has native outerHTML, but Moz does not. | |
void | setOuterHTML (Node node, String html) |
If setting outerHTML is not native (as it is on IE), we emulate on Moz using its proprietary createContextualFragment (which is also available on recent KHTML browsers). | |
void | insertAdjacentElement (Node node, String where, Node el) |
insertAdjacentElement, insertAdjacentHTML and insertAdjacentText are IE-specific, but convenient. | |
void | insertAdjacentText (Node node, String where, Node el) |
Calls native insertAdjacentText if available. | |
void | insertAdjacentHTML (Node node, String where, Node el) |
Calls native insertAdjacentHTML if available. | |
String | serialize (Node node, Boolean isHtml) |
Serialize the provided node to a String. | |
Node | nd (Node node, Object attmap, Node child1,...) |
Set the attributes in attmap in the provided node, and call appendChild on all children. | |
Element | structToNode (Object st, Document doc) |
Convert a hierarchical structure to a Node. | |
String | el (String name, Object attmap, String children,...) |
Return a String of HTML (or XML) for the element with provided name, attributes and children. | |
void | for_children (Node node, Function unary_func, Number node_type) |
Iterate through the node's child nodes calling the provided function with each child. | |
Node | find_child (Node node, Function unary_pred, Number node_type) |
Find the first child of node satisfying the predicate. | |
Node | firstChildWithTagName (Node node, String name, Boolean must_exist, Boolean cs) |
Return the first child with the specified tag name, or null. | |
Node | nthChildWithTagName (Node node, Number n, String name, Boolean must_exist, Boolean cs) |
Like firstChildWithTagName, but returns the nth (zero-based) child element with the specified tag name. | |
Array | getChildrenWithTagName (Node node, String name, Boolean cs) |
Returns a snapshot Array, unlike getElementsByTagName(name). | |
Array | childrenNamed (Node node, String name, Boolean is_snapshot) |
A convenience function. | |
String | getAttribute (Element node, String name) |
Perform what Node.getAttribute should do, but doesn't always. | |
void | setAttribute (Element node, String name, String val) |
Correct for any problems with native Node.setAttribute. |
|
A convenience function. If is_snapshot, then calls burst.xml.DomUtil.getChildrenWithTagName. Otherwise uses Node.getElementsByTagName (which differs semantically in that it returns all descendants not just immediate children). |
|
Return a String of HTML (or XML) for the element with provided name, attributes and children. For attribute values, we do value quoting and escaping; the caller is not expected to. We skip attributes whose value is null. We throw on attributes whose value is undefined.
|
|
Replace: less-than, greater-than, and ampersand with their html parameters.
|
|
Find the first child of node satisfying the predicate.
|
|
Return the first child with the specified tag name, or null. Note that this only iterates through immediate children (unlike DOM getElementsByTagName, which goes through all descendants). It will only return an Element child, of an Element parent. By default (cs is false), name is uppercased prior to iteration.
|
|
Iterate through the node's child nodes calling the provided function with each child. Implementation note: This is implemented with firstChild and nextSibling because NodeList Node.childNodes isn't a true Array but a collection and isn't terribly efficient.
|
|
Perform what Node.getAttribute should do, but doesn't always. PPK has much discussion of this, for example at: http://www.xs4all.nl/~ppk/js/w3c_core.html He suggests that Node.getAttribute in IE5 and IE6 is not always correct, saying the function is only trustworthy in Moz, Safari, IE-mac. However, I think it does actually work in IE5/IE6 except for the special cases noted below. In fact, see PPK's own tests at http://www.xs4all.nl/~ppk/js/w3c/attributes.html
Attributes that are ECMAScript reserved namesApparently getAttribute('class') doesn't work in IE (must use getAttribute('className')). Apparently opera does not support getAttribute('className').
Attribute name case-sensitivityIn IE, Node.getAttribute takes a second argument that is 0 for case-insensitive, and 1 for case-insensitive. The default is 0, for case-insensitive. However, reputedly in practice IE5+ still acts case-sensitively for special attributes (e.g., requiring 'bgColor' or 'colSpan' vs. allowing 'bgcolor' or 'colspan'), see: http://www.pxl8.com/setAttribute_test.html The W3 DOM has no such second argument. Moz and IEMac are case-insensitive at least for HTML.
Non-Standard AttributesApparently, only IE preserves non-standard attributes in "expando" properties. But for getAttribute and setAttribute, non-standard attributes seem to be generally supported.
Attributes for event handlers
In IE, attributes for event handlers (such as 'onclick') may be queried with getAttribute, but not set with setAttribute, but will allow a set with "expando" properties. If they are queried, IE returns a Function object, not a String. To set in IE, you have to say Moz returns a String from getAttribute, and supports setAttribute with String too.
The 'style' attributeFor the 'style' attribute, IE6 getAttribute('style') returns an object. Moz returns a String for getAttribute('style'). Note that object accessor "node.style" is an Object in IE. Note however that it has no value unless the document has an inline style attribute (from the document or from setAttribute). To set a 'style' attribute, node.setAttribute(style, 'top: 5px') works in Moz, but not in IE, where it is necessary to do something like node.style.top = '5px' or node.style.cssText = 'top: 5px' or node.style.setProperty('top', '5px'). (Btw, 'float' may appear in css text, but the name for setProperty and for rule attribute is 'cssFloat'. See http://www.w3.org/TR/DOM-Level-2-Style/css.html .) The W3 standard way to get the effective style on a element is document.defaultView.getComputedStyle(node,null). You can get particular properties with getPropertyValue('top') This is implemented in Mozilla 1.2 but not IE6, which instead has "node.currentStyle". Note that the choice between setting style by:
Missing attributesThe W3 standard says that the empty string '' should be returns for attribute that aren't set. Allegedly, in NN6 getAttribute of a non-existent attribute returns '' instead of null or undefined. Moz and NN7 instead return something that tests as false. See http://www.pxl8.com/setAttribute_test.html
White space in valuesApparent IE does not preserve white space in attribute values: http://www.zvon.org/xxl/DOM2reference/Output/examples/Element_getAttribute.html
XML namespaces and prefixesWe don't do anything about xml namespaces here; we are dealing with getAttribute here, not level 2 getAttributeNS.
|
|
On W3-compliant systems, just returns node.attributes (which supports both by-number and by-name indexing). On IE, it returns an Array of Attr nodes (which will only support by-number). See http://www.xs4all.nl/~ppk/js/w3c_core.html |
|
Returns a snapshot Array, unlike getElementsByTagName(name). Has special treatment for name '*', to return all Element children. |
|
innerHTML is non-standard, but is available as a gettable and settable member variable in Mozilla, IE, and Opera 7. If it is not native, we implement by calling getOuterHTML on all children. |
|
innerText is a convenient node member, but not part of the standard DOM . If available (as in IE), we use the native member. Otherwise we implement it ourselves. Note that IE innerText and innerHTML are members of document.documentElement, but not of document. In IE, innerHTML can be roundtripped (what it returns can be set). What it provides is normalized:
Furthermore, IE normalizes it to its own DTD, which might include changing the doctype. In the case of innerText, "what you see is what you get". But in the case of html, you only get concatenated text nodes. You don't get any tags. You may get less-than and ampersand, but they are literals (not markup). See http://www.xs4all.nl/~ppk/js/w3c_html.html for which browsers implement these. NS6 has innerHTML but does not have innerText or outerHTML. IE5 Mac has innerHTML but not innerText. Opera 7, has innerHTML, innerText, outerHTML, outerText. Note that (at least in beta) in Opera, innerHTML has escaped angle brackets, whereas in IE they are not: http://groups.google.com/groups?selm=65sih4uf.fsf%40hotpop.com
|
|
IE has native outerHTML, but Moz does not. If getting outerHTML is not native, we emulating by writing the top level ourselves, then calling getInnerHTML (which may in turn recursively call us again). |
|
insertAdjacentElement, insertAdjacentHTML and insertAdjacentText are IE-specific, but convenient. See http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/insertadjacentelement.asp Opera 7 implements them. Mozilla does not. The emulation for insertAdjacentHTML relies on the Mozilla non-standard createContextualFragment function (also implemented in recent KHTML browsers). We do not have an implementation otherwise. Our emulation for the other two functions, insertAdjacentElement and insertAdjacentText, does not rely on Mozilla-specific functionality. There are available implementations of insertAdjacent* by:
We are currently using Thor's. |
|
Calls native insertAdjacentHTML if available. Otherwise emulates it if Mozilla-style createContextualFragment is available. Else it throws. |
|
Calls native insertAdjacentText if available. Otherwise emulates it. |
|
Returns true if the document (defaults to current) is complete (finished loading).
It is very important to never call For now, this function only works with an html dom.
|
|
Set the attributes in attmap in the provided node, and call appendChild on all children.
|
|
Serialize the provided node to a String. Works with a node from either an HTML or XML DOM. Note that in some browsers (such as IE5.0 PC), document has no children. You have to pass in document.documentElement, which is a real Node.
|
|
Correct for any problems with native Node.setAttribute. See burst.xml.DomUtil.getAttribute for more information. |
|
Set innerHTML. At the moment this just sets the member variable: we do not have an emulation for setting innerHTML if it is not native (which it is on IE and Moz and Opera). |
|
Setting innerText. This is native on IE, but not Moz. If it is not native, it is implemented in terms of innerHTML (which is native on Moz), by simply escaping html (less-than, greater-than, ampersand). |
|
If setting outerHTML is not native (as it is on IE), we emulate on Moz using its proprietary createContextualFragment (which is also available on recent KHTML browsers). We do not have an emulation otherwise. (The technique of providing settable outerHTML using createContextualFragment may be seen by:
|
|
On platforms that only support window.setTimeout of String, not Function, simulate Function support.
|
|
Convert a hierarchical structure to a Node. The structure is of the form:
|