The JavaScriptUtil contains a set of misc constants, functions and classes.
Note: The input field selection and caret operations work only on Internet Explorer for Windows
and Gecko-based browsers (FireFox, Mozilla, etc). On other browsers, the functions that return
values will return null, and functions that does not return values will do nothing.
|
Object manipulation functions |
booleanValue |
Determine if the object represents a true value |
debug |
Returns all properties in the object, sorted or not, with the separator between them |
decode |
Returns an argument depending on the value of the first argument |
functionName |
Returns the name of a function, given a function reference |
getObject |
Returns the reference to a named object |
ifEmpty |
Returns the first object if it is not empty (according to the isEmpty function), or the second object otherwise |
ifNull |
Returns the first object if it is not null, or the second object otherwise |
invoke |
Invokes a given function with the given arguments |
invokeAsMethod |
Invokes a given function with the given arguments as if it were a method of the given object |
isEmpty |
Returns if the object is null, an empty string, undefined or NaN |
isUndefined |
Returns if the object is undefined |
select |
Returns an argument depending on the boolean value of the prior argument |
|
Form elements manipulation functions |
addOption |
Adds an option to a select |
addOptions |
Adds all options from the array to a select |
checkAll |
Checks (or unchecks) all checkboxes |
clearOptions |
Removes all options from a select |
compareOptions |
Function used to compare two options by their text |
getCaret |
Returns the caret position |
getInputSelection |
Returns an input's selected text |
getInputSelectionRange |
Returns an input's selected range |
getValue |
Returns an object value |
isCaretSupported |
Returns if caret operations are supported in the given object |
isInputSelectionSupported |
Returns if input selection operations are supported in the given object |
prepareForCaret |
Prepares the input object to use caret or selection manipulation functions on Internet Explorer |
replaceSelection |
Replaces the selected text for a new one |
selectString |
Selects a given string on the input text |
setCaret |
Sets the caret to the specified position |
setCaretToEnd |
Sets the caret to the text end |
setCaretToStart |
Sets the caret to the text start |
setInputSelectionRange |
Sets the selection range on an input field |
setOptions |
Sets a select's options from an array |
setValue |
Sets an object value |
sortOptions |
Sorts the options on a Select |
transferOptions |
Transfers options from a select to another |
|
Array manipulation functions |
arrayConcat |
Returns an array containing all elements of both arrays |
arrayEquals |
Returns an the two arrays have exactly the same elements |
ensureArray |
Ensurea an array is returned |
inArray |
Returns if the object is in the array |
indexOf |
Returns the first index of the object within the array |
removeFromArray |
Removes all occurrences of the given objects is in the array |
|
Event manipulation functions |
observeEvent |
Adds an event listener to a given object |
preventDefault |
Makes the given event to not be completed (example: on keypress, the key is not accepted) |
stopPropagation |
Makes the event to stop propagating to innermost elements |
typedCode |
Returns the key code of the given event |
|
String manipulation functions |
capitalize |
Capitalizes a String |
crop |
Removes a specified number of characters from a String after a specified position |
escapeCharacters |
Escapes the string's special characters to their escaped form ('\\' to '\\\\', '\n' to '\\n', |
insertString |
Insert a String on another |
lcrop |
Removes a specified number of characters from the beggining of a String |
left |
Return 'n' charactes from the string's left side |
lpad |
Make the string have the specified length, completing with the specified character on the left |
ltrim |
Removes all specified characters on the String's left side |
mid |
Return 'n' charactes from the string's specified position |
onlyAlpha |
Return if the string has only letters or numbers |
onlyLetters |
Return if the string has only letters |
onlyNumbers |
Return if the string has only numbers |
onlySpecified |
Return if the string has only the specified characters |
rcrop |
Removes a specified number of characters from the end of a String |
repeat |
Repeats the given string a number of times |
replaceAll |
Replaces all the occurences in the string |
right |
Return 'n' charactes from the string's right side |
rpad |
Make the string have the specified length, completing with the specified character on the right |
rtrim |
Removes all specified characters on the String's right side |
trim |
Removes all specified characters on both sides of the String |
unescapeCharacters |
Unescapes the string, changing the special characters to their unescaped form ('\\\\' to '\\', '\\n' to '\n', '\\\\uXXXX' to the ASC(XXXX), |
|
Date manipulation functions |
dateAdd |
Adds a given amount on a given date field |
dateDiff |
Returns the difference, as in date2 - date1 |
getDateField |
Returns the value of a given date field |
getFullYear |
Returns the full year, given a 2 digit year |
getMaxDay |
Returns the maximum day of a given month and year |
setDateField |
Sets the value of a given date field |
truncDate |
Truncates the date, setting all fields lower than the specified one to its minimum value |
|
Cookie manipulation functions |
deleteCookie |
Removes the specified cookie |
readCookie |
Reads the specified cookie |
writeCookie |
Writes the specified cookie |
|
Style manipulation functions |
getOpacity |
Returns an object opacity |
setOpacity |
Sets an object opacity, to a value ranging from 0 to 100 |