From: Aleksander Ɓukasz Date: Mon, 1 Jul 2013 14:12:10 +0000 (+0200) Subject: metaWidget wip: reacting to class change X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/1fee1a1755e0b9ce88e1f9df5016f44b9982f368?ds=inline;hp=ff17619a4071364ea15383c696cb7e84b6c83089 metaWidget wip: reacting to class change --- diff --git a/modules/documentCanvas/canvasNode.js b/modules/documentCanvas/canvasNode.js index a57c10a..1ef5628 100644 --- a/modules/documentCanvas/canvasNode.js +++ b/modules/documentCanvas/canvasNode.js @@ -38,6 +38,16 @@ CanvasNode.prototype.getClass = function() { return this.dom.attr('wlxml-class'); }; +CanvasNode.prototype.setClass = function(klass) { + if(klass != this.getClass()) { + this.dom.attr('wlxml-class', klass); + var c = this; + this.getMetaAttrs().forEach(function(attr) { + c.dom.removeAttr('wlxml-meta-' + attr.name); + }); + } +} + CanvasNode.prototype.getId = function() { return this.dom.attr('id'); }; diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index 50a3777..2fa8722 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -29,8 +29,11 @@ return function(sandbox) { }, modifyCurrentNode: function(attr, value) { if(manager.currentNode) { - if(_.contains(['tag', 'class'], attr)) { + if(attr === 'tag') { manager.getNodeElement(manager.currentNode).attr('wlxml-'+attr, value); + } + else if(attr === 'class') { + manager.currentNode.setClass(value); } else { // changing node meta attr manager.currentNode.setMetaAttr(attr, value); diff --git a/modules/documentCanvas/tests/canvasNode.test.js b/modules/documentCanvas/tests/canvasNode.test.js index f944d90..0077d46 100644 --- a/modules/documentCanvas/tests/canvasNode.test.js +++ b/modules/documentCanvas/tests/canvasNode.test.js @@ -81,4 +81,16 @@ suite('meta attributes', function() { }); }); +suite('modifing node', function() { + test('changing class removes meta attributes', 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('author'); + + assert.equal(node.getMetaAttr('uri'), undefined); + }) +}) + }); \ No newline at end of file diff --git a/modules/rng/rng.js b/modules/rng/rng.js index 469a6fc..2078494 100644 --- a/modules/rng/rng.js +++ b/modules/rng/rng.js @@ -64,10 +64,12 @@ return function(sandbox) { }, selectNode: function(canvasNode, origin) { sandbox.getModule('documentCanvas').selectNode(canvasNode); + this.updateNodesModules(canvasNode); + }, + updateNodesModules: function(canvasNode) { sandbox.getModule('nodePane').setNode(canvasNode); sandbox.getModule('nodeFamilyTree').setNode(canvasNode); sandbox.getModule('nodeBreadCrumbs').setNode(canvasNode); - }, resetDocument: function(document, reason) { var modules = []; @@ -199,6 +201,10 @@ return function(sandbox) { dirty.documentCanvas = true; }, + currentNodeChanged: function(canvasNode) { + commands.updateNodesModules(canvasNode); + }, + nodeHovered: function(canvasNode) { commands.highlightDocumentNode(canvasNode); },