From: Aleksander Ɓukasz Date: Thu, 18 Jul 2013 13:05:48 +0000 (+0200) Subject: Keeping xmlns and other attributes intact X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/65bc68bd4bf15529bfc3a59b135de3ace448ba42?ds=sidebyside;hp=b60fde6f2bb4d1e10bd4187d54601315aa2e3435 Keeping xmlns and other attributes intact --- diff --git a/modules/documentCanvas/canvas/canvas.js b/modules/documentCanvas/canvas/canvas.js index 8905d3e..079c229 100644 --- a/modules/documentCanvas/canvas/canvas.js +++ b/modules/documentCanvas/canvas/canvas.js @@ -24,17 +24,20 @@ $.extend(Canvas.prototype, { if(currentTag.attr('wlxml-tag')) return; - var meta = {}; + var meta = {}, others = {}; for(var i = 0; i < this.attributes.length; i++) { var attr = this.attributes[i]; if(attr.name.substr(0, 5) === 'meta-') meta[attr.name.substr(5)] = attr.value; + else if(attr.name !== 'class') + others[attr.name] = attr.value; } var element = documentElement.DocumentNodeElement.create({ tag: currentTag.prop('tagName').toLowerCase(), klass: currentTag.attr('class'), - meta: meta + meta: meta, + others: others }); element.dom().append(currentTag.contents()); diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index a68e66b..76ece55 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -1102,6 +1102,15 @@ describe('Canvas', function() { expect(input.isEqualNode(output)).to.be.true; }); + it('keeps arbitrary node attributes intact', function() { + var xmlIn = '
', + $xmlOut = $(canvas.fromXML(xmlIn).toXML()); + + expect($xmlOut.attr('a')).to.equal('1'); + expect($xmlOut.attr('xmlns:dcterms')).to.equal('http://purl.org/dc/terms/'); + + }); + describe('formatting output xml', function() { /*it('keeps white spaces at the edges of input xml', function() { var xmlIn = '
', diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index f5a022b..9c2749e 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -122,6 +122,7 @@ $.extend(DocumentNodeElement, { dom.attr('wlxml-meta-'+key, params.meta[key]); }); } + dom.data('other-attrs', params.others); return dom; }, @@ -164,6 +165,9 @@ $.extend(DocumentNodeElement.prototype, { meta.forEach(function(attr) { node.attr('meta-' + attr.name, attr.value); }); + _.keys(this.data('other-attrs') || {}).forEach(function(key) { + node.attr(key, this.data('other-attrs')[key]); + }, this); if(this.data('orig-before') !== undefined) { toret.append(document.createTextNode(this.data('orig-before')));