Methods
(static) blurAll(node)
Blurs (unfocuses) a specified DOM node and all relevant child nodes. This
function will recursively blur all <a>
, <button>
, <input>
,
<textarea>
and <select>
child nodes found.
- Parameters:
-
Name Type Description node
{Object} the HTML DOM node - Source:
- RapidContext.Util.js, line 215
(static) dict(itemsOrKeys, valuesopt) → {Object}
Creates a dictionary object from a list of keys and values. Optionally a list of key-value pairs can be provided instead. As a third option, a single (non-array) value can be assigned to all the keys.
If a key is specified twice, only the last value will be used. Note that
this function is the reverse of MochiKit.Base.items()
,
MochiKit.Base.keys()
and MochiKit.Base.values()
.
- Parameters:
-
Name Type Attributes Description itemsOrKeys
{Array} the list of keys or items values
{Array} <optional>
the list of values (optional if key-value pairs are specified in first argument) - Returns:
- {Object} an object with properties for each key-value pair
- Examples:
-
RapidContext.Util.dict(['a','b'], [1, 2]) ==> { a: 1, b: 2 }
RapidContext.Util.dict([['a', 1], ['b', 2]]) ==> { a: 1, b: 2 }
RapidContext.Util.dict(['a','b'], true) ==> { a: true, b: true }
- Source:
- RapidContext.Util.js, line 60
(static) mask(src, keys) → {Object}
Filters an object by removing a list of keys. A list of key names (or an object whose property names will be used as keys) must be specified as an argument. A new object containing the source object values for the specified keys will be returned. The source object will be modified by removing all the specified keys.
- Parameters:
-
Name Type Description src
{Object} the source object to select and modify keys
{Array|Object} the list of keys to remove, or an object with the keys to remove - Returns:
- {Object} a new object containing the matching keys and values found in the source object
- Deprecated:
- This function will be removed in the future.
- Examples:
-
var o = { a: 1, b: 2 }; RapidContext.Util.mask(o, ['a', 'c']); ==> { a: 1 } and modifies o to { b: 2 }
var o = { a: 1, b: 2 }; RapidContext.Util.mask(o, { a: null, c: null }); ==> { a: 1 } and modifies o to { b: 2 }
- Source:
- RapidContext.Util.js, line 109
(static) registerSizeConstraints(node, widthopt, heightopt)
Registers size constraints for the element width and/or height. The constraints may either be fixed numeric values or simple arithmetic (in a string). The formulas will be converted to CSS calc() expressions.
Legacy constraint functions are still supported and must take two arguments (parent width and height) and should return a number. The returned number is set as the new element width or height (in pixels). Any returned value will also be bounded by the parent element size to avoid calculation errors.
- Parameters:
-
Name Type Attributes Description node
{Object} the HTML DOM node width
{number|string|function} <optional>
the width constraint height
{number|string|function} <optional>
the height constraint - See:
- RapidContext.Util.resizeElements
- Examples:
-
RapidContext.Util.registerSizeConstraints(node, "50%-20", "100%"); ==> Sets width to 50%-20 px and height to 100% of parent dimension
RapidContext.Util.resizeElements(node, otherNode); ==> Evaluates the size constraints for both nodes
- Source:
- RapidContext.Util.js, line 250
(static) resizeElements(…node)
Resizes one or more DOM nodes using their registered size constraints and their parent element sizes. The resize operation will only modify those elements that have constraints, but will perform a depth-first recursion over all element child nodes as well.
Partial constraints are accepted, in which case only the width or the height is modified. Aspect ratio constraints are applied after the width and height constraints. The result will always be bounded by the parent element width or height.
The recursive descent of this function can be limited by adding a
resizeContent
function to a DOM node. Such a function will be called to
handle all subnode resizing, making it possible to limit or omitting the
DOM tree traversal.
- Parameters:
-
Name Type Attributes Description node
{Node} <repeatable>
the HTML DOM nodes to resize - See:
- RapidContext.Util.registerSizeConstraints
- Examples:
-
RapidContext.Util.resizeElements(node); ==> Evaluates the size constraints for a node and all child nodes
elem.resizeContent = () => {}; ==> Assigns a no-op child resize handler to elem
- Source:
- RapidContext.Util.js, line 303
(static) resolveURI(uri, baseopt) → {string}
Resolves a relative URI to an absolute URI. This function will return absolute URI:s directly and traverse any "../" directory paths in the specified URI. The base URI provided must be absolute.
- Parameters:
-
Name Type Attributes Description uri
{string} the relative URI to resolve base
{string} <optional>
the absolute base URI, defaults to the the current document base URI - Returns:
- {string} the resolved absolute URI
- Deprecated:
- This function will be removed and/or renamed in the future. Better solutions for handling URL:s is to use a URL-parsing library such as URL.js.
- Source:
- RapidContext.Util.js, line 178
(static) toTitleCase(str) → {string}
Converts a string to a title-cased string. All word boundaries are replaced with a single space and the subsequent character is capitalized.
All underscore ("_"), hyphen ("-") and lower-upper character pairs are recognized as word boundaries. Note that this function does not change the capitalization of other characters in the string.
- Parameters:
-
Name Type Description str
{string} the string to convert - Returns:
- {string} the converted string
- Examples:
-
RapidContext.Util.toTitleCase("a short heading") ==> "A Short Heading"
RapidContext.Util.toTitleCase("camelCase") ==> "Camel Case"
RapidContext.Util.toTitleCase("bounding-box") ==> "Bounding Box"
RapidContext.Util.toTitleCase("UPPER_CASE_VALUE") ==> "UPPER CASE VALUE"
- Source:
- RapidContext.Util.js, line 152