Index: sky/framework/sky-element/TemplateBinding.sky |
diff --git a/sky/framework/sky-element/TemplateBinding.sky b/sky/framework/sky-element/TemplateBinding.sky |
index 65d9bb5d3667a33e59b649ff83040507f8130be1..1000094526302b2a835bbffbed705aa243337670 100644 |
--- a/sky/framework/sky-element/TemplateBinding.sky |
+++ b/sky/framework/sky-element/TemplateBinding.sky |
@@ -14,7 +14,7 @@ Node.prototype.bind = function(name, observable, oneTime) { |
return; |
} |
- observable.open(function(value) { |
+ this[name] = observable.open(function(value) { |
self[name] = value; |
}); |
@@ -544,6 +544,16 @@ function parseWithDefault(el, name, prepareBindingFn) { |
return parseMustaches(v == '' ? '{{}}' : v, name, el, prepareBindingFn); |
} |
+function addEventHandler(element, name, method) { |
+ element.addEventListener(name, function(event) { |
+ var scope = element.ownerScope; |
+ var host = scope.host; |
+ var handler = host && host[method]; |
+ if (handler instanceof Function) |
+ return handler.call(host, event); |
+ }); |
+} |
+ |
function parseAttributeBindings(element, prepareBindingFn) { |
var bindings = []; |
var ifFound = false; |
@@ -560,6 +570,13 @@ function parseAttributeBindings(element, prepareBindingFn) { |
continue; |
} |
+ if (name.startsWith('on-')) { |
+ if (!bindings.eventHandlers) |
+ bindings.eventHandlers = new Map(); |
+ bindings.eventHandlers.set(name.substring(3), value); |
+ continue; |
+ } |
+ |
var tokens = parseMustaches(value, name, element, |
prepareBindingFn); |
if (!tokens) |
@@ -618,6 +635,12 @@ function cloneAndBindInstance(node, parent, stagingDocument, bindings, model, |
clone.setDelegate_(delegate); |
} |
+ if (bindings.eventHandlers) { |
+ bindings.eventHandlers.forEach(function(handler, eventName) { |
+ addEventHandler(clone, eventName, handler); |
+ }); |
+ } |
+ |
processBindings(clone, bindings, model, instanceBindings); |
return clone; |
} |