|
11 | 11 | <link rel="import" href="dom-innerHTML.html"> |
12 | 12 | <script> |
13 | 13 |
|
| 14 | + /** |
| 15 | + * DomApi is a dom manipulation library which is compatible with both |
| 16 | + * Shady DOM and Shadow DOM. The general usage is |
| 17 | + * `Polymer.dom(node).method(arguments)` where methods and arguments |
| 18 | + * match native DOM where possible. |
| 19 | + */ |
14 | 20 | Polymer.DomApi = (function() { |
15 | 21 | 'use strict'; |
16 | 22 |
|
|
462 | 468 | return list; |
463 | 469 | }, |
464 | 470 |
|
| 471 | + /* |
| 472 | + Returns a list of effective childNoes within this element. These can be |
| 473 | + dom child nodes or elements distributed to children that are insertion |
| 474 | + points. |
| 475 | + */ |
465 | 476 | getEffectiveChildNodes: function() { |
466 | 477 | var list = []; |
467 | 478 | var c$ = this.childNodes; |
|
526 | 537 | return n; |
527 | 538 | }, |
528 | 539 |
|
| 540 | + /** |
| 541 | + * Notifies callers about changes to the element's effective child nodes, |
| 542 | + * the same list as returned by `getEffectiveChildNodes`. |
| 543 | + * @param {function} callback The supplied callback is called with an |
| 544 | + * `info` argument which is an object that provides |
| 545 | + * the `target` on which the changes occurred, a list of any nodes |
| 546 | + * added in the `addedNodes` array, and nodes removed in the |
| 547 | + * `removedNodes` array. |
| 548 | + * @return {object} Returns a handle which is the argument to |
| 549 | + * `unobserveNodes`. |
| 550 | + */ |
529 | 551 | observeNodes: function(callback) { |
530 | | - if (!this.observer) { |
531 | | - this.observer = this.node.localName === CONTENT ? |
532 | | - new DomApi.MutationContent(this) : |
533 | | - new DomApi.Mutation(this); |
| 552 | + if (callback) { |
| 553 | + if (!this.observer) { |
| 554 | + this.observer = this.node.localName === CONTENT ? |
| 555 | + new DomApi.ObserveDistributedNodes(this) : |
| 556 | + new DomApi.ObserveNodes(this); |
| 557 | + } |
| 558 | + return this.observer.addListener(callback); |
534 | 559 | } |
535 | | - return this.observer.addListener(callback); |
536 | 560 | }, |
537 | 561 |
|
| 562 | + /** |
| 563 | + * Stops observing changes to the element's effective child nodes. |
| 564 | + * @param {object} handle The handle for the callback that should |
| 565 | + * no longer receive notifications. This handle is returned from |
| 566 | + * `observeNodes`. |
| 567 | + */ |
538 | 568 | unobserveNodes: function(handle) { |
539 | 569 | if (this.observer) { |
540 | 570 | this.observer.removeListener(handle); |
|
0 commit comments