From 84ae5c7247597bf095ade00b94bf187773f732a8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 2 Jul 2013 13:52:55 +0200 Subject: [PATCH 1/1] Don't lose node's meta attr value when it has no sense --- modules/documentCanvas/canvasNode.js | 3 ++- modules/documentCanvas/tests/canvasNode.test.js | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 -- 2.20.1