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)
createClipboard( parent )
Used to create a hidden clipboard in a given parent. Text and other data can be inserted into the clipboard via the insert() method on the DOM object returned by this method. Once data is inserted into the clipboard, clients can retrieve the data via the browser "paste" event (e.g. ctrl+v on windows).
parentDOM element used to hold the clipboard (required)
getSuggestedColumnWidths( records, pixelsPerChar, maxWidth )
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
maxWidthOptional. The available width for the table/grid control
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 )
Used to update a DOM element and enable dragging. It is up to the caller to process the drag events and update the DOM element via event handlers defined in the config. Example:
    initDrag(div, {
        onDragStart: function(mouseX, mouseY){
            //Do something, like compute x/y offsets, update cursor, etc
        },
        onDrag: function(mouseX, mouseY){
            this.style.left = x + 'px';
            this.style.top = y + 'px';
        },
        onDragEnd: function(){
            //Do something, like repost position, update cursor, etc
        }
    });
    
addResizeListener( element, fn )
Used to watch for resize events for a given element.
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.
alert( msg, config )
Used to render an alert dialog using the javaxt.dhtml.Window class.
msgMessage to display in the alert. Supports strings and XHR responses with "responseText".
configOptional config used to instantiate the javaxt.dhtml.Window class.
confirm( msg, config )
Used to render a confirm dialog using the javaxt.dhtml.Window class. Example:
    javaxt.dhtml.utils.confirm({
        title: "Quit Game?",
        text: "Are you sure you want to quit the game?",
        leftButton: {
            label: "Yes",
            value: true
        },
        rightButton: {
            label: "No",
            value: false
        },
        callback: function(answer){
            if (answer===true) console.log("quit game");
            else console.log("continue game");
        }
    });
    
msgString with question/prompt or a JSON config like the example above. If passing a string, a default config is used which can be overridden using the optional "config" parameter.
configJSON config like the example above. This parameter is optional.