X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/f8b3ddf413bc700b6c640a0da368b3a1a41c09cc..fc38c8a4517c3733dc5e47bc25f5c1ac85a0afc6:/modules/nodeFamilyTree/nodeFamilyTree.js
diff --git a/modules/nodeFamilyTree/nodeFamilyTree.js b/modules/nodeFamilyTree/nodeFamilyTree.js
index bd9c42c..7415b2d 100644
--- a/modules/nodeFamilyTree/nodeFamilyTree.js
+++ b/modules/nodeFamilyTree/nodeFamilyTree.js
@@ -13,34 +13,50 @@ return function(sandbox) {
var view = {
dom: $('
' + template({children: null, parent: null}) + '
'),
setup: function() {
+ var view = this;
this.dom.on('click', 'a', function(e) {
var target = $(e.target);
- sandbox.publish('nodeSelected', target.attr('data-id'));
+ sandbox.publish('nodeSelected', view.nodes[target.attr('data-id')]);
});
this.dom.on('mouseenter', 'a', function(e) {
var target = $(e.target);
- sandbox.publish('nodeEntered', target.attr('data-id'));
+ sandbox.publish('nodeEntered', view.nodes[target.attr('data-id')])
});
this.dom.on('mouseleave', 'a', function(e) {
var target = $(e.target);
- sandbox.publish('nodeLeft', target.attr('data-id'));
+ sandbox.publish('nodeLeft', view.nodes[target.attr('data-id')])
});
},
setNode: function(node) {
- var parentClass = node.parent().attr('wlxml-class');
- var parent = node.parent('[wlxml-tag]').length ? {
- repr: node.parent().attr('wlxml-tag') + (parentClass ? ' / ' + parentClass : ''),
- id: node.parent().attr('id')
- } : undefined;
+ console.log('familyTree sets node');
+ var nodes = this.nodes = {};
+ this.currentNode = node;
+ var parentNode = node.parent();
+ var parent = undefined;
+
+ if(parentNode) {
+ parent = {
+ repr: parentNode.tag + (parentNode.klass ? ' / ' + parentNode.klass : ''),
+ id: parentNode.id
+ };
+ this.nodes[parentNode.id] = parentNode;
+ }
+
var children = [];
- node.children('[wlxml-tag]').each(function() {
- var child = $(this);
- var childClass = child.attr('wlxml-class');
- children.push({repr: child.attr('wlxml-tag') + (childClass ? ' / ' + childClass : ''), id: child.attr('id')});
+ node.children().each(function() {
+ var child = this;
+ children.push({repr: child.tag + (child.klass ? ' / ' + child.klass : ''), id: child.id});
+ nodes[child.id] = child;
});
this.dom.empty();
this.dom.append($(template({parent: parent, children: children})));
+ },
+ highlightNode: function(wlxmlNode) {
+ this.dom.find('a[data-id="'+wlxmlNode.id+'"]').addClass('rng-common-hoveredNode');
+ },
+ dimNode: function(wlxmlNode) {
+ this.dom.find('a[data-id="'+wlxmlNode.id+'"]').removeClass('rng-common-hoveredNode');
}
}
@@ -50,17 +66,18 @@ return function(sandbox) {
start: function() {
sandbox.publish('ready');
},
- setNode: function(node) {
- view.setNode(node);
+ setNode: function(wlxmlNode) {
+ if(!wlxmlNode.is(view.currentNode))
+ view.setNode(wlxmlNode);
},
getView: function() {
return view.dom;
},
- highlightNode: function(id) {
- view.dom.find('a[data-id="'+id+'"]').addClass('rng-hover');
+ highlightNode: function(wlxmlNode) {
+ view.highlightNode(wlxmlNode);
},
- dimNode: function(id) {
- view.dom.find('a[data-id="'+id+'"]').removeClass('rng-hover');
+ dimNode: function(wlxmlNode) {
+ view.dimNode(wlxmlNode);
}
};
};