Jx

Jx is a global singleton object that contains the entire Jx library within it.  All Jx functions, attributes and classes are accessed through the global Jx object.  Jx should not create any other global variables, if you discover that it does then please report it as a bug

License

Copyright © 2008, DM Solutions Group Inc.

This file is licensed under an MIT style license

Summary
JxJx is a global singleton object that contains the entire Jx library within it.
Properties
{String} baseURLThis is the URL that Jx was loaded from, it is automatically calculated from the script tag src property that included Jx.
Functions
applyPNGFilterStatic method that applies the PNG Filter Hack for IE browsers when showing 24bit PNG’s.
addToImgQueueRequest that an image be set to a DOM IMG element src attribute.
checkImgQueueAn internal method that ensures no more than 2 images are loading at a time.
loadNextImgAn internal method actually populate the DOM element with the image source.
createIframeShimCreates a new iframe element that is intended to fill a container to mask out other operating system controls (scrollbars, inputs, buttons, etc) when HTML elements are supposed to be above them.
getNumbersafely parse a number and return its integer value.
getPageDimensionsreturn the dimensions of the browser client area.
ElementElement is a global object provided by the mootools library.
Functions
getContentBoxSizereturn the size of the content area of an element.
getBorderBoxSizereturn the size of the border area of an element.
getMarginBoxSizereturn the size of the margin area of an element.
setContentBoxSizeset either or both of the width and height of an element to the provided size.
setBorderBoxSizeset either or both of the width and height of an element to the provided size.
getPaddingSizereturns the padding for each edge of an element
getBorderSizereturns the border size for each edge of an element
descendantOfdetermines if the element is a descendent of the reference node.
findElementsearch the parentage of the element to find an element of the given tag name.
Jx.ContentLoaderContentLoader is a mix-in class that provides a consistent mechanism for other Jx controls to load content in one of four different ways:
Options
contentcontent may be an HTML element reference, the id of an HTML element already in the DOM, or an HTML string that becomes the inner HTML of the element.
contentURLthe URL to load content from
Properties
contentIsLoadedtracks the load state of the content, specifically useful in the case of remote content.
Functions
loadContenttriggers loading of content based on options set for the current object.
checkRequest()Is fired after a delay to check the request to make sure it’s not failing in AIR.
Jx.AutoPositionMix-in class that provides a method for positioning elements relative to other elements.
Functions
positionpositions an element relative to another element based on the provided options.
Jx.ChromeA mix-in class that provides chrome helper functions.
Properties
chromethe DOM element that contains the chrome
Functions
makeChromecreate chrome on an element.
showChromeshow the chrome on an element.
hideChromeremoves the chrome from the DOM.
Jx.AddableA mix-in class that provides a helper function that allows an object to be added to an existing element on the page.
Functions
addToadds the object to the DOM relative to another element.

Properties

{String} baseURL

This is the URL that Jx was loaded from, it is automatically calculated from the script tag src property that included Jx.

Note that this assumes that you are loading Jx from a js/ or lib/ folder in parallel to the images/ folder that contains the various images needed by Jx components.  If you have a different folder structure, you can define Jx’s base by including the following before including the jxlib javascript file:

Jx = {
   baseURL: 'some/path'
}

Functions

applyPNGFilter

Jx.applyPNGFilter = function(o)

Static method that applies the PNG Filter Hack for IE browsers when showing 24bit PNG’s.  Used automatically for img tags with a class of png24.

The filter is applied using a nifty feature of IE that allows javascript to be executed as part of a CSS style rule - this ensures that the hack only gets applied on IE browsers.

The CSS that triggers this hack is only in the ie6.css files of the various themes.

Parameters

object {Object} the object (img) to which the filter needs to be applied.

addToImgQueue

Jx.addToImgQueue = function(obj)

Request that an image be set to a DOM IMG element src attribute.  This puts the image into a queue and there are private methods to manage that queue and limit image loading to 2 at a time.

Parameters

obj{Object} an object containing an element and src property, where element is the element to update and src is the url to the image.

checkImgQueue

