From 5921556a715bc28d59b6cfdf265056caed0b4c11 Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Mon, 7 Oct 2019 11:50:08 +0200 Subject: [PATCH 1/3] Allow creating namespaced domelements --- src/view/domconverter.js | 7 ++++++- tests/view/domconverter/dom-to-view.js | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/view/domconverter.js b/src/view/domconverter.js index 6693a6feb..cc1eb92ba 100644 --- a/src/view/domconverter.js +++ b/src/view/domconverter.js @@ -224,7 +224,12 @@ export default class DomConverter { return domElement; } else { // Create DOM element. - domElement = domDocument.createElement( viewNode.name ); + const namespace = viewNode.getAttribute( 'xmlns' ); + if ( namespace !== undefined ) { + domElement = domDocument.createElementNS( namespace, viewNode.name ); + } else { + domElement = domDocument.createElement( viewNode.name ); + } if ( options.bind ) { this.bindElements( domElement, viewNode ); diff --git a/tests/view/domconverter/dom-to-view.js b/tests/view/domconverter/dom-to-view.js index 5880cea45..48f1665ca 100644 --- a/tests/view/domconverter/dom-to-view.js +++ b/tests/view/domconverter/dom-to-view.js @@ -175,6 +175,15 @@ describe( 'DomConverter', () => { expect( converter.domToView( comment ) ).to.be.null; } ); + it( 'should create namespaced elements', () => { + const namespace = 'http://www.w3.org/2000/svg'; + const svg = createElement( document, 'svg', { xmlns: namespace } ); + + const viewSvg = converter.domToView( svg ); + + expect( viewSvg.getAttribute( 'xmlns' ) ).to.equal( namespace ); + } ); + describe( 'it should clear whitespaces', () => { it( 'at the beginning of block element', () => { const domDiv = createElement( document, 'div', {}, [ From ec7a9bb51cbe467087f3b4aacc86544c6933ef43 Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Tue, 8 Oct 2019 09:25:59 +0200 Subject: [PATCH 2/3] Simplify check for xmlns attribute --- src/view/domconverter.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/view/domconverter.js b/src/view/domconverter.js index cc1eb92ba..f0723a718 100644 --- a/src/view/domconverter.js +++ b/src/view/domconverter.js @@ -224,9 +224,8 @@ export default class DomConverter { return domElement; } else { // Create DOM element. - const namespace = viewNode.getAttribute( 'xmlns' ); - if ( namespace !== undefined ) { - domElement = domDocument.createElementNS( namespace, viewNode.name ); + if ( viewNode.hasAttribute( 'xmlns' ) ) { + domElement = domDocument.createElementNS( viewNode.getAttribute( 'xmlns' ), viewNode.name ); } else { domElement = domDocument.createElement( viewNode.name ); } From 1f2d981121cfd3a9386516b6186d3634d6a9a67c Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Tue, 8 Oct 2019 09:43:32 +0200 Subject: [PATCH 3/3] Make sure test for namespaced elements fail without change --- tests/view/domconverter/dom-to-view.js | 9 --------- tests/view/domconverter/view-to-dom.js | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/view/domconverter/dom-to-view.js b/tests/view/domconverter/dom-to-view.js index 48f1665ca..5880cea45 100644 --- a/tests/view/domconverter/dom-to-view.js +++ b/tests/view/domconverter/dom-to-view.js @@ -175,15 +175,6 @@ describe( 'DomConverter', () => { expect( converter.domToView( comment ) ).to.be.null; } ); - it( 'should create namespaced elements', () => { - const namespace = 'http://www.w3.org/2000/svg'; - const svg = createElement( document, 'svg', { xmlns: namespace } ); - - const viewSvg = converter.domToView( svg ); - - expect( viewSvg.getAttribute( 'xmlns' ) ).to.equal( namespace ); - } ); - describe( 'it should clear whitespaces', () => { it( 'at the beginning of block element', () => { const domDiv = createElement( document, 'div', {}, [ diff --git a/tests/view/domconverter/view-to-dom.js b/tests/view/domconverter/view-to-dom.js index 5948600fa..57c03eb70 100644 --- a/tests/view/domconverter/view-to-dom.js +++ b/tests/view/domconverter/view-to-dom.js @@ -174,6 +174,15 @@ describe( 'DomConverter', () => { expect( domTextNode.data ).to.equal( 'foo' ); } ); + it( 'should create namespaced elements', () => { + const namespace = 'http://www.w3.org/2000/svg'; + const viewSvg = new ViewElement( 'svg', { xmlns: namespace } ); + + const domSvg = converter.viewToDom( viewSvg, document ); + + expect( domSvg.createSVGRect ).to.be.a( 'function' ); + } ); + describe( 'it should convert spaces to  ', () => { it( 'at the beginning of each container element', () => { const viewDiv = new ViewContainerElement( 'div', null, [