@@ -147,137 +147,51 @@ Object.defineProperty(HTMLElement.prototype, 'dataset', {
147147
148148} ;
149149
150- //DOM4 w3c.github.io/dom
151- 'append' in document . createDocumentFragment ( ) || new function ( ) {
152-
153- var ELEMENT_NODE = 1 ,
154- proto = HTMLElement . prototype ,
155- api = {
156-
157- before : function ( /* ...nodes */ ) {
158- //todo IE8 removedNode.parentNode ≠ null
159- var parentNode = this . parentNode ;
160- if ( parentNode ) {
161- parentNode . insertBefore ( mutationMacro ( arguments ) , this ) ;
162- }
163- } ,
164-
165- after : function ( /* ...nodes */ ) {
166- var parentNode = this . parentNode ,
167- nextSibling ,
168- nodes ;
169- if ( parentNode ) {
170- nodes = mutationMacro ( arguments ) ;
171- nextSibling = this . nextSibling ;
172- if ( nextSibling ) {
173- parentNode . insertBefore ( nodes , nextSibling ) ;
174- } else {
175- parentNode . appendChild ( nodes ) ;
176- }
177- }
178- } ,
179-
180- replace : function ( /* ...nodes */ ) {
181- var parentNode = this . parentNode ;
182- if ( parentNode ) {
183- parentNode . replaceChild ( mutationMacro ( arguments ) , this ) ;
184- }
185- } ,
186-
187- remove : function ( ) {
188- var parentNode = this . parentNode ;
189- if ( parentNode ) {
190- parentNode . removeChild ( this ) ;
191- }
192- } ,
193-
194- append : function ( /* ...nodes */ ) {
195- this . appendChild ( mutationMacro ( arguments ) ) ;
196- } ,
197-
198- prepend : function ( ) {
199- this . insertBefore ( mutationMacro ( arguments ) , this . firstChild ) ;
200- } ,
201-
202- querySelector : proto . querySelector ,
203-
204- querySelectorAll : proto . querySelectorAll ,
205-
206- matches : [
207- proto . matchesSelector ,
208- proto . oMatchesSelector ,
209- proto . msMatchesSelector ,
210- proto . mozMatchesSelector ,
211- proto . webkitMatchesSelector ,
212- function ( selector ) {
213- var contains ,
214- root ;
215- if ( this === document ) {
216- //if docFragment.constructor ≡ document.constructor
217- return false ;
218- }
150+ document . documentElement . matches || new function ( ) {
151+
152+ var proto = HTMLElement . prototype ;
153+
154+ proto . matches = [
155+ proto . matchesSelector ,
156+ proto . oMatchesSelector ,
157+ proto . msMatchesSelector ,
158+ proto . mozMatchesSelector ,
159+ proto . webkitMatchesSelector
160+ ] . find ( Boolean ) ;
161+
162+ if ( ! proto . matches ) {
163+ proto . matches = new function ( ) {
164+ var ELEMENT_NODE = 1 ;
165+ function isContains ( root , element , selector ) {
166+ return Array . contains ( root . querySelectorAll ( selector ) , element ) ;
167+ }
168+ return function ( selector ) {
169+ var contains ,
219170 root = this . parentNode ;
220- if ( root ) {
221- if ( ELEMENT_NODE == root . nodeType ) {
222- root = root . ownerDocument ;
223- }
224- return isContains ( root , this , selector ) ;
171+ if ( root ) {
172+ if ( ELEMENT_NODE == root . nodeType ) {
173+ root = root . ownerDocument ;
225174 }
226- root = document . createDocumentFragment ( ) ;
227- root . appendChild ( this ) ;
228- contains = isContains ( root , this , selector ) ;
229- root . removeChild ( this ) ;
175+ return isContains ( root , this , selector ) ;
230176 }
231- ] . find ( Boolean )
232-
177+ root = document . createDocumentFragment ( ) ;
178+ root . appendChild ( this ) ;
179+ contains = isContains ( root , this , selector ) ;
180+ root . removeChild ( this ) ;
181+ } ;
233182 } ;
234-
235- function isContains ( root , element , selector ) {
236- return - 1 != Array . indexOf ( root . querySelectorAll ( selector ) , element ) ;
237183 }
238184
239- function mutationMacro ( nodes ) {
240- var node ,
241- fragment ,
242- length = nodes . length ,
243- i ;
244- if ( 1 == length ) {
245- node = nodes [ 0 ] ;
246- if ( 'string' == typeof node ) {
247- return document . createTextNode ( node ) ;
248- }
249- return node ;
250- }
251- fragment = document . createDocumentFragment ( ) ;
252- nodes = Array . from ( nodes ) ;
253- i = 0 ;
254- while ( i < length ) {
255- node = nodes [ i ] ;
256- if ( 'string' == typeof node ) {
257- node = document . createTextNode ( node ) ;
258- }
259- fragment . appendChild ( node ) ;
260- i ++ ;
261- }
262- return fragment ;
263- }
264-
265- function implement ( key ) {
266- if ( ! ( key in proto ) ) {
267- proto [ key ] = api [ key ] ;
268- }
269- }
270-
271- Object . keys ( api ) . forEach ( implement ) ;
185+ } ;
272186
273- proto = document . constructor . prototype ;
274- [ 'querySelector' , 'querySelectorAll' ] . forEach ( implement ) ;
187+ new function ( ) {
275188
276- proto = document . createDocumentFragment ( ) . constructor . prototype ;
277- [
278- 'append' , 'prepend' ,
279- 'querySelector' , 'querySelectorAll' ,
280- 'matches'
281- ] . forEach ( implement ) ;
189+ var docFragment = document . createDocumentFragment ( ) ,
190+ target = docFragment . constructor . prototype ,
191+ source = HTMLElement . prototype ;
192+ if ( ! docFragment . querySelector ) {
193+ target . querySelector = source . querySelector ;
194+ target . querySelectorAll = source . querySelectorAll ;
195+ }
282196
283197} ;
0 commit comments