SUI.browser

Holds a set of browser specific functions.

Defined in: browser.js


Member summary

Attr. Type Name Description
private int

_id

Counter to create unique id's within the scope of the page.

public boolean

isGecko

Is the code executed by a Mozilla type browser?

public boolean

isIE

Is the code executed by an IE type browser?

public boolean

isOpera

Is the code executed by an Opera type browser?

public boolean

isWebKit

Is the code executed by a WebKit type browser?

public boolean

version

What's the version of the browser? TODO not really supported yet.

public int

viewportHeight

The current height of the browser window (viewport).

public int

viewportWidth

The current width of the browser window (viewport).

Method summary

Attr. Type Name / Description
public

addEventListener(el, id, fn)

Add an event listener to an HTML element node. This is basically a wrapper for HTMLElementNode.addEventListener() because we would like to use the standard mechamism but can't because of IE. Also note that we really can't 'add' eventlisteners because of IE, unless we're adding event listeners to the window object. That's because in this library we normally store the listener element in an SUI.Event object. Using attachEvent (what you want to use if you want to add listeners) will leave you with a this pointer that points to the window object instead of the element that handles te event. So except for the window object there is no posibility to add multiple event listners to a HTML element. IE will only recognize the last one added when using this function.

public

createElement(tag, attr)

Create an HTML element with a set of default properties set. In the SUI library most elements are created by this function to ensure some standard settings. The following element properties are set:

  • not selectable unless it's a from element,
  • set a standard font (class),
  • disable system context menu's,
  • no margin or padding,
  • the default cursor,
  • absolute positioning
  • generate a unique id

public Object | *

currentStyle(el, property)

Get the current/computed style of an HTML element. You can either retrieve the style object itself or a single property. Note: You can only use this function if the HTML content of the page is fully rendered because the currentStyle is asynchronious in IE.

public

getBrowser()

Get the browser type and version. The function has no return values, but it sets the isIE, isGEcko, isOpera, isWebKit and version fields of the SUI.browser object. TODO version not really supported yet

public

getVieportSize()

Get the browser window (viewport) size and set the viewportWidth and viewportHeight members of the SUI.browser object. Note that this function returns no values.

public int

getX(e)

Get the horizontal mouse position from a mouse event with respect to the left of the document.

public int

getY(e)

Get the vertical mouse position from a mouse event with respect to the top of the document.

public

mergeAttributes(newMode, oldMode)

Add and overwrite the attributes of some HTML element node with the attributes of another.

public String

newId()

Return a new unique id. Note that the id sequence is initialized when this module is loaded.

public

noPropagation()

Stop the propagation (bubbling) of the event upwards the DOM tree. This is basically a wrapper for DOMEvent.stopPropagation needed for IE compatibility.

public

patchNoArrayIndexOf()

Some older browsers (notably IE 8) don't implement Array.indexOf. This is the fix for a missing Array.indexOf method as proposed on MDN.

public

patchSubstrIE()

Fix for String.substr implementations (IE) that do not support a negative index.

public

removeEventListener(el, id, fn)

Remove an event listener from an HTML element node that was previously added with addEventListener. It is basically a wrapper for HTMLElementNode.removeEventListener() needed for IE compatibility.

public

removeNode(e, removeChildren)

Remove an element from the document tree. Either remove the node completely or keep the nodes child nodes in place.

public

setAttributes(e, attr)

Set/unset a number of attributes using an object. The attributes get the values from the corresonding properties. A property value of null will remove the attribute.

public int

viewportScrollX()

Get the vertical scroll offset of the viewport.

public int

viewportScrollY()

Get the horizontal scroll offset of the viewport.

 


Members

private int _id

Counter to create unique id's within the scope of the page.

public boolean isGecko

Is the code executed by a Mozilla type browser?

public boolean isIE

Is the code executed by an IE type browser?

public boolean isOpera

Is the code executed by an Opera type browser?

public boolean isWebKit

Is the code executed by a WebKit type browser?

public boolean version

What's the version of the browser? TODO not really supported yet.

public int viewportHeight

The current height of the browser window (viewport).

public int viewportWidth

The current width of the browser window (viewport).


Methods

public addEventListener( HTMLElementNode el, String id, Function fn)

Add an event listener to an HTML element node. This is basically a wrapper for HTMLElementNode.addEventListener() because we would like to use the standard mechamism but can't because of IE. Also note that we really can't 'add' eventlisteners because of IE, unless we're adding event listeners to the window object. That's because in this library we normally store the listener element in an SUI.Event object. Using attachEvent (what you want to use if you want to add listeners) will leave you with a this pointer that points to the window object instead of the element that handles te event. So except for the window object there is no posibility to add multiple event listners to a HTML element. IE will only recognize the last one added when using this function.

