|
159 | 159 | // and forces distribution.
|
160 | 160 | var insertionPointTag = ownerRoot && ownerRoot.getInsertionPointTag() || '';
|
161 | 161 | var fragContent = (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) &&
|
162 |
| - !node.__noContent && |
| 162 | + !node.__noContent && |
163 | 163 | insertionPointTag && node.querySelector(insertionPointTag);
|
164 | 164 | var wrappedContent = fragContent &&
|
165 | 165 | (Tree.Logical.getParentNode(fragContent).nodeType !==
|
|
278 | 278 | firstComposedNode: function(insertionPoint) {
|
279 | 279 | var n$ = insertionPoint.getDistributedNodes();
|
280 | 280 | var root = this.ownerRootForNode(insertionPoint);
|
281 |
| - for (var i=0, l=n$.length, n, p$; (i<l) && (n=n$[i]); i++) { |
| 281 | + for (var i=0, l=n$.length, n; (i<l) && (n=n$[i]); i++) { |
282 | 282 | // means that we're composed to this spot.
|
283 | 283 | if (root.isFinalDestination(insertionPoint, n)) {
|
284 | 284 | return n;
|
|
317 | 317 |
|
318 | 318 | // NOTE: `query` is used primarily for ShadyDOM's querySelector impl,
|
319 | 319 | // but it's also generally useful to recurse through the element tree
|
320 |
| - // and is used by Polymer's styling system. |
| 320 | + // and is used by Polymer's styling system. |
321 | 321 | query: function(node, matcher, halter) {
|
322 | 322 | var list = [];
|
323 |
| - this._queryElements(Tree.Logical.getChildNodes(node), matcher, |
| 323 | + this._queryElements(Tree.Logical.getChildNodes(node), matcher, |
324 | 324 | halter, list);
|
325 | 325 | return list;
|
326 | 326 | },
|
327 | 327 |
|
328 | 328 | _queryElements: function(elements, matcher, halter, list) {
|
329 | 329 | for (var i=0, l=elements.length, c; (i<l) && (c=elements[i]); i++) {
|
330 |
| - if (c.nodeType === Node.ELEMENT_NODE && |
| 330 | + if (c.nodeType === Node.ELEMENT_NODE && |
331 | 331 | this._queryElement(c, matcher, halter, list)) {
|
332 | 332 | return true;
|
333 | 333 | }
|
|
342 | 342 | if (halter && halter(result)) {
|
343 | 343 | return result;
|
344 | 344 | }
|
345 |
| - this._queryElements(Tree.Logical.getChildNodes(node), matcher, |
| 345 | + this._queryElements(Tree.Logical.getChildNodes(node), matcher, |
346 | 346 | halter, list);
|
347 | 347 | },
|
348 | 348 |
|
|
394 | 394 | };
|
395 | 395 |
|
396 | 396 | Object.defineProperties(NodeMixin, {
|
397 |
| - |
| 397 | + |
398 | 398 | isConnected: {
|
399 | 399 | get() {
|
400 | 400 | return document.contains(this);
|
|
485 | 485 | }
|
486 | 486 | }
|
487 | 487 | // if adding to a shadyRoot, add to host instead
|
488 |
| - var container = ShadyDom.isShadyRoot(this) ? |
| 488 | + var container = ShadyDom.isShadyRoot(this) ? |
489 | 489 | this.host : this;
|
490 | 490 | if (ref_node) {
|
491 | 491 | Tree.Composed.insertBefore(container, node, ref_node);
|
|
510 | 510 | if (!mixinImpl.removeNode(node)) {
|
511 | 511 | // if removing from a shadyRoot, remove form host instead
|
512 | 512 | var container = ShadyDom.isShadyRoot(this) ?
|
513 |
| - this.host : |
| 513 | + this.host : |
514 | 514 | this;
|
515 | 515 | // not guaranteed to physically be in container; e.g.
|
516 | 516 | // undistributed nodes.
|
|
573 | 573 | }
|
574 | 574 | }
|
575 | 575 | return n;
|
576 |
| - }, |
577 |
| - |
578 |
| - // TODO(sorvell): removeEventListener + weakmap... |
579 |
| - addEventListener: function(type, fn, capture) { |
580 |
| - if (!this.__eventListenerCount) { |
581 |
| - this.__eventListenerCount = 0; |
582 |
| - } |
583 |
| - this.__eventListenerCount++; |
584 |
| - var wrappedFn = function(e) { |
585 |
| - if (!e.__target) { |
586 |
| - e.__target = e.target; |
587 |
| - var proto = ShadyDom.patchImpl.prototypeForObject(e); |
588 |
| - if (proto) { |
589 |
| - e.__proto__ = proto; |
590 |
| - } |
591 |
| - } |
592 |
| - return fn(e); |
593 |
| - } |
594 |
| - fn.__eventWrapper = wrappedFn; |
595 |
| - return origAddEventListener.call(this, type, wrappedFn, capture); |
596 |
| - }, |
597 |
| - |
598 |
| - removeEventListener: function(type, fn, capture) { |
599 |
| - var wrapper = fn.__eventWrapper; |
600 |
| - origRemoveEventListener.call(this, type, wrapper || fn, capture); |
601 |
| - if (wrapper) { |
602 |
| - fn.__eventWrapper = null; |
603 |
| - this.__eventListenerCount--; |
604 |
| - } |
605 | 576 | }
|
606 |
| - |
607 | 577 | };
|
608 | 578 |
|
609 | 579 | Object.defineProperties(FragmentMixin, {
|
|
731 | 701 | nativeRemoveAttribute.call(this, name);
|
732 | 702 | if (!mixinImpl.maybeDistributeParent(this)) {
|
733 | 703 | mixinImpl.maybeDistributeAttributeChange(this, name);
|
734 |
| - }; |
| 704 | + } |
735 | 705 | }
|
736 | 706 |
|
737 | 707 | };
|
738 | 708 |
|
739 | 709 | Object.defineProperties(ElementMixin, {
|
740 | 710 |
|
741 | 711 | shadowRoot: {
|
742 |
| - get() { |
| 712 | + get() { |
743 | 713 | return this.shadyRoot;
|
744 | 714 | }
|
745 | 715 | },
|
|
772 | 742 | });
|
773 | 743 |
|
774 | 744 | var EventMixin = {
|
775 |
| - |
| 745 | + |
776 | 746 | __patched: 'Event',
|
777 | 747 |
|
778 | 748 | composedPath() {
|
|
802 | 772 | },
|
803 | 773 |
|
804 | 774 | get target() {
|
805 |
| - // If ANCESTOR's root is not a shadow root or ANCESTOR's root is BASE's |
| 775 | + // If ANCESTOR's root is not a shadow root or ANCESTOR's root is BASE's |
806 | 776 | // shadow-including inclusive ancestor, return ANCESTOR.
|
807 | 777 | var base = this.currentTarget;
|
808 | 778 | var baseRoot = base && ShadyDom.ownerRootForNode(base);
|
|
818 | 788 |
|
819 | 789 | };
|
820 | 790 |
|
| 791 | + ShadyDom.addEventListener = function(type, fn, capture) { |
| 792 | + if (!this.__eventListenerCount) { |
| 793 | + this.__eventListenerCount = 0; |
| 794 | + } |
| 795 | + this.__eventListenerCount++; |
| 796 | + var wrappedFn = function(e) { |
| 797 | + if (!e.__target) { |
| 798 | + e.__target = e.target; |
| 799 | + var proto = ShadyDom.patchImpl.prototypeForObject(e); |
| 800 | + if (proto) { |
| 801 | + e.__proto__ = proto; |
| 802 | + } |
| 803 | + } |
| 804 | + return fn(e); |
| 805 | + } |
| 806 | + fn.__eventWrapper = wrappedFn; |
| 807 | + return origAddEventListener.call(this, type, wrappedFn, capture); |
| 808 | + }; |
| 809 | + |
| 810 | + ShadyDom.removeEventListener = function(type, fn, capture) { |
| 811 | + var wrapper = fn.__eventWrapper; |
| 812 | + origRemoveEventListener.call(this, type, wrapper || fn, capture); |
| 813 | + if (wrapper) { |
| 814 | + fn.__eventWrapper = null; |
| 815 | + this.__eventListenerCount--; |
| 816 | + } |
| 817 | + }; |
| 818 | + |
821 | 819 | ShadyDom.Mixins = {
|
822 |
| - |
| 820 | + |
823 | 821 | Node: ShadyDom.extendAll({__patched: 'Node'}, NodeMixin),
|
824 | 822 |
|
825 |
| - Fragment: ShadyDom.extendAll({__patched: 'Fragment'}, |
| 823 | + Fragment: ShadyDom.extendAll({__patched: 'Fragment'}, |
826 | 824 | NodeMixin, FragmentMixin, ActiveElementMixin),
|
827 | 825 |
|
828 |
| - Element: ShadyDom.extendAll({__patched: 'Element'}, |
| 826 | + Element: ShadyDom.extendAll({__patched: 'Element'}, |
829 | 827 | NodeMixin, FragmentMixin, ElementMixin, ActiveElementMixin),
|
830 | 828 |
|
831 | 829 | // Note: activeElement cannot be patched on document!
|
832 |
| - Document: ShadyDom.extendAll({__patched: 'Document'}, |
| 830 | + Document: ShadyDom.extendAll({__patched: 'Document'}, |
833 | 831 | NodeMixin, FragmentMixin, ElementMixin, UnderActiveElementMixin),
|
834 | 832 |
|
835 | 833 | Event: EventMixin
|
|
0 commit comments