Autosync
work with data, not with DOM
Download
autosync.jsStandard version: IE 9+, Firefox 4.0+, Opera 12.1+, Chrome 5.0+
autosync-compat.jsExtended version: IE 6+, Firefox 1.0+, Opera 8.0+
API

Attributes

asmodel
Path toi the model relative to its context
string
asscope
The context (parent object of the model)
string
asmodelkey
Model key
string
astemplate
The template
string with references to model object's fields in {$value['field']} format
aslist
Flag telling Autosync that the template should be applied to each element of the collection (the model must be a collection, i.e. сcontain integer fields and an integer length field). Also sets the first and the last element to output as the range
None or string in "number1:number2" format
asjson
Flag telling Autosync that the pull method must parse the element value from the JSON string (the pull method only works for <input> and <textarea> elements)
Can take special values "pretty", "pretty:<n>" or "pretty:<str>" for pretty JSON output, where n is the width of each level indentation in spaces, and str is an arbitrary prefix for each indentation level.
None or string
asplaceholder
Placeholder HTML or CSS selector of the element with the placeholder inside it
HTML string or string in the $([ selector ]) format, where [ selector ] is a valid CSS selector
asif
Element output condition in JS code (special variables $value, $index, $now are supported)
asclasses
CSS class lists to add to the element based on the truthiness of condition in [ cond ] ? [ list1 ] | [ list2 ] or [ cond ] ? [ list1 ] format
asstyles
CSS rules lists to add to the element based on the truthiness of condition in [ cond ] ? [ list1 ] | [ list2 ] or [ cond ] ? [ list1 ] format
asattrs
Attribute lists to add to the element based on the truthiness of condition in [ cond ] ? [ list1 ] | [ list2 ] or [ cond ] ? [ list1 ] format
as-on*
Event handler. Inside the handler the special variables event, value, scope, index are available (if value is not an element inside a collection, then index is -1)

Methods

as.add(model [, scope] [, key] [, atomic] [, value])

Register an object as a model

model
model name
string
scope
context
string or object reference
key
unique key
string
atomic
atomic update mode (changes in child objects cause the change of the whole object)
true / false
value
initial value
any
as.remove(model [, scope] [, unset])

Remove object from the models list

model
model name
string
scope
context
string or object reference
unset
if true the object will be removed completely, otherwise just the watching of its state will be stopped
true / false
as.pull(model [, scope] [, update] [, url] [, key])

Update model based on the data in input elements

model
model name
string
scope
context
string or object reference
update
if true the update of all elements connected to the model will be triggered
true / false
url
URL on the server for sending the updated value
URL
key
unique key
string
as.update(model [, scope] [, key])

Force update of all elements connected to the model

model
model name
string
scope
context
string or object reference
key
unique key
string
as.setBefore(model, func, scope)

Register a new before DOM update hook. To register a global hook model must be an empty string

model
model name
string
scope
context
string or object reference
func
user function
function
as.setAfter(model, func, scope)

Register a new after DOM update hook. To register a global hook model must be an empty string

model
model name
string
scope
context
string or object reference
func
user function
function
as.addEvent(el, type, func, scope, value_key, keep)

Event handler registration

el
element
DOM element
type
event type
string
func
user function
function
scope
context
string or object reference
value_key
key of the model property inside the context
string
keep
if true, any other handlers of the same type will not be removed
true / false
as.removeEvent(el, type, func)

Event handler removal

el
element
DOM element
type
event type
string
func
user function
function
as.embedObject(context, str)

Embed registration

context
context of the source and destination models
string or object reference
str
string in the following format:
path.to.source:id -> path.to.dest:ref_id:field
or
path.to.source:id -> path.to.dest:ref_id:[field1 > new_field1 , field2 > new_field2]
string
as.removeEmbed(context, str, keep)

Embed removal

context
context of the source and destination models
string or object reference
str
string in the following format:
path.to.source:id -> path.to.dest:ref_id:field
or
path.to.source:id -> path.to.dest:ref_id:[field1 > new_field1 , field2 > new_field2]
string
keep
if true, the watching will be stopped, but the embeds will not be deleted
true / false