Jx.checkImgQueue = function()

An internal method that ensures no more than 2 images are loading at a time.

loadNextImg

Jx.loadNextImg = function()

An internal method actually populate the DOM element with the image source.

createIframeShim

Jx.createIframeShim = function()

Creates a new iframe element that is intended to fill a container to mask out other operating system controls (scrollbars, inputs, buttons, etc) when HTML elements are supposed to be above them.

Returns

an HTML iframe element that can be inserted into the DOM.

getNumber

Jx.getNumber = function(n,
def)

safely parse a number and return its integer value.  A NaN value returns 0.  CSS size values are also parsed correctly.

Parameters

n{Mixed} the string or object to parse.

Returns

{Integer} the integer value that the parameter represents

getPageDimensions

Jx.getPageDimensions = function()

return the dimensions of the browser client area.

Returns

{Object} an object containing a width and height property that represent the width and height of the browser client area.

Element

Element is a global object provided by the mootools library.  The functions documented here are extensions to the Element object provided by Jx to make cross-browser compatibility easier to achieve.  Most of the methods are measurement related.

While the code in these methods has been converted to use MooTools methods, there may be better MooTools methods to use to accomplish these things.  Ultimately, it would be nice to eliminate most or all of these and find the MooTools equivalent or convince MooTools to add them.

Summary
Functions
getContentBoxSizereturn the size of the content area of an element.
getBorderBoxSizereturn the size of the border area of an element.
getMarginBoxSizereturn the size of the margin area of an element.
setContentBoxSizeset either or both of the width and height of an element to the provided size.
setBorderBoxSizeset either or both of the width and height of an element to the provided size.
getPaddingSizereturns the padding for each edge of an element
getBorderSizereturns the border size for each edge of an element
descendantOfdetermines if the element is a descendent of the reference node.
findElementsearch the parentage of the element to find an element of the given tag name.

Functions

getContentBoxSize

getContentBoxSize : function()

return the size of the content area of an element.  This is the size of the element less margins, padding, and borders.

Parameters

elem{Object} the element to get the content size of.

Returns

{Object} an object with two properties, width and height, that are the size of the content area of the measured element.

getBorderBoxSize

getBorderBoxSize: function()

return the size of the border area of an element.  This is the size of the element less margins.

Parameters

elem{Object} the element to get the border sizing of.

Returns

{Object} an object with two properties, width and height, that are the size of the border area of the measured element.

getMarginBoxSize

getMarginBoxSize: function()

return the size of the margin area of an element.  This is the size of the element plus margins.

Parameters

elem{Object} the element to get the margin sizing of.

Returns

{Object} an object with two properties, width and height, that are the size of the margin area of the measured element.

setContentBoxSize

setContentBoxSize : function(size)

set either or both of the width and height of an element to the provided size.  This function ensures that the content area of the element is the requested size and the resulting size of the element may be larger depending on padding and borders.

Parameters

elem{Object} the element to set the content area of.
size{Object} an object with a width and/or height property that is the size to set the content area of the element to.

setBorderBoxSize

setBorderBoxSize : function(size)

set either or both of the width and height of an element to the provided size.  This function ensures that the border size of the element is the requested size and the resulting content areaof the element may be larger depending on padding and borders.

Parameters

elem{Object} the element to set the border size of.
size{Object} an object with a width and/or height property that is the size to set the content area of the element to.

getPaddingSize

getPaddingSize : function ()

returns the padding for each edge of an element

Parameters

elem{Object} The element to get the padding for.

Returns

{Object} an object with properties left, top, right and bottom that contain the associated padding values.

getBorderSize

getBorderSize : function()

returns the border size for each edge of an element

Parameters

elem{Object} The element to get the borders for.

Returns

{Object} an object with properties left, top, right and bottom that contain the associated border values.

descendantOf

descendantOf: function(node)

determines if the element is a descendent of the reference node.

Parameters

node{HTMLElement} the reference node

Returns

{Boolean} true if the element is a descendent, false otherwise.

findElement

findElement: function(type)

