From 880c47bce9a351c9ac528e08533f5f1f23eda67f Mon Sep 17 00:00:00 2001 From: Steve Orvell Date: Fri, 11 Apr 2014 14:19:49 -0700 Subject: [PATCH] by default, install template syntax once. --- build.json | 1 + polymer.html | 1 + src/declaration/mdv.js | 54 ++++++++++++++++++++++++++++++++++++ src/declaration/prototype.js | 2 ++ src/declaration/styles.js | 4 --- src/instance/mdv.js | 28 +------------------ src/polymer-body.html | 1 + 7 files changed, 60 insertions(+), 31 deletions(-) create mode 100644 src/declaration/mdv.js diff --git a/build.json b/build.json index 4146d6a..2988578 100644 --- a/build.json +++ b/build.json @@ -20,6 +20,7 @@ "src/declaration/events.js", "src/declaration/properties.js", "src/declaration/attributes.js", + "src/declaration/mdv.js", "src/declaration/prototype.js", "src/declaration/queue.js", "src/declaration/import.js", diff --git a/polymer.html b/polymer.html index eb5a612..6c0370a 100644 --- a/polymer.html +++ b/polymer.html @@ -24,6 +24,7 @@ + diff --git a/src/declaration/mdv.js b/src/declaration/mdv.js new file mode 100644 index 0000000..6ae2313 --- /dev/null +++ b/src/declaration/mdv.js @@ -0,0 +1,54 @@ +/* + * Copyright 2013 The Polymer Authors. All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ +(function(scope) { + + // imports + + var syntax = new PolymerExpressions(); + syntax.resolveEventHandler = function(model, path, node) { + var ctlr = findEventController(node); + if (ctlr) { + var fn = path.getValueFrom(ctlr); + if (fn) { + return fn.bind(ctlr); + } + } + }; + + // An event controller is the host element for the shadowRoot in which + // the node exists, or the first ancestor with a 'lightDomController' + // property. + function findEventController(node) { + while (node.parentNode) { + if (node.lightDomController) { + return node; + } + node = node.parentNode; + } + return node.host; + } + + // declaration api supporting mdv + var mdv = { + syntax: syntax, + fetchTemplate: function() { + return this.querySelector('template'); + }, + templateContent: function() { + var template = this.fetchTemplate(); + return template && templateContent(template); + }, + installBindingDelegate: function(template) { + if (template) { + template.bindingDelegate = this.syntax; + } + } + }; + + // exports + scope.api.declaration.mdv = mdv; + +})(Polymer); diff --git a/src/declaration/prototype.js b/src/declaration/prototype.js index 01a5a69..c089099 100644 --- a/src/declaration/prototype.js +++ b/src/declaration/prototype.js @@ -79,6 +79,8 @@ // build side-chained lists to optimize iterations this.optimizePropertyMaps(this.prototype); this.createPropertyAccessors(this.prototype); + // install mdv delegate on template + this.installBindingDelegate(this.fetchTemplate()); // install external stylesheets as if they are inline this.installSheets(); // adjust any paths in dom from imports diff --git a/src/declaration/styles.js b/src/declaration/styles.js index 8fa8486..b134663 100644 --- a/src/declaration/styles.js +++ b/src/declaration/styles.js @@ -125,10 +125,6 @@ } return matcher ? nodes.filter(matcher) : nodes; }, - templateContent: function() { - var template = this.querySelector('template'); - return template && templateContent(template); - }, /** * Promotes external stylesheets and