| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of html; | 5 part of html; |
| 6 | 6 |
| 7 // This code is a port of Model-Driven-Views: | 7 // This code is a port of Model-Driven-Views: |
| 8 // https://github.com/polymer-project/mdv | 8 // https://github.com/polymer-project/mdv |
| 9 // The code mostly comes from src/template_element.js | 9 // The code mostly comes from src/template_element.js |
| 10 | 10 |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } | 371 } |
| 372 } | 372 } |
| 373 | 373 |
| 374 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { | 374 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { |
| 375 clone.append(_createDeepCloneAndDecorateTemplates(c, syntax)); | 375 clone.append(_createDeepCloneAndDecorateTemplates(c, syntax)); |
| 376 } | 376 } |
| 377 return clone; | 377 return clone; |
| 378 } | 378 } |
| 379 | 379 |
| 380 // http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#
dfn-template-contents-owner | 380 // http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#
dfn-template-contents-owner |
| 381 static Document _getTemplateContentsOwner(Document doc) { | 381 static Document _getTemplateContentsOwner(HtmlDocument doc) { |
| 382 if (doc.window == null) { | 382 if (doc.window == null) { |
| 383 return doc; | 383 return doc; |
| 384 } | 384 } |
| 385 var d = doc._templateContentsOwner; | 385 var d = doc._templateContentsOwner; |
| 386 if (d == null) { | 386 if (d == null) { |
| 387 // TODO(arv): This should either be a Document or HTMLDocument depending | 387 // TODO(arv): This should either be a Document or HTMLDocument depending |
| 388 // on doc. | 388 // on doc. |
| 389 d = doc.implementation.createHtmlDocument(''); | 389 d = doc.implementation.createHtmlDocument(''); |
| 390 while (d.$dom_lastChild != null) { | 390 while (d.$dom_lastChild != null) { |
| 391 d.$dom_lastChild.remove(); | 391 d.$dom_lastChild.remove(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 void bootstrap(template) { | 449 void bootstrap(template) { |
| 450 if (!TemplateElement.decorate(template)) { | 450 if (!TemplateElement.decorate(template)) { |
| 451 _bootstrapTemplatesRecursivelyFrom(template.content); | 451 _bootstrapTemplatesRecursivelyFrom(template.content); |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 | 454 |
| 455 // Need to do this first as the contents may get lifted if |node| is | 455 // Need to do this first as the contents may get lifted if |node| is |
| 456 // template. | 456 // template. |
| 457 // TODO(jmesserly): node is DocumentFragment or Element | 457 // TODO(jmesserly): node is DocumentFragment or Element |
| 458 var descendents = (node as dynamic).queryAll(_allTemplatesSelectors); | 458 var descendents = (node as dynamic).queryAll(_allTemplatesSelectors); |
| 459 if (node is Element && node.isTemplate) bootstrap(node); | 459 if (node is Element && (node as Element).isTemplate) bootstrap(node); |
| 460 | 460 |
| 461 descendents.forEach(bootstrap); | 461 descendents.forEach(bootstrap); |
| 462 } | 462 } |
| 463 | 463 |
| 464 static final String _allTemplatesSelectors = 'template, option[template], ' + | 464 static final String _allTemplatesSelectors = 'template, option[template], ' + |
| 465 Element._TABLE_TAGS.keys.map((k) => "$k[template]").join(", "); | 465 Element._TABLE_TAGS.keys.map((k) => "$k[template]").join(", "); |
| 466 | 466 |
| 467 static void _addBindings(Node node, model, [CustomBindingSyntax syntax]) { | 467 static void _addBindings(Node node, model, [CustomBindingSyntax syntax]) { |
| 468 if (node is Element) { | 468 if (node is Element) { |
| 469 _addAttributeBindings(node, model, syntax); | 469 _addAttributeBindings(node, model, syntax); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 | 603 |
| 604 static void _removeAllBindingsRecursively(Node node) { | 604 static void _removeAllBindingsRecursively(Node node) { |
| 605 _nodeOrCustom(node).unbindAll(); | 605 _nodeOrCustom(node).unbindAll(); |
| 606 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { | 606 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { |
| 607 _removeAllBindingsRecursively(c); | 607 _removeAllBindingsRecursively(c); |
| 608 } | 608 } |
| 609 } | 609 } |
| 610 | 610 |
| 611 static void _removeChild(Node parent, Node child) { | 611 static void _removeChild(Node parent, Node child) { |
| 612 child._templateInstance = null; | 612 child._templateInstance = null; |
| 613 if (child is Element && child.isTemplate) { | 613 if (child is Element && (child as Element).isTemplate) { |
| 614 // Make sure we stop observing when we remove an element. | 614 // Make sure we stop observing when we remove an element. |
| 615 var templateIterator = child._templateIterator; | 615 var templateIterator = child._templateIterator; |
| 616 if (templateIterator != null) { | 616 if (templateIterator != null) { |
| 617 templateIterator.abandon(); | 617 templateIterator.abandon(); |
| 618 child._templateIterator = null; | 618 child._templateIterator = null; |
| 619 } | 619 } |
| 620 } | 620 } |
| 621 child.remove(); | 621 child.remove(); |
| 622 _removeAllBindingsRecursively(child); | 622 _removeAllBindingsRecursively(child); |
| 623 } | 623 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 _sub.cancel(); | 779 _sub.cancel(); |
| 780 _sub = null; | 780 _sub = null; |
| 781 } | 781 } |
| 782 | 782 |
| 783 void abandon() { | 783 void abandon() { |
| 784 unobserve(); | 784 unobserve(); |
| 785 _valueBinding.cancel(); | 785 _valueBinding.cancel(); |
| 786 inputs.dispose(); | 786 inputs.dispose(); |
| 787 } | 787 } |
| 788 } | 788 } |
| OLD | NEW |