Universal Web App (UWA) JavaScript namespace root object that contains UWA mains functions.
Index
Members
Methods
Members
-
<static> UWA.version :String
-
Current UWA API Version (e.g "1.3.RC4").
Type
- String
-
<static> UWA.hosts :Object
-
UWA hosts urls indexed by name.
Type
- Object
Properties:
Name Type Description netvibes
String Netvibes Dashboard url
uwa
String UWA resources url
exposition
String Exposition server url
ecosystem
String Ecosystem url
-
<static> UWA.paths :Object
-
UWA internal paths indexed by name.
Type
- Object
Properties:
Name Type Description lib
String Internal Library path (e.g: "/lib/")
js
String Internal JavaScript files (e.g: "/lib/UWA/js/")
css
String Internal Style Sheets and associaded assets (e.g: "/lib/c/UWA/assets/css/")
img
String Internal Images, Logo and Flash files (e.g: "/lib/c/UWA/assets/img/")
-
<static> UWA.debug :Boolean
-
Whether the framework is in debug mode or not.
If
true
, UWA will log extra messages, deactivate some caches etc. Iffalse
, UWA will add extra try / catches to prevent the application to break due to external errors.Type
- Boolean
Methods
-
<static> UWA.createElement()
-
Alias of UWA/Element.create
-
<static> UWA.extendElement()
-
Alias of UWA/Element.extend
-
<static> UWA.namespace(namespace, value, root, extend)
-
Store value argument into root argument using namespace argument as property name.
If the target namespace already exists, it will behave as told by the fourth argument:
- If it is omited, it will throw an exception
- If it is
"extend"
, it will extend the current namespace value with the properties of the new value - If it is
"replace"
, it will extend the new value with the current namespace value properties, then replace the namespace value - Deprecated: If it is
true
, it will behave like"extend"
but will merge properties recursively
See UWA.extend
Example
// Create a namespace UWA.namespace('MyProject', { myString: 'MyProject', myValues: [], myMethod: function () { } }); // Create a sub namespace UWA.namespace('MyProject/Utils/Tests', { myString: 'MyProject/Utils/Tests' }); // Extend a sub namespace UWA.namespace('MyProject/Utils', { myString: 'MyProject/Utils' }, 'extend');
Parameters
Name Type Argument Description namespace
Object The namespace name
value
Object The namespace new value
root
Object The Object that will store the namespace (default: global)
extend
String | Boolean <optional>
Existing namespace replacement (see method description)
-
<static> UWA.getGlobal() → {Object}
-
Returns the global object, e.g. window in browsers.
Returns
The global object.
- Type
- Object
-
<static> UWA.extend(original, extended, recursive)
-
Copies all the properties from the second passed object to the first passed object.
Example
var a = {key1: 'value1a', key2: 'value2a'}; var b = {key2: 'value2b', key3: 'value3b'}; UWA.extend(a, b); // will return {key1: 'value1a', 'key2: 'value2b', key3: 'value3b'}
Parameters
Name Type Description original
Object The object to extends
extended
Object The object to copy
recursive
Boolean Extends the sub objects too
-
<static> UWA.merge(original, extended)
-
Copies all the properties from the second passed object to the first passed object if it not exists already.
Example
var a = {key1: 'value1a', key2: 'value2a', key3: null}; var b = {key2: 'value2b', key3: 'value3b', key4: 'value4b'}; UWA.merge(a, b); // will return {key1: 'value1a', 'key2: 'value2a', key3: 'value3b', key4: 'value4b'}
Parameters
Name Type Description original
Object The object to extends
extended
Object The object to copy
-
<static> UWA.clone(object, deep)
-
Copies the properties from the object to remove references.
Example
var value = {}; var a = {key: value}; var b = UWA.clone(a); var c = UWA.clone(a,`false`); a === b; // will return `false` a.key === b.key; // will return `false` a === c; // will return `false` a.key === c.key; // will return `true` (because c is a shallow clone of a)
Parameters
Name Type Argument Default Description object
Object The object to copy
deep
Boolean <optional>
true If set to
false
, a shallow clone is returned instead of a deep cloneNote: Element and others complex or native object may fail to clone.
-
<static> UWA.result(object, property, fallback) → {Void}
-
Resolves the value of property key on object. If the value of key is a function (that should be nullary) then it is invoked with the object as context and its result is returned, otherwise the property value is returned. If the object or the property value is undefined, the fallback default value (if provided) is used in its place. The fallback default value can be a nullary function. In this case, it is invoked with the object as context and its result returned.
Example
var object = { user: 'fred', age: function () { return 40; } }; UWA.result(object, 'user'); // returns 'fred' UWA.result(object, 'age'); // returns 40 UWA.result(object, 'phone'); // returns undefined UWA.result(null, 'address'); // returns undefined UWA.result(object, 'status', 'busy'); // returns 'busy' UWA.result(null, 'status', 'busy'); // returns 'busy' UWA.result(object, 'status', function () { return 'fred' === this.user ? 'busy' : 'idle'; }); // returns 'busy'
Parameters
Name Type Argument Description object
Object The object to query.
property
string The key of the property to resolve.
fallback
Void <optional>
The value returned if the property value resolves to undefined.
Returns
Returns the resolved value.
- Type
- Void
-
<static> UWA.typeOf(object) → {String}
-
Returns the real type name of an object.
- 'window' (string) If object is a window.
- 'document' (string) If object is a DOM document node.
- 'element' (string) If object is a DOM element node.
- 'number' (string) If object is a number.
- 'boolean' (string) If object is a Boolean.
- 'arguments' (string) If object is a Arguments.
- 'math' (string) If object is a Math.
- 'error' (string) If object is a Error.
- 'array' (string) If object is an array.
- 'object' (string) If object is an object.
- 'string' (string) If object is a string.
- 'date' (string) If object is a Date.
- 'boolean' (string) If object is a boolean.
- 'function' (string) If object is a function.
- 'regexp' (string) If object is a regular expression.
- 'class' (string) If object is a Class (created with new Class or the extend of another class).
- 'file' (string) If object is a File
- 'nodelist' (string) If object is a NodeList
- 'typedarray' (string) If object is a TypedArray
- 'dataview' (string) If object is a DataView
- 'false' (boolean) If object is undefined, null, NaN or none of the above.
Example
// Detected types UWA.typeOf(window); // "window" UWA.typeOf(document); // "document" UWA.typeOf({a: 4}); // "object" UWA.typeOf(new ReferenceError); // "error" UWA.typeOf([1, 2, 3]); // "array" UWA.typeOf(new Date); // "date" UWA.typeOf(/a-z/); // "regexp" UWA.typeOf(new RegExp(/a-z/)); // "regexp" UWA.typeOf(new Number(4)); // "number" UWA.typeOf(new String("abc")); // "string" UWA.typeOf(""); // "string" UWA.typeOf(true); // "boolean" UWA.typeOf(false); // "boolean" UWA.typeOf(new Boolean(true)); // "boolean" UWA.typeOf(new Boolean(true)); // "boolean" UWA.typeOf((function () {})); // "function" UWA.typeOf(new File(...)); // "file" // Invalid types UWA.typeOf(); // false UWA.typeOf(window.myUndefined); // false UWA.typeOf(null); // false UWA.typeOf("x" - 111); // false // Other types UWA.typeOf(Math); // "object" UWA.typeOf(RegExp); // "function"
Parameters
Name Type Description object
Void the object to inspect
Returns
Object type name or
false
if is undefined, null or NaN.- Type
- String
-
<static> UWA.is(object, type) → {Boolean}
-
Check the type of an object or if is not an undefined, null or NaN, and match the type parameter if provided.
Example
// Will return false UWA.is(null); // false UWA.is(); // false UWA.is(window.myUndefined); // false // Will return true UWA.is({}); // true UWA.is(function () {}); // true UWA.is(UWA); // true // Check type UWA.is({}, 'object'); // true UWA.is("hello", 'string'); // true UWA.is(1, 'number'); // true UWA.is(true, 'boolean'); // true UWA.is(true, 'boolean'); // true UWA.is(new Date, 'date'); // true // Check for plain objects. Plain objects are "Plain Old objects", meaning that they are not instance of any class other than Object UWA.is({}, 'plain'); // true UWA.is(Object.create({a: 1}), 'plain'); // false // Multiple check (better performance than multiple call to UWA.is) UWA.is(window, ['window', 'document']); // true
Parameters
Name Type Description object
Void The object to inspect
type
String The expected object type
Returns
Return
true
if is not an undefined, null or NaN, and match the type parameter if provided.- Type
- Boolean
- See:
-
- UWA.typeOf for type parameter matching.
-
<static> UWA.equals(x, y) → {Boolean}
-
Perform a deep comparison to check if the two objects passed as arguments are equal.
Note that this method tests the equality of the two objects, it does not test whether or not they are identical. To check the identity of two objects, use <Object.is Object.is> or the === operator.
Example
var moe = {name : 'moe', luckyNumbers : [13, 27, 34]}; var clone = {name : 'moe', luckyNumbers : [13, 27, 34]}; var anotherClone = UWA.clone(moe); moe === clone; // returns false moe === anotherClone; // returns false UWA.equals(moe, clone); // returns true UWA.equals(moe, anotherClone); // returns true
Parameters
Name Type Description x
Object The first object
y
Object The second object
Returns
true
if the two objects are equal,false
otherwise.- Type
- Boolean
-
<static> UWA.owns(object, property) → {Boolean}
-
Returns a boolean indicating whether the object has the specified property.
Example
// Simple Examples var myObject = { myProp: true, myUndefinedProp: undefined }; UWA.owns(myObject, 'myProp'); // true UWA.owns(myObject, 'myUndefinedProp'); // true UWA.owns(myObject, 'myMissingProp'); // false
Parameters
Name Type Description object
Object The object owner of the property to test
property
String The name of the property to test
Returns
Return
true
if the object has the specified property.- Type
- Boolean
-
<static> UWA.log(message)
-
Log a message to a console, if one available.
Example
UWA.log("Widget is loading ...");
Parameters
Name Type Description message
String The message to log
-
<static> UWA.i18n(message, lang) → {String|Object}
-
Translate a string from English to the current language.
Examples
// Create Alias to UWA.i18n var i18n = UWA.i18n; i18n("Hello"); // Will return "Hello" // Add French translation for "Hello" i18n({ "Hello": 'Bonjour' }); i18n("Hello"); // Will return "Bonjour"
// Create Alias to UWA.i18n var i18n = UWA.i18n; UWA.String.format(i18n("Hello {0} welcome on {1}.", 'John', 'UWA'); // Will return "Hello John welcome on UWA." // Add French translation for "Hello" i18n({ "Hello {0} welcome on {1}.": 'Bonjour {0} bienvenue sur {1}.' }); UWA.String.format(i18n("Hello {0} welcome on {1}.", 'John', 'UWA'); // Will return "Bonjour John bienvenue sur UWA."
Parameters
Name Type Description message
String | Object The message String to translate or the object hash message/translation pair.
lang
String The current locale (default: "default")
Returns
The translated string if argument is a string else the new object hash message/translation pair if argument is an object.
- Type
- String | Object