Namespace foodev
The Foodev namespace and fundamental methods to create packages/classes.
The global foodev object itself is an instance of Package with additional static method
as detailed below.
Defined in: base.js.
Constructor Attributes | Constructor Name and Description |
---|---|
The Foodev namespace and fundamental methods to create packages/classes.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
foodev.addClass(el, cls)
Adds the given class if it's not already present on the element.
|
<static> |
foodev.ancIs(ancestor, el)
Tells if the given ancestor DOM element is an ancestor of the given element.
|
<static> |
foodev.arrIn(array, elt, from)
Returns the first index of the value in the given array.
|
<static> |
foodev.arrIs(array)
Tells if the given object is an array instance.
|
<static> |
foodev.arrRm(array, from, to)
Removes the elements from index 'from' to index 'to', both inclusive.
|
<static> |
foodev.assert(val, name, type, undefinedOk, nullOk)
Helper method to assert that a required parameter is not undefined and if it has a value, is
of the specified type given.
|
<static> |
foodev.bind(func, scope, arguments)
Binds the function to have the scope object as 'this' during invocation.
|
<static> |
foodev.Class(cname, obj)
Creates a new class under the package the function is being invoked on.
|
<static> |
foodev.classForName(cname)
Returns the class for the given string name.
|
<static> |
foodev.elByClass(className, ancestor)
Returns an element found by class name, ensuring that the optional ancestor parameter is an
ancestor somewhere up the parent chain.
|
<static> |
foodev.elIs(o)
Tells if the given object is a DOM element.
|
<static> |
foodev.extend(target, source)
Copy all properties of a source object to a target object.
|
<static> |
foodev.getStyle(el, style)
Returns the current active style for the given element.
|
<static> |
foodev.hasClass(el, cls)
Tests if the given element has the given class.
|
<static> |
foodev.jsonp(req)
Function to make jsonp request.
|
<static> |
foodev.measure(el, attachTo)
Measures the given element even if it is not currently attached.
|
<static> |
foodev.objToReqParams(param)
Turns the given object of key-values into a string of request parameters.
|
<static> |
foodev.Package(subPackageName)
Creates a package underneath this current package.
|
<static> |
foodev.removeClass(el, cls)
Removes the given class from the element if it's present.
|
<static> |
foodev.RootPackage(rootPackageName)
Creates a new root package under the window scope.
|
<static> |
foodev.tween(duration, el, from, to)
Tweens properties between (numerical) values.
|
<static> |
foodev.valueForPath(obj, path, delim)
Returns the value for the property of the given (dot delimited) path, starting from 'obj'.
|
<static> |
foodev.xhr(req)
Function to make ajax request.
|
Namespace Detail
foodev
The Foodev namespace and fundamental methods to create packages/classes.
The global foodev object itself is an instance of Package with additional static method as detailed below.
Author: Martin Algesten.
The global foodev object itself is an instance of Package with additional static method as detailed below.
Author: Martin Algesten.
Method Detail
<static>
foodev.addClass(el, cls)
Adds the given class if it's not already present on the element.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Element} el
- the element to add to
- {String} cls
- the class to add (takes more classes as additional arguments).
<static>
{Boolean}
foodev.ancIs(ancestor, el)
Tells if the given ancestor DOM element is an ancestor of the given element.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Element} ancestor
- the ancestor element
- {Element} el
- the child element
- Returns:
- {Boolean} true if ancestor is somewhere up the parent chain.
<static>
{Number}
foodev.arrIn(array, elt, from)
Returns the first index of the value in the given array.
Defined in: util.js.
This method is normally inserted into the Array object, but we don't want to pollute anything outside the foodev package.
Defined in: util.js.
- Parameters:
- {Array} array
- Array to resolve the value in.
- {Mixed} elt
- Value to find the index for in the array.
- {boolean} from Optional, Default: 0
- The index to start the search from.
- Returns:
- {Number} The index of the value in the array, if found, else -1.
<static>
{boolean}
foodev.arrIs(array)
Tells if the given object is an array instance.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Object} array
- Object to test.
- Returns:
- {boolean} True if the object given is an {Array}.
<static>
{Array}
foodev.arrRm(array, from, to)
Removes the elements from index 'from' to index 'to', both inclusive.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Array} array
- Array to remove elements from. This array is left untouched.
- {Number} from Optional, Default: 0
- Index of first element to remove, inclusive.
- {Number} to Optional
- Index of last element to remove, inclusive. If not provided, set to the same value as from to remove only the value at from.
- Returns:
- {Array} A (shallow) copy of the given array with the elements removed.
<static>
foodev.assert(val, name, type, undefinedOk, nullOk)
Helper method to assert that a required parameter is not undefined and if it has a value, is
of the specified type given.
Defined in: util.js.
It's possible to turn off asserts by setting foodev.assert
to false before
loading the util.js file.
Defined in: util.js.
- Parameters:
- {Object} val
- Value of the parameter. This will be asserted to be a value and
- {String} name
- Name of the parameter, used for throw
- {Mixed} type Optional
- Either a string specifying a primitive type such as 'number', 'string', 'boolean', 'object', 'function' or a real function to specify an instanceof object type. Primitive type 'array' and (DOM) 'element' are also handled. If not provided, type is not enforced.
- {boolean} undefinedOk Optional, Default: false
- If it is okay with undefined values. Default is false.
- {boolean} nullOk Optional, Default: false
- If it is okay with null values. Default is false.
<static>
{Function}
foodev.bind(func, scope, arguments)
Binds the function to have the scope object as 'this' during invocation. The function can
take an optional number of arguments after the 'func' argument, these will be prepended to
the invocation of the bound function.
Defined in: util.js.
Defined in: util.js.
var bound1 = foodev.bind(a, b); bound1('xyz'); // will invoke function a with 'this' // set to b and arguments ('xyz'). var bound2 = foodev.bind(a, b, 42, c); bound2('xyz'); // will invoke function a with 'this' // set to b and arguments (42, c, 'xyz').
- Parameters:
- {Function} func
- Function to bind the scope to.
- {Object} scope
- Scope to set as 'this' during invocation of func.
- arguments
- Variable number of arguments can be supplied that will be prepended to any arguments in the invocation of the bound function.
- Returns:
- {Function} A function that will have 'this' set to scope during invocation.
<static>
foodev.Class(cname, obj)
Creates a new class under the package the function is being invoked on. Every package
created using Package#Package will have this method for creating classes
under that package.
This method exist on all packages/subpackages created using the foodev.Package method.
// This constructs a new class at foodev.bar.Test
foodev.bar.Class( 'Test', {
initialize: function () {
// constructor
}
});
new foodev.bar.Test() instanceof foodev.bar.Test // true
// This constructs a new class and returns it.
// This allows a class to be used in a closure and remain "private".
// foodev.Test will not be available in this example. Instead MyPrivateClass
// in the current scope/closures will.
var MyPrivateClass = foodev.Class( 'Test', {
Private: true,
initialize: function () {
// constructor
}
});
- Parameters:
- {String} cname
- The name of the new class to create.
- {Object} obj
- Object containing the functions/fields to put into the new class prototype.
- {Function} obj.initialize
- A function that is used to construct new instances of the class.
- {Class} obj.Extends Optional
- A class to inherit from.
- {Boolean} obj.Private Optional, Default: false
- If set to true the class will not be exposed in the Package. It will be returned instead allowing for it to be used in a closure and thus remain 'private'.
<static>
{Function}
foodev.classForName(cname)
Returns the class for the given string name.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {String} cname
- Name of the class to get.
- Returns:
- {Function} The constructor function of the class for the given name or null if not found.
<static>
foodev.elByClass(className, ancestor)
Returns an element found by class name, ensuring that the optional ancestor parameter is an
ancestor somewhere up the parent chain.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {String} className
- the css class name of the element to find
- {Element} ancestor Optional, Default: null
- optional ancestor element, any ancestor up the parent chain works.
- Returns:
- the first element that matches the parameters, or null.
<static>
foodev.elIs(o)
Tells if the given object is a DOM element.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Element} o
- the object to test
- Returns:
- true if the given object is a dom element.
<static>
{Object}
foodev.extend(target, source)
Copy all properties of a source object to a target object. Modifies the passed in target
object. Any properties on the source object that are set to undefined will not be (re)set on
the destination object.
- Parameters:
- {Object} target
- The object that will be modified or null to make new object.
- {Object} source
- The object with properties to be set on the destination. It's possible to pass multiple source objects.
- Returns:
- {Object} The destination object. In case target is null, this is a newly created
object.
Function borrowed from OpenLayers: Copyright (c) 2005-2008 MetaCarta, Inc.
<static>
{String}
foodev.getStyle(el, style)
Returns the current active style for the given element.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Elememt} el
- the element to calculate active style for.
- {String} style
- the style to calculate provided either as camel caze (backgroundColor) or hyphenated (background-color).
- Returns:
- {String} The calculated style as a string or null.
<static>
{Boolean}
foodev.hasClass(el, cls)
Tests if the given element has the given class.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Element} el
- the element to check
- {String} cls
- the class to check for
- Returns:
- {Boolean} true or false
<static>
{Object}
foodev.jsonp(req)
Function to make jsonp request. The provided req object encapsulates the request to be
made.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Object} req
- encapsulating request object.
- {String} req.url
- the request url.
- {String} req.callback Optional, Default: "jsonp"
- the name of the jsonp callback.
- {Object} req.params Optional
- key-value-pair parameters to send with the request.
- {Number} req.timeout Optional
- amount of milliseconds to wait before the request is considered to have timed out.
- {Function} req.before Optional
- callback that will be invoked right before the load occurs.
- {Function} req.success Optional
- callback that will be invoked on success.
- {Function} req.failure Optional
- callback that will be invoked on timeout, if req.timeout is larger than 0.
- {Function} req.complete Optional
- callback that will be invoked regardless of success or timeout.
- {Function} req.abort Optional
- callback that will be invoked on abort.
- {Object} req.bind Optional
- object to bind all the callbacks to.
- {Function} req.dataFilter Optional
- callback that will be invoked once the request has complete. The callback will receive the JSON object from the server and the request object. The callback is expected to return a JSON object to pass to the success/failure/complete callbacks.
- Returns:
- {Object} An object with a single function
abort()
which can be used to abort the request.
<static>
{Object}
foodev.measure(el, attachTo)
Measures the given element even if it is not currently attached. The measurement includes,
width, height and absolute position from document top left (0,0).
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Element} el
- the element to measure.
- {Element} attachTo Optional
- optional element to attach the element to when measuring.
- Returns:
- {Object} with the properties
w
for width andh
for height in pixels,x
for offset x,y
for offset y.
<static>
foodev.objToReqParams(param)
Turns the given object of key-values into a string of request parameters. Will not prepend an ampersand (&)
or question mark (?) in front of the first value. Handles also the case where the value is an array by turning
the values into a comma separated string.
var obj = {
key1: 'value1',
key2: 'value2',
key3: ['a1', 'a2', 'a3']
};
var str = foodev.objToReqParams(obj);
// str is now 'key1=value1&key2=value2&key3=a1,a2,a3'
Defined in: util.js.
- Parameters:
- {String} param
- the parameter object to turn into request parameter string.
- Returns:
- the request parameter string.
<static>
foodev.Package(subPackageName)
Creates a package underneath this current package. All packages created this way
receives three functions: Package#Class, Package#Package,
Package#RootPackage which are used to create classes and further subpackages
under the current package.
This method exist on all packages/subpackages created using the foodev.Package method.
Create a package under foodev.example foodev.Package('example'); // foodev.example is now available foodev.Package('example.bar.baz') foodev.example.bar.baz is now available
- Parameters:
- {String} subPackageName
- The new package name. This can be dot notation to create deep sub packages.
<static>
foodev.removeClass(el, cls)
Removes the given class from the element if it's present.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Element} el
- the element to remove from.
- {String} cls
- the class to remove (takes more classes as additional arguments).
<static>
foodev.RootPackage(rootPackageName)
Creates a new root package under the window scope.
Create a root package named example. foodev.RootPackage('example'); // Object example is now avaiable in the global scope.
- Parameters:
- {String} rootPackageName
- The root package name.
<static>
{Object}
foodev.tween(duration, el, from, to)
Tweens properties between (numerical) values.
Defined in: fx.js.
Defined in: fx.js.
- Parameters:
- {Number} duration
- time in milliseconds for tween.
- {Element} el
- the node to change style attributes on
- {Object} from
- definition of properties to tween from.
- {Object} from.prop
- start value for property named 'prop'. Valid values are numerics and strings that holds number suffixed with 'px' or 'em'.
- {Object} from.onStart Optional
- function to invoke upon start.
- {Object} from.onEnd Optional
- function to invoke upon completion.
- {Object} to
- definition of properties to tween to.
- {Object} to.prop
- end value for property named 'prop'.
- Returns:
- {Object} with one single function
cancel()
which can be used to cancel animation.
<static>
{Mixed}
foodev.valueForPath(obj, path, delim)
Returns the value for the property of the given (dot delimited) path, starting from 'obj'.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Object} obj
- Object to resolve the path from.
- {String} path
- The
delim
delimited path to resolve a value for. - {String} delim Optional, Default: '.'
- Delimiter to use.
- Returns:
- {Mixed} The property found at path, or null. Null is also returned if the full path can't be resolved.
<static>
foodev.xhr(req)
Function to make ajax request. The provided req object encapsulates the request to be made.
Defined in: util.js.
Defined in: util.js.
- Parameters:
- {Object} req
- encapsulating request object.
- {String} req.url
- the request url.
- {String} req.method Optional, Default: "GET"
- request method, defaults to GET.
- {String} req.body Optional
- request body.
- {Function} req.success Optional
- callback that will receive the success.
- {Function} req.failure Optional
- callback that will receive the failure.
- {Function} req.complete Optional
- callback that will be invoked after the success and failure callback.
- {Object} req.bind Optional
- object to bind the success/failure callbacks to.