1+ <!--
2+ @license
3+ Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+ Code distributed by Google as part of the polymer project is also
8+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+ -->
10+ < script >
11+ ( function ( ) {
12+ 'use strict' ;
13+
14+ var Settings = Polymer . Settings ;
15+ var TreeApi = Polymer . TreeApi ;
16+ var DomApi = Polymer . DomApi ;
17+
18+ // *************** Configure DomApi for Shadow DOM!! ***************
19+ if ( ! Settings . useShadow ) {
20+ return ;
21+ }
22+
23+ Polymer . Base . extend ( DomApi . prototype , {
24+
25+ querySelectorAll : function ( selector ) {
26+ return TreeApi . arrayCopy ( this . node . querySelectorAll ( selector ) ) ;
27+ } ,
28+
29+ getOwnerRoot : function ( ) {
30+ var n = this . node ;
31+ while ( n ) {
32+ if ( n . nodeType === Node . DOCUMENT_FRAGMENT_NODE && n . host ) {
33+ return n ;
34+ }
35+ n = n . parentNode ;
36+ }
37+ } ,
38+
39+ importNode : function ( externalNode , deep ) {
40+ var doc = this . node instanceof Document ? this . node :
41+ this . node . ownerDocument ;
42+ return doc . importNode ( externalNode , deep ) ;
43+ } ,
44+
45+ getDestinationInsertionPoints : function ( ) {
46+ var n$ = this . node . getDestinationInsertionPoints &&
47+ this . node . getDestinationInsertionPoints ( ) ;
48+ return n$ ? TreeApi . arrayCopy ( n$ ) : [ ] ;
49+ } ,
50+
51+ getDistributedNodes : function ( ) {
52+ var n$ = this . node . getDistributedNodes &&
53+ this . node . getDistributedNodes ( ) ;
54+ return n$ ? TreeApi . arrayCopy ( n$ ) : [ ] ;
55+ }
56+
57+ } ) ;
58+
59+ Object . defineProperties ( DomApi . prototype , {
60+
61+ childNodes : {
62+ get : function ( ) {
63+ return TreeApi . arrayCopyChildNodes ( this . node ) ;
64+ } ,
65+ configurable : true
66+ } ,
67+
68+ children : {
69+ get : function ( ) {
70+ return TreeApi . arrayCopyChildren ( this . node ) ;
71+ } ,
72+ configurable : true
73+ } ,
74+
75+ // textContent / innerHTML
76+ textContent : {
77+ get : function ( ) {
78+ return this . node . textContent ;
79+ } ,
80+ set : function ( value ) {
81+ return this . node . textContent = value ;
82+ } ,
83+ configurable : true
84+ } ,
85+
86+ innerHTML : {
87+ get : function ( ) {
88+ return this . node . innerHTML ;
89+ } ,
90+ set : function ( value ) {
91+ return this . node . innerHTML = value ;
92+ } ,
93+ configurable : true
94+ }
95+
96+ } ) ;
97+
98+ var forwardMethods = function ( m$ ) {
99+ for ( var i = 0 ; i < m$ . length ; i ++ ) {
100+ forwardMethod ( m$ [ i ] ) ;
101+ }
102+ } ;
103+
104+ var forwardMethod = function ( method ) {
105+ DomApi . prototype [ method ] = function ( ) {
106+ return this . node [ method ] . apply ( this . node , arguments ) ;
107+ }
108+ } ;
109+
110+ forwardMethods ( [ 'cloneNode' , 'appendChild' , 'insertBefore' ,
111+ 'removeChild' , 'replaceChild' , 'setAttribute' , 'removeAttribute' ,
112+ 'querySelector' ] ) ;
113+
114+ var forwardProperties = function ( f$ ) {
115+ for ( var i = 0 ; i < f$ . length ; i ++ ) {
116+ forwardProperty ( f$ [ i ] ) ;
117+ }
118+ } ;
119+
120+ var forwardProperty = function ( name ) {
121+ Object . defineProperty ( DomApi . prototype , name , {
122+ get : function ( ) {
123+ return this . node [ name ] ;
124+ } ,
125+ configurable : true
126+ } ) ;
127+ } ;
128+
129+ forwardProperties ( [ 'parentNode' , 'firstChild' , 'lastChild' ,
130+ 'nextSibling' , 'previousSibling' , 'firstElementChild' ,
131+ 'lastElementChild' , 'nextElementSibling' , 'previousElementSibling' ] ) ;
132+
133+ } ) ( ) ;
134+ </ script >
0 commit comments