new BindingUtils()
Binding utilities class
Used to bind properties of EventDispatcher class instances to DOM elements,
other EventDispatcher class instances or setter functions
Extends
Members
removeAttributeAfterBinding :boolean
Should binding attributes, like "cb-bind", be removed after they've been processed?
Type:
- boolean
supro
Similar to `super` in ActionScript or Java, this property enables
you to access properties and methods of the super class prototype,
which is the case of JavaScript is the next prototype up the chain
- Inherited From:
- Source:
Methods
applyAttribute(element, attributeName) → {conbo.BindingUtils}
Applies the specified read-only Conbo or custom attribute to the specified element
Parameters:
Name | Type | Description |
---|---|---|
element |
HTMLElement | DOM element to bind value to (two-way bind on input/form elements) |
attributeName |
string | The attribute to bind as it appears in HTML, e.g. "cb-prop-name" |
Returns:
A reference to this object
- Type
- conbo.BindingUtils
Example
conbo.bindingUtils.applyAttribute(el, "my-custom-attr");
applyViews(rootView, namespace, typeopt) → {conbo.BindingUtils}
Applies View and Glimpse classes DOM elements based on their cb-view
attribute or tag name
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
rootView |
HTMLElement | DOM element, View or Application class instance | ||
namespace |
conbo.Namespace | The current namespace | ||
type |
string |
<optional> |
view | View type, 'view' or 'glimpse' |
Returns:
A reference to this object
- Type
- conbo.BindingUtils
attributeExists(attributeName) → {Boolean}
Does the specified Conbo or custom attribute exist?
Parameters:
Name | Type | Description |
---|---|---|
attributeName |
string | The attribute name as it appears in HTML, e.g. "cb-prop-name" |
Returns:
- Type
- Boolean
bindAll(…methodNameopt) → {this}
Scope all methods of this class instance to this class instance
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
methodName |
string |
<optional> <repeatable> |
Specific method names to bind (all will be bound if none specified) |
- Inherited From:
- Source:
Returns:
- Type
- this
bindAttribute(source, propertyName, element, attributeName, parseFunctionopt, optionsopt) → {Array}
Bind a DOM element to the property of a EventDispatcher class instance,
e.g. Hash or Model, using cb-* attributes to specify how the binding
should be made.
Two way bindings will automatically be applied where the attribute name
matches a property on the target element, meaning your EventDispatcher object
will automatically be updated when the property changes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
source |
conbo.EventDispatcher | Class instance which extends from conbo.EventDispatcher (e.g. Hash or Model) | |
propertyName |
string | Property name to bind | |
element |
HTMLElement | DOM element to bind value to (two-way bind on input/form elements) | |
attributeName |
string | The attribute to bind as it appears in HTML, e.g. "cb-prop-name" | |
parseFunction |
function |
<optional> |
Method used to parse values before outputting as HTML |
options |
Object |
<optional> |
Options related to this attribute binding |
Returns:
Array of bindings
- Type
- Array
bindElement(source, propertyName, el, parseFunctionopt) → {Array}
Bind a property of a EventDispatcher class instance (e.g. Hash or View)
to a DOM element's value/content, using ConboJS's best judgement to
work out how the value should be bound to the element.
This method of binding also allows for the use of a parse function,
which can be used to manipulate bound data in real time
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
source |
conbo.EventDispatcher | Class instance which extends from conbo.EventDispatcher | |
propertyName |
string | Property name to bind | |
el |
HTMLElement | DOM element to bind value to (two-way bind on input/form elements) | |
parseFunction |
function |
<optional> |
Optional method used to parse values before outputting as HTML |
Returns:
Array of bindings
- Type
- Array
bindProperty(source, sourcePropertyName, destination, destinationPropertyNameopt, twoWayopt) → {conbo.BindingUtils}
Bind the property of one EventDispatcher class instance (e.g. Hash or View) to another
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
source |
conbo.EventDispatcher | Class instance which extends conbo.EventDispatcher | ||
sourcePropertyName |
string | Source property name | ||
destination |
* | Object or class instance which extends conbo.EventDispatcher | ||
destinationPropertyName |
string |
<optional> |
Defaults to same value as sourcePropertyName | |
twoWay |
Boolean |
<optional> |
false | Apply 2-way binding |
Returns:
A reference to this object
- Type
- conbo.BindingUtils
bindSetter(source, propertyName, setterFunction) → {conbo.BindingUtils}
Call a setter function when the specified property of a EventDispatcher
class instance (e.g. Hash or Model) is changed
Parameters:
Name | Type | Description |
---|---|---|
source |
conbo.EventDispatcher | Class instance which extends conbo.EventDispatcher |
propertyName |
string | |
setterFunction |
function |
Returns:
A reference to this object
- Type
- conbo.BindingUtils
bindView(view) → {conbo.BindingUtils}
Bind everything within the DOM scope of a View to properties of the View instance
Parameters:
Name | Type | Description |
---|---|---|
view |
conbo.View | The View class controlling the element |
Returns:
A reference to this object
- Type
- conbo.BindingUtils
declarations() → {void}
Declarations is used to declare instance properties used by this class
Parameters:
Type | Attributes | Description |
---|---|---|
* |
<repeatable> |
- Inherited From:
- Source:
Returns:
- Type
- void
defaultParseFunction(value) → {*}
Default parse function
Parameters:
Name | Type | Description |
---|---|---|
value |
* | The value to be parsed |
Returns:
The parsed value
- Type
- *
destroy() → {void}
Clean everything up ready for garbage collection (you should override in your own classes)
- Inherited From:
- Source:
Returns:
- Type
- void
getClass(className, namespace) → {*}
Attempt to convert string into a conbo.Class in the specified namespace
Parameters:
Name | Type | Description |
---|---|---|
className |
string | The name of the class |
namespace |
conbo.Namespace | The namespace containing the class |
Returns:
- Type
- *
initialize() → {void}
Initialize (entry point) is called immediately after the constructor has completed
Parameters:
Type | Attributes | Description |
---|---|---|
* |
<repeatable> |
- Inherited From:
- Source:
Returns:
- Type
- void
parseTemplate(template) → {string}
Parses a template, preparing values in {{double}} curly brackets to
be replaced with bindable text nodes
Parameters:
Name | Type | Description |
---|---|---|
template |
string | String containing a View template |
Returns:
The parsed template
- Type
- string
preinitialize() → {void}
Preinitialize is called before any code in the constructor has been run
Parameters:
Type | Attributes | Description |
---|---|---|
* |
<repeatable> |
- Inherited From:
- Source:
Returns:
- Type
- void
registerAttribute(name, handler, readOnly, rawopt) → {conbo.BindingUtils}
Register a custom attribute handler
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | camelCase version of the attribute name (must include a namespace prefix) | ||
handler |
function | function that will handle the data bound to the element | ||
readOnly |
boolean | Whether or not the attribute is read-only (default: false) | ||
raw |
boolean |
<optional> |
false | Whether or not parameters should be passed to the handler as a raw String instead of a bound value |
Returns:
A reference to this object
- Type
- conbo.BindingUtils
Example
// HTML: <div my-font-name="myProperty"></div>
conbo.bindingUtils.registerAttribute('myFontName', function(el, value, options, param)
{
el.style.fontName = value;
});
registerAttributes(handlers, readOnlyopt) → {conbo.BindingUtils}
Register one or more custom attribute handlers
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
handlers |
Object | Object containing one or more custom attribute handlers | ||
readOnly |
boolean |
<optional> |
false | Whether or not the attributes are read-only |
- Source:
- See:
Returns:
A reference to this object
- Type
- conbo.BindingUtils
Example
conbo.bindingUtils.registerAttributes({myFoo:myFooFunction, myBar:myBarFunction});
toString() → {string}
String representation of the current class
- Overrides:
- Source:
Returns:
- Type
- string
unbindElement(source, propertyName, el) → {conbo.BindingUtils}
Unbinds the specified property of a bindable class from the specified DOM element
Parameters:
Name | Type | Description |
---|---|---|
source |
conbo.EventDispatcher | Class instance which extends from conbo.EventDispatcher |
propertyName |
string | Property name to bind |
el |
HTMLElement | DOM element to unbind value from |
Returns:
A reference to this object
- Type
- conbo.BindingUtils
unbindView(view) → {conbo.BindingUtils}
Removes all data binding from the specified View instance
Parameters:
Name | Type | Description |
---|---|---|
view |
conbo.View |
Returns:
A reference to this object
- Type
- conbo.BindingUtils