search the parentage of the element to find an element of the given tag name.

Parameters

type{String} the tag name of the element type to search for

Returns

{HTMLElement} the first node (this one or first parent) with the requested tag name or false if none are found.

Jx.ContentLoader

ContentLoader is a mix-in class that provides a consistent mechanism for other Jx controls to load content in one of four different ways:

  • using an existing element, by id
  • using an existing element, by object reference
  • using an HTML string
  • using a URL to get the content remotely

Use the Implements syntax in your Class to add Jx.ContentLoader to your class.

Summary
Options
contentcontent may be an HTML element reference, the id of an HTML element already in the DOM, or an HTML string that becomes the inner HTML of the element.
contentURLthe URL to load content from
Properties
contentIsLoadedtracks the load state of the content, specifically useful in the case of remote content.
Functions
loadContenttriggers loading of content based on options set for the current object.
checkRequest()Is fired after a delay to check the request to make sure it’s not failing in AIR.

Options

content

content may be an HTML element reference, the id of an HTML element already in the DOM, or an HTML string that becomes the inner HTML of the element.

contentURL

the URL to load content from

Properties

contentIsLoaded

tracks the load state of the content, specifically useful in the case of remote content.

Functions

loadContent

loadContent: function(element)

triggers loading of content based on options set for the current object.

Parameters

element{Object} the element to insert the content into

Events

ContentLoader adds the following events to an object.  You can register for these events using the addEvent method or by providing callback functions via the on{EventName} properties in the options object

contentLoadedcalled when the content has been loaded.  If the content is not asynchronous then this is called before loadContent returns.
contentLoadFailedcalled if the content fails to load, primarily useful when using the contentURL method of loading content.

checkRequest()

checkRequest: function()

Is fired after a delay to check the request to make sure it’s not failing in AIR.

Jx.AutoPosition

Mix-in class that provides a method for positioning elements relative to other elements.

Summary
Functions
positionpositions an element relative to another element based on the provided options.

Functions

position

position: function(element,
relative,
options)

positions an element relative to another element based on the provided options.  Positioning rules are a string with two space-separated values.  The first value references the parent element and the second value references the thing being positioned.  In general, multiple rules can be considered by passing an array of rules to the horizontal and vertical options.  The position method will attempt to position the element in relation to the relative element using the rules specified in the options.  If the element does not fit in the viewport using the rule, then the next rule is attempted.  If all rules fail, the last rule is used and element may extend outside the viewport.  Horizontal and vertical rules are processed independently.

Horizontal Positioning

Horizontal values are ‘left’, ‘center’, ‘right’, and numeric values.  Some common rules are:

  • ’left left’ is interpreted as aligning the left edge of the element to be positioned with the left edge of the reference element.
  • ’right right’ aligns the two right edges.
  • ’right left’ aligns the left edge of the element to the right of the reference element.
  • ’left right’ aligns the right edge of the element to the left edge of the reference element.

Vertical Positioning

Vertical values are ‘top’, ‘center’, ‘bottom’, and numeric values.  Some common rules are:

  • ’top top’ is interpreted as aligning the top edge of the element to be positioned with the top edge of the reference element.
  • ’bottom bottom’ aligns the two bottom edges.
  • ’bottom top’ aligns the top edge of the element to the bottom of the reference element.
  • ’top bottom’ aligns the bottom edge of the element to the top edge of the reference element.

Parameters

elementthe element to position
relativethe element to position relative to
optionsthe positioning options, see list below.

Options

horizontalthe horizontal positioning rule to use to position the element.  Valid values are ‘left’, ‘center’, ‘right’, and a numeric value.  The default value is ‘center center’.
verticalthe vertical positioning rule to use to position the element.  Valid values are ‘top’, ‘center’, ‘bottom’, and a numeric value.  The default value is ‘center center’.
offsetsan object containing numeric pixel offset values for the object being positioned as top, right, bottom and left properties.

Jx.Chrome

