diff --git a/src/spine.databind.coffee b/src/spine.databind.coffee index 3460a87..5038fcb 100644 --- a/src/spine.databind.coffee +++ b/src/spine.databind.coffee @@ -231,7 +231,14 @@ class Attribute extends Template keys: [ "attr" ] bind: (operators,model,controller,el,options) -> - @init(operators,model,controller,el,options,"update") + if options.watch + for operator in operators + json = JSON.parse(operator.property) + for own property of json + @init([operator],model,controller,el,options,"update["+json[property]+"]") + else + @init(operators,model,controller,el,options,"update") + @update(operators,model,controller,el,options) update: (operators,model,controller,el,options) -> @@ -240,7 +247,9 @@ class Attribute extends Template json = JSON.parse(operator.property) for own property of json value = binder.get(model,json[property]) - el.attr(property,value) + if el.attr(property) isnt value + el.attr(property,value) + el.trigger("change") @ class Checked extends Template diff --git a/src/spine.databind.js b/src/spine.databind.js index 094878b..8a083aa 100644 --- a/src/spine.databind.js +++ b/src/spine.databind.js @@ -420,7 +420,19 @@ Attribute.prototype.keys = ["attr"]; Attribute.prototype.bind = function(operators, model, controller, el, options) { - this.init(operators, model, controller, el, options, "update"); + var json, operator, property, _i, _len; + if (options.watch) { + for (_i = 0, _len = operators.length; _i < _len; _i++) { + operator = operators[_i]; + json = JSON.parse(operator.property); + for (property in json) { + if (!__hasProp.call(json, property)) continue; + this.init([operator], model, controller, el, options, "update[" + json[property] + "]"); + } + } + } else { + this.init(operators, model, controller, el, options, "update"); + } return this.update(operators, model, controller, el, options); }; @@ -434,7 +446,10 @@ for (property in json) { if (!__hasProp.call(json, property)) continue; value = binder.get(model, json[property]); - el.attr(property, value); + if (el.attr(property) !== value) { + el.attr(property, value); + el.trigger("change"); + } } return this; };