From: Aleksander Ɓukasz Date: Tue, 2 Jul 2013 11:52:55 +0000 (+0200) Subject: Don't lose node's meta attr value when it has no sense X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/84ae5c7247597bf095ade00b94bf187773f732a8?ds=inline Don't lose node's meta attr value when it has no sense --- diff --git a/modules/documentCanvas/canvasNode.js b/modules/documentCanvas/canvasNode.js index 5f7efb9..72343a4 100644 --- a/modules/documentCanvas/canvasNode.js +++ b/modules/documentCanvas/canvasNode.js @@ -50,7 +50,8 @@ CanvasNode.prototype.setClass = function(klass) { if(klass != this.getClass()) { var c = this; this.getMetaAttrs().forEach(function(attr) { - c.dom.removeAttr('wlxml-meta-' + attr.name); + if(!classAttributes.hasMetaAttr(klass, attr.name)) + c.dom.removeAttr('wlxml-meta-' + attr.name); }); this.dom.attr('wlxml-class', klass); } diff --git a/modules/documentCanvas/tests/canvasNode.test.js b/modules/documentCanvas/tests/canvasNode.test.js index 444ee0f..2452fff 100644 --- a/modules/documentCanvas/tests/canvasNode.test.js +++ b/modules/documentCanvas/tests/canvasNode.test.js @@ -96,6 +96,13 @@ suite('meta attributes', function() { assert.equal(node.getMetaAttr('uri'), undefined); }); + + test('changing class to another with the same attribute keeps the value', function() { + var node = canvasNode.create({tag: 'span', klass: 'uri', meta: {uri: 'http://some.uri.com'}}); + assert.equal(node.getMetaAttr('uri'), 'http://some.uri.com'); + node.setClass('uri-subclass'); + assert.equal(node.getMetaAttr('uri'), 'http://some.uri.com'); + }); }); }); \ No newline at end of file