Parameters:

Name Type Description
HTMLElementNode el The HTML element node to add the event listener to.
String id An event id (like: "click", "mouseover", etc.).
Function fn Listener function with signature ({DOMEvent}). Note that in IE the listener will be called with no parameter and that access to the DOMEvent will be provided by the widow object.
public createElement( String tag, Object attr)

Create an HTML element with a set of default properties set. In the SUI library most elements are created by this function to ensure some standard settings. The following element properties are set:

  • not selectable unless it's a from element,
  • set a standard font (class),
  • disable system context menu's,
  • no margin or padding,
  • the default cursor,
  • absolute positioning
  • generate a unique id

Parameters:

Name Type Argument Default Description
String tag <optional>
"DIV" HTML tag name of the element to create
Object attr <optional>
Object containing the name and value pairs for the elements attributes.
public Object | * currentStyle( HTMLElementNode el, String property)

Get the current/computed style of an HTML element. You can either retrieve the style object itself or a single property. Note: You can only use this function if the HTML content of the page is fully rendered because the currentStyle is asynchronious in IE.

Parameters:

Name Type Argument Description
HTMLElementNode el HTML element node to get the computed style (property) from.
String property <optional>
The style property to retrieve.

Returns:

Object | * The style object if no specific property was set, or else the requested style property.

public getBrowser()

Get the browser type and version. The function has no return values, but it sets the isIE, isGEcko, isOpera, isWebKit and version fields of the SUI.browser object. TODO version not really supported yet

public getVieportSize()

Get the browser window (viewport) size and set the viewportWidth and viewportHeight members of the SUI.browser object. Note that this function returns no values.

public int getX( DOMEvent e)

Get the horizontal mouse position from a mouse event with respect to the left of the document.

Parameters:

Name Type Description
DOMEvent e A mouse event.

Returns:

int The distance from the left side of the document to the mouse click in pixels.

public int getY( DOMEvent e)

Get the vertical mouse position from a mouse event with respect to the top of the document.

Parameters:

Name Type Description
DOMEvent e A mouse event.

Returns:

int The distance from the top side of the document to the mouse click in pixels.

public mergeAttributes( HTMLElementNode newMode, HTMLElementNode oldMode)

Add and overwrite the attributes of some HTML element node with the attributes of another.

Parameters:

Name Type Description
HTMLElementNode newMode The node to copy the attributes to.
HTMLElementNode oldMode The node to copy the attributes from.
public String newId()

Return a new unique id. Note that the id sequence is initialized when this module is loaded.

Returns:

String An unique id.

public noPropagation()

Stop the propagation (bubbling) of the event upwards the DOM tree. This is basically a wrapper for DOMEvent.stopPropagation needed for IE compatibility.

public patchNoArrayIndexOf()

Some older browsers (notably IE 8) don't implement Array.indexOf. This is the fix for a missing Array.indexOf method as proposed on MDN.

public patchSubstrIE()

Fix for String.substr implementations (IE) that do not support a negative index.

public removeEventListener( HTMLElementNode el, String id, Function fn)

Remove an event listener from an HTML element node that was previously added with addEventListener. It is basically a wrapper for HTMLElementNode.removeEventListener() needed for IE compatibility.

Parameters:

Name Type Description
HTMLElementNode el The HTML element node to add the event listener to.
String id An event id (like: "click", "mouseover", etc.).
Function fn A valid reference to the listener function that earlier was added with addEventListener method.
public removeNode( HTMLElementNode e, boolean removeChildren)

Remove an element from the document tree. Either remove the node completely or keep the nodes child nodes in place.

Parameters:

Name Type Description
HTMLElementNode e Element node to remove.
boolean removeChildren Also remove the children of the node.
public setAttributes( HTMLElementNode e, Object attr)

Set/unset a number of attributes using an object. The attributes get the values from the corresonding properties. A property value of null will remove the attribute.

Parameters:

Name Type Description
HTMLElementNode e Element node of which the attributes to set.
Object attr Object containing the new values for the attributes.
public int viewportScrollX()

Get the vertical scroll offset of the viewport.

Returns:

int The vertical scroll offset of the viewport.

public int viewportScrollY()

Get the horizontal scroll offset of the viewport.

Returns:

int The horizontal scroll offset of the viewport.