This repository was archived by the owner on Sep 20, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +43
-6
lines changed Expand file tree Collapse file tree 4 files changed +43
-6
lines changed Original file line number Diff line number Diff line change 338
338
setWrapper ( impl , this ) ;
339
339
}
340
340
341
+ var originalCreateDocument = document . implementation . createDocument ;
342
+ DOMImplementation . prototype . createDocument = function ( ) {
343
+ arguments [ 2 ] = unwrap ( arguments [ 2 ] ) ;
344
+ return wrap ( originalCreateDocument . apply ( unsafeUnwrap ( this ) , arguments ) ) ;
345
+ } ;
346
+
341
347
function wrapImplMethod ( constructor , name ) {
342
348
var original = document . implementation [ name ] ;
343
349
constructor . prototype [ name ] = function ( ) {
353
359
}
354
360
355
361
wrapImplMethod ( DOMImplementation , 'createDocumentType' ) ;
356
- wrapImplMethod ( DOMImplementation , 'createDocument' ) ;
357
362
wrapImplMethod ( DOMImplementation , 'createHTMLDocument' ) ;
358
363
forwardImplMethod ( DOMImplementation , 'hasFeature' ) ;
359
364
362
367
forwardMethodsToWrapper ( [
363
368
window . DOMImplementation ,
364
369
] , [
365
- 'createDocumentType' ,
366
370
'createDocument' ,
371
+ 'createDocumentType' ,
367
372
'createHTMLDocument' ,
368
373
'hasFeature' ,
369
374
] ) ;
Original file line number Diff line number Diff line change 93
93
'noscript'
94
94
] ) ;
95
95
96
+ var XHTML_NS = 'http://www.w3.org/1999/xhtml' ;
97
+
98
+ function needsSelfClosingSlash ( node ) {
99
+ // if the namespace is not XHTML_NS, this is probably an XML or SVG Document
100
+ // and will need a closing slash on void elements
101
+ if ( node . namespaceURI !== XHTML_NS )
102
+ return true ;
103
+
104
+ var doctype = node . ownerDocument . doctype ;
105
+ // doctype is null for quirksmode documents
106
+ // publicId and systemId are required for XHTML, and are null for HTML5
107
+ return doctype && doctype . publicId && doctype . systemId ;
108
+ }
109
+
96
110
function getOuterHTML ( node , parentNode ) {
97
111
switch ( node . nodeType ) {
98
112
case Node . ELEMENT_NODE :
102
116
for ( var i = 0 , attr ; attr = attrs [ i ] ; i ++ ) {
103
117
s += ' ' + attr . name + '="' + escapeAttr ( attr . value ) + '"' ;
104
118
}
105
- s += '>' ;
106
- if ( voidElements [ tagName ] )
107
- return s ;
108
119
109
- return s + getInnerHTML ( node ) + '</' + tagName + '>' ;
120
+ if ( voidElements [ tagName ] ) {
121
+ if ( needsSelfClosingSlash ( node ) )
122
+ s += '/' ;
123
+ return s + '>' ;
124
+ }
125
+
126
+ return s + '>' + getInnerHTML ( node ) + '</' + tagName + '>' ;
110
127
111
128
case Node . TEXT_NODE :
112
129
var data = node . data ;
Original file line number Diff line number Diff line change @@ -33,6 +33,13 @@ htmlSuite('Document', function() {
33
33
assert . equal ( doc2 . lastElementChild . tagName , 'HTML' ) ;
34
34
} ) ;
35
35
36
+ test ( 'Create XHTML Document' , function ( ) {
37
+ var docType = wrap ( document ) . implementation . createDocumentType ( 'html' , '-//W3C//DTD XHTML 1.0 Transitional//EN' ,
38
+ 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' ) ;
39
+ var doc = wrap ( document ) . implementation . createDocument ( 'http://www.w3.org/1999/xhtml' , 'html' , docType ) ;
40
+ assert ( doc ) ;
41
+ } ) ;
42
+
36
43
test ( 'document.documentElement' , function ( ) {
37
44
var doc = wrap ( document ) ;
38
45
assert . equal ( doc . documentElement . ownerDocument , doc ) ;
Original file line number Diff line number Diff line change @@ -114,4 +114,12 @@ suite('HTMLElement', function() {
114
114
div . hidden = false ;
115
115
assert . isFalse ( div . hasAttribute ( 'hidden' ) ) ;
116
116
} ) ;
117
+
118
+ test ( 'img outerHTML in XHTML documents' , function ( ) {
119
+ var docType = document . implementation . createDocumentType ( 'html' , '-//W3C//DTD XHTML 1.0 Transitional//EN' ,
120
+ 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' ) ;
121
+ var doc = document . implementation . createDocument ( 'http://www.w3.org/1999/xhtml' , 'html' , docType ) ;
122
+ var img = doc . createElement ( 'img' ) ;
123
+ assert . equal ( img . outerHTML , '<img/>' ) ;
124
+ } ) ;
117
125
} ) ;
You can’t perform that action at this time.
0 commit comments