Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

burst.xml.HtmlUtil Class Reference

List of all members.

Detailed Description

Scoping class holding static HTML DOM-related utility functions.

The scoping class burst.xml.HtmlBox has utilities specifically about element size and location.


Static Public Member Functions

String getDocumentScriptSrc (String matching, Boolean mustFind)
 Extract the full 'src' attribute value of the 'script' element in this document which matches the provided regexp or string.

void addClassValue (Element node, String val, Boolean first)
 Add the provided value to any existing value for the "class" attribute of the provided Element.

Boolean removeClassValue (Node node, String val)
 Remove the id val from the "class" attribute of the provided Element.

String getStyleProperty (Node node, String propName)
 Get a single style property.

void setStyleProperty (Node node, String propName, String propVal)
 Set a single style property (in node.style).

Number maxZIndex (DomDocument doc)
 finds the maximum z-index set in the document.

String getComputedStyle (Node node, String attname)
 Get computed style value.

Number parseStylePixels (String s, String attname, Number fallback)
 Convert a string like '30' or '30px' into a number like 30.

Number getComputedStylePixels (Node node, String attname, Number fallback)
 returns a number if fallback is not defined, and it finds a non-empty string it can't parse as a number, it throws.

String stylePropertyName (String attname)
 convert an "attribute name" (such as "font-size") to a "property name" (such as "fontSize").

Node getDocumentElementIE (DomDocument doc)
 Return doc.body or doc.documentElement according to IE compatMode.

Object parseStyle (String text)
 Parse a string which follows the conventions of a CSS style declaration.

String getWindowBaseUrl (Window win, Boolean recurse_parent)
 Return the base URI for the provided window.

String resolveWindowUrl (String url, Window win)
 Resolve the uri relative to the provided window.

Element iframeCreate (String iframe_id, String srcval, String onloadval, Function create_cb, Boolean as_visible)
 Create a hidden iframe element child in the current document.

Window iframeContentWindow (Element iframe_el)
 Go from iframe element (in the parent document) to the iframe window object.

Document iframeContentDocument (Element iframe_el)
 Get the Document object for the iframe.

Location iframeLocation (Element iframe_el)
 Get the Location object for the iframe element.

void iframeReplaceContents (Element iframe_el, String html)
 Replaces the contents of the iframe with the provided html.


Member Function Documentation

void burst.xml.HtmlUtil.addClassValue Element  node,
String  val,
Boolean  first
[static]
 

Add the provided value to any existing value for the "class" attribute of the provided Element.

If there no "class" already or it has the empty value, it is set to this. Otherwise if first is true, it is prepended, otherwise appended, always preserving space separation. Also, it checks to see if it is already present, and if so, does nothing.

Parameters:
node the element in question
val the string id of a CSS class
first (Optional) whether to prepend instead of append the val.
Returns:
whether it was added

String burst.xml.HtmlUtil.getComputedStyle Node  node,
String  attname
[static]
 

Get computed style value.

See: http://www.xs4all.nl/~ppk/js/w3c_css.html http://www.w3.org/TR/1998/REC-CSS2-19980512/cascade.html#computed-value

The getPropertyValue function takes a CSS hyphenated "style attribute" name like 'font-size', 'z-index', 'background-color'. When using members of a style object, such as node.style['color'], it is necessary to have "style property" member names like 'fontSize', 'zIndex', 'backgroundColor'.

Mozilla supports getComputedStyle. In Mozilla, both node.style and getComputedStyle support access both by getPropertyValue(attname) and by propname members.

Safari (upcoming) supports getComputedStyle.

The IE style and currentStyle objects support access only by propname, both as expando and using getAttribute. IE also has a runtimeStyle object, which can be used for overrides.

Opera 7.0 supports neither currentStyle nor getComputedStyle. Opera 7.5 supports getComputedStyle but not currentStyle. At least in O7.0 , its style object does expand out 'border' and 'padding' settings to their individual property values, though still preserving the original units: if it was 'padding: 0.25in', then there will be a 'padding-left' value of '0.25in'. But it otherwise does not have a way to retrieve a computed style attribute.

The return value is always a String. An empty string means no value. (This is how the style object works in all browsers).

The standard says that computed values should in fact be computed numbers. This is not always the case; some browsers return the actually set strings, or return nothing at all.

Mozilla will return a number + 'px' value for some attributes regardless of whether they were explicitly set or not, and regardless of whether it was set by an expression such 'auto' or '37%' or '5in'. These reliable attribute names include: 'width', 'padding-left', 'padding-right' 'border-left-width', 'border-right-width', 'margin-left', 'margin-right', 'height', 'padding-top', 'padding-bottom' 'border-top-width', 'border-bottom-width', 'margin-top', 'margin-bottom' This does not include: 'left', 'right', 'top', 'bottom', Furthermore, if just 'border' or 'padding' is set explicitly in css, Mozilla getComputedStyle will return appropriate values for the particular measurements on each side such as 'border-left-width' (the reverse is not true).

IE's currentStyle object does not generally do conversion. If a node style is 'width: 37%', then currentStyle['width'] == '37%'. Like Opera, it does expand border and padding settings to the individual ones, preserving original units.

Note that the CSS rules may be accessed via: document.styleSheets[0].cssRules[0].style.borderWidth

Node burst.xml.HtmlUtil.getDocumentElementIE DomDocument  doc  )  [static]
 

Return doc.body or doc.documentElement according to IE compatMode.

Only for use with Internet Explorer.

String burst.xml.HtmlUtil.getDocumentScriptSrc String  matching,
Boolean  mustFind
[static]
 

Extract the full 'src' attribute value of the 'script' element in this document which matches the provided regexp or string.

It checks the type of its first argument).

This is useful when generating a script "src" value, because it will be interpreted relative to the base url of the document which included this file (location object), *not* relative to this file.

Parameters:
matching Either a Regexp to match against script, or a String to test substring
mustFind If true, the function throws and exception if no match is returned
Returns:
The String value of the 'src' attribute of the matching 'script' element.

String burst.xml.HtmlUtil.getStyleProperty Node  node,
String  propName
[static]
 

Get a single style property.

This returns the computed (aka 'current') style.

See also:
http://www.xs4all.nl/~ppk/js/w3c_css.html

String burst.xml.HtmlUtil.getWindowBaseUrl Window  win,
Boolean  recurse_parent
[static]
 

Return the base URI for the provided window.

It determines this from these sources:

  • any 'base' element with a 'href' attribute
  • win.location.href

(Note that Content-Base is not in the HTTP 1.1 RFC (it is not in 2616, only 2068), so 'META http-equiv="Content-Base" content="http://w.com/"' is a non-issue.)

In an xml document, the "xml:base" attribute is relevant: http://www.w3.org/TR/xmlbase/ However, as that could appear anywhere in the hierarchy, we don't deal with it.

In general, the string this function returns might be absolute or relative.

See http://www.w3.org/TR/REC-html40/struct/links.html#resolving-relative-uris If a base element is provided, it must have an href attribute, which must be an absolute URI.

Parameters:
win The window.
recurse_parent If this windows base url is relative, whether it should recurse to parent.

Document burst.xml.HtmlUtil.iframeContentDocument Element  iframe_el  )  [static]
 

Get the Document object for the iframe.

Note: iframe_el.document, which is set in Opera and IE6, is the containing document, not the document of the iframe. It should *not* be used.

Window burst.xml.HtmlUtil.iframeContentWindow Element  iframe_el  )  [static]
 

Go from iframe element (in the parent document) to the iframe window object.

Current W3 standards define contentDocument but do not require a contentWindow method.

Here a bit of the sad story we work around here:

  • NS6 iframe window has contentDocument, not contentWindow.
  • Gecko 1.0.1 has contentWindow.
  • IE5 Mac and IE5.0 PC has no contentWindow, but do have a document child.
  • IE5.5+ PC has contentWindow but no contentDocument.
  • IE4+ has document.parentWindow but Mozilla does not. Mozilla and Opera have document.defaultView
  • Mozilla has __parent__

Element burst.xml.HtmlUtil.iframeCreate String  iframe_id,
String  srcval,
String  onloadval,
Function  create_cb,
Boolean  as_visible
[static]
 

Create a hidden iframe element child in the current document.

Todo:
what browsers require Function vs. String for onload?

For browsers that support iframe onload, do the events bubble up? does returning false help?

Parameters:
iframe_id The value for both the 'name' and 'id' attributes.
srcval Optional. The value for the 'src' attribute. If undefined, defaults to burst.io.IframeURIRequest.NO_SRC
onloadval Optional. The value for the 'onload' attribute. can be a Function or String.
create_cb Optional. Called with the newly created element (prior to attaching to parent, if possible).
as_visible Optional. If true, do not create the iframe to be initially invisible (it won't set size either though).
Returns:
the created Element

void burst.xml.HtmlUtil.iframeReplaceContents Element  iframe_el,
String  html
[static]
 

Replaces the contents of the iframe with the provided html.

Calls iframeContentDocument(iframe_el) and performes a Document.write on it with the html.

Number burst.xml.HtmlUtil.maxZIndex DomDocument  doc  )  [static]
 

finds the maximum z-index set in the document.

returns null if none set.

Object burst.xml.HtmlUtil.parseStyle String  text  )  [static]
 

Parse a string which follows the conventions of a CSS style declaration.

Any example might be a: 1; foobar: 'some text'

Note that this does not parse a CSS rule (which would include selectors and {}). Just the body declaration, as might appear in a style attribute.

This is not a perfect emulation. If you have a real style, you should use the style object and call the official style.getPropertyValue or style.getPropertyCSSValue methods. This function is intended just for use if you have a string which mimics the CSS syntax.

Returns an associative array with keys being property names. Both names and values have surrounding white space stripped.

Quoted values are unquoted, if the entire value string (between ':' and ';') is quoted. If the value string contains an internal quoted string, it is preserved.

Boolean burst.xml.HtmlUtil.removeClassValue Node  node,
String  val
[static]
 

Remove the id val from the "class" attribute of the provided Element.

Parameters:
node the element in question
val the string id of a CSS class
Returns:
whether it was found

String burst.xml.HtmlUtil.resolveWindowUrl String  url,
Window  win
[static]
 

Resolve the uri relative to the provided window.

The logic is:

  • If url is already absolute, it is returned.
  • Determine the base url of window (which may require a recursive call through window parents)
  • Relativize url to that base url

The result may still not be an absolute url.


The documentation for this class was generated from the following file:
Generated on Tue Nov 30 04:03:09 2004 for BurstProject by doxygen 1.3.4