utils Class

Common functions and utilities used by the webcontrols

Constructors

There are no public constructors.

Events

onRender( el, callback )
Used to check whether DOM element has been added to the document. Calls a callback if it exists or when it is added.

Public Methods

get( url, config )
Used to execute an HTTP GET request. Example:
    get(url + "?filter=" + encodeURIComponent(filter), {
        success: function(text){
            var arr = JSON.parse(text).records;
        },
        failure: function(request){
            alert(request.status);
        }
    });
    
urlRequired.
configOptional. Common config settings include a "success" callback function, "failure" callback function, and "payload". Note that if a payload is given, an HTTP POST request will be executed. See the http() method for a full range of options.
post( url, payload, config )
Used to execute an HTTP POST request.
delete( url, config )
Used to execute an HTTP DELETE request.
http( url, config )
Used to execute an HTTP request.
getParameter( name, url )
Returns the value of a given parameter name in a URL querystring
nameParameter name
urlURL (e.g. window.location.href)
merge( settings, defaults )
Used to merge properties from one json object into another. Credit: https://github.com/stevenleadbeater/JSONT/blob/master/JSONT.js
clone( obj )
Used to clone a json object
isDirty( obj, org )
Returns true if the given json object differs from the original.
diff( obj1, obj2 )
Used to compare 2 json objects. Returns a json object with differences. Credit: https://stackoverflow.com/a/13389935/
isEmpty( obj )
Returns true if the given json object has no key/value pairs.
isArray( obj )
Used to check whether a given object is an array. Note that this check does not use the "instanceof Array" approach because of issues with frames.
isString( obj )
Return true if a given object is a string.
isNumber( n )
Return true if a given object is a number or can be parsed into a number.
isDate( d )
Return true if a given object can be parsed into a date. Returns false if the object is a number (e.g. "3", "1.2")
isElement( obj )
Return true if a given object is a DOM element.
setStyle( el, style )
Used to set the style for a given element, replacing whatever style was there before.
elDOM element.
styleIf a string is provided, assumes that the string represents a CSS class name update "class" attribute of given element. If a JSON object is provided, will assign the key/value pairs to the "style" attribute of the node.
addStyle( el, style )
Used to add style to a given element.
elDOM element.
styleIf a string is provided, assumes that the string represents a CSS class name update "class" attribute of given element. If a JSON object is provided, will assign the key/value pairs to the "style" attribute of the node.
hasStyleRule( selector )
Returns true if there is a style rule defined for a given selector.
selectorCSS selector (e.g. ".deleteIcon", "h2", "#mid")
addNoSelectRule( )
Inserts the "javaxt-noselect" class into the document if it is not present.
createElement( type, obj, style )
Used to create a DOM element
typeNode type (string). Example "div". This field is required.
objOptional. If a DOM element is provided, will append the newly created node into the element. Otherwise, will assume that the object is a style.
styleOptional. If a string is provided, assumes that the string represents a CSS class name update "class" attribute of the newly created node. If a JSON object is provided, will assign the key/value pairs to the "style" attribute.
createTable( parent )
Used to create a table element.
parentDOM element to append to (optional)
getSuggestedColumnWidths( records, pixelsPerChar )
Used to analyze a given dataset and suggest column widths for a table or a datagrid
recordsA two-dimensional array representing rows and columns
pixelsPerCharApproximate, average width of a character
updateDOM( )
Used to update the default befaviour of the browser to prevent things like right mouse click, scrolling beyond a page, and drag and drop.
getRect( el )
Returns the geometry of a given element.
intersects( r1, r2 )
Used to test whether two rectangles intersect.
getAreaOfIntersection( r1, r2 )
Returns the area of intersection between 2 rectangles.
getZScores( values, normalize )
Returns z-scores for a given set of values
valuesAn array of numbers
normalizeIf true, will return positive values for z-scores
initDrag( dragHandle, config )
addResizeListener( element, fn )
Used to watch for resize events for a given element. Credit: http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/
getHighestElements( obj )
Returns an array of elements at the highest z-index in the document
getNextHighestZindex( obj )
Returns an integer represeting the highest z-value of all the DOM elements that appear with the given object + 1
addShowHide( el )
Adds show/hide methods to a DOM element or javaxt component
destroy( me )
Used to help destroy javaxt components
round( number, decimalPlaces )
Rounds decimal to the nearest 10ths place.