A mix-in class that provides chrome helper functions.  Chrome is the extraneous visual element that provides the look and feel to some elements i.e. dialogs.  Chrome is added inside the element specified but may bleed outside the element to provide drop shadows etc.  This is done by absolutely positioning the chrome objects in the container based on calculations using the margins, borders, and padding of the jxChrome class and the element it is added to.

Chrome can consist of either pure CSS border and background colors, or a background-image on the jxChrome class.  Using a background-image on the jxChrome class creates four images inside the chrome container that are positioned in the top-left, top-right, bottom-left and bottom-right corners of the chrome container and are sized to fill 50% of the width and height.  The images are positioned and clipped such that the appropriate corners of the chrome image are displayed in those locations.

Summary
Properties
chromethe DOM element that contains the chrome
Functions
makeChromecreate chrome on an element.
showChromeshow the chrome on an element.
hideChromeremoves the chrome from the DOM.

Properties

chrome

the DOM element that contains the chrome

Functions

makeChrome

makeChrome: function(element)

create chrome on an element.

Parameters

element{HTMLElement} the element to put the chrome on.

showChrome

showChrome: function(element)

show the chrome on an element.  This creates the chrome if necessary.  If the chrome has been previously created and not removed, you can call this without an element and it will just resize the chrome within its existing element.  You can also pass in a different element from which the chrome was previously attached to and it will move the chrome to the new element.

Parameters

element{HTMLElement} the element to show the chrome on.

hideChrome

hideChrome: function()

removes the chrome from the DOM.  If you do this, you can’t call showChrome with no arguments.

Jx.Addable

A mix-in class that provides a helper function that allows an object to be added to an existing element on the page.

Summary
Functions
addToadds the object to the DOM relative to another element.

Functions

addTo

addTo: function(reference,
where)

adds the object to the DOM relative to another element.  If you use ‘top’ or ‘bottom’ then the element is added to the relative element (becomes a child node).  If you use ‘before’ or ‘after’ then the element is inserted adjacent to the reference node.

Parameters

reference{Object} the DOM element or id of a DOM element to append the object relative to
where{String} where to append the element in relation to the reference node.  Can be ‘top’, ‘bottom’, ‘before’ or ‘after’.  The default is ‘bottom’.

Returns

the object itself, which is useful for chaining calls together

Jx.applyPNGFilter = function(o)
Static method that applies the PNG Filter Hack for IE browsers when showing 24bit PNG’s.
Jx.addToImgQueue = function(obj)
Request that an image be set to a DOM IMG element src attribute.
Jx.checkImgQueue = function()
An internal method that ensures no more than 2 images are loading at a time.
Jx.loadNextImg = function()
An internal method actually populate the DOM element with the image source.
Jx.createIframeShim = function()
Creates a new iframe element that is intended to fill a container to mask out other operating system controls (scrollbars, inputs, buttons, etc) when HTML elements are supposed to be above them.
Jx.getNumber = function(n,
def)
safely parse a number and return its integer value.
Jx.getPageDimensions = function()
return the dimensions of the browser client area.
getContentBoxSize : function()
return the size of the content area of an element.
getBorderBoxSize: function()
return the size of the border area of an element.
getMarginBoxSize: function()
return the size of the margin area of an element.
setContentBoxSize : function(size)
set either or both of the width and height of an element to the provided size.
setBorderBoxSize : function(size)
set either or both of the width and height of an element to the provided size.
getPaddingSize : function ()
returns the padding for each edge of an element
getBorderSize : function()
returns the border size for each edge of an element
descendantOf: function(node)
determines if the element is a descendent of the reference node.
findElement: function(type)
search the parentage of the element to find an element of the given tag name.
loadContent: function(element)
triggers loading of content based on options set for the current object.
checkRequest: function()
Is fired after a delay to check the request to make sure it’s not failing in AIR.
position: function(element,
relative,
options)
positions an element relative to another element based on the provided options.
makeChrome: function(element)
create chrome on an element.
showChrome: function(element)
show the chrome on an element.
hideChrome: function()
removes the chrome from the DOM.
addTo: function(reference,
where)
adds the object to the DOM relative to another element.