Permalink
Browse files

add script tag support for IE

  • Loading branch information...
1 parent 55b02fd commit a1e20cc60447b58627bb154d824fbcf9cec2c214 @lancejpollard lancejpollard committed Jul 15, 2014
Showing with 20 additions and 1 deletion.
  1. +15 −1 index.js
  2. +5 −0 test/domify.js
View
@@ -6,14 +6,28 @@
module.exports = parse;
/**
+ * Tests for browser support.
+ */
+
+var div = document.createElement('div');
+// Setup
+div.innerHTML = ' <link/><table></table><a href="/a">a</a><input type="checkbox"/>';
+// Make sure that link elements get serialized correctly by innerHTML
+// This requires a wrapper element in IE
+var innerHTMLBug = !div.getElementsByTagName('link').length;
+div = undefined;
+
+/**
* Wrap map from jquery.
*/
var map = {
legend: [1, '<fieldset>', '</fieldset>'],
tr: [2, '<table><tbody>', '</tbody></table>'],
col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
- _default: [0, '', '']
+ // for script/link/style tags to work in IE6-8, you have to wrap
+ // in a div with a non-whitespace character in front, ha!
+ _default: innerHTMLBug ? [1, 'X<div>', '</div>'] : [0, '', '']
};
map.td =
View
@@ -79,6 +79,11 @@ describe('domify(html)', function(){
assert('TR' == el.nodeName);
})
+ it('should support script tags', function(){
+ var el = domify('<script src="example.js"></script>');
+ assert('SCRIPT' == el.nodeName);
+ })
+
it('should support option tags', function(){
var el = domify('<option></option>');
assert('OPTION' == el.nodeName);

0 comments on commit a1e20cc

Please sign in to comment.