fnp
/
fnpeditor.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
b60fde6
)
Keeping xmlns and other attributes intact
author
Aleksander Łukasz
<aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 18 Jul 2013 13:05:48 +0000
(15:05 +0200)
committer
Aleksander Łukasz
<aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 18 Jul 2013 13:05:48 +0000
(15:05 +0200)
modules/documentCanvas/canvas/canvas.js
patch
|
blob
|
history
modules/documentCanvas/canvas/canvas.test3.js
patch
|
blob
|
history
modules/documentCanvas/canvas/documentElement.js
patch
|
blob
|
history
diff --git
a/modules/documentCanvas/canvas/canvas.js
b/modules/documentCanvas/canvas/canvas.js
index
8905d3e
..
079c229
100644
(file)
--- 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;
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;
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'),
}
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());
});
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
(file)
--- 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;
});
expect(input.isEqualNode(output)).to.be.true;
});
+ it('keeps arbitrary node attributes intact', function() {
+ var xmlIn = '<section a="1" xmlns:dcterms="http://purl.org/dc/terms/"></section>',
+ $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 = ' <section></section> ',
describe('formatting output xml', function() {
/*it('keeps white spaces at the edges of input xml', function() {
var xmlIn = ' <section></section> ',
diff --git
a/modules/documentCanvas/canvas/documentElement.js
b/modules/documentCanvas/canvas/documentElement.js
index
f5a022b
..
9c2749e
100644
(file)
--- 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.attr('wlxml-meta-'+key, params.meta[key]);
});
}
+ dom.data('other-attrs', params.others);
return dom;
},
return dom;
},
@@
-164,6
+165,9
@@
$.extend(DocumentNodeElement.prototype, {
meta.forEach(function(attr) {
node.attr('meta-' + attr.name, attr.value);
});
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')));
if(this.data('orig-before') !== undefined) {
toret.append(document.createTextNode(this.data('orig-before')));