2 'libs/jquery-1.9.1.min',
4 'libs/text!./template.html'
5 ], function($, _, templateSrc) {
9 return function(sandbox) {
11 var template = _.template(templateSrc);
14 dom: $('<div>' + template({children: null, parent: null}) + '</div>'),
17 this.dom.on('click', 'a', function(e) {
18 var target = $(e.target);
19 sandbox.publish('elementClicked', target.data('element'));
22 this.dom.on('mouseenter', 'a', function(e) {
23 var target = $(e.target);
24 sandbox.publish('elementEntered', target.data('element'));
26 this.dom.on('mouseleave', 'a', function(e) {
27 var target = $(e.target);
28 sandbox.publish('elementLeft', target.data('element'));
31 setElement: function(element) {
32 console.log('familyTree sets node');
33 var textElement = element.getText ? element : null,
34 nodeElement = element.getText ? element.parent() : element, // TODO: better type detection
35 nodeElementParent = nodeElement.parent(),
38 this.currentNodeElement = nodeElement;
40 if(nodeElementParent) {
42 repr: nodeElementParent.getWlxmlTag() + (nodeElementParent.getWlxmlClass() ? ' / ' + nodeElementParent.getWlxmlClass() : '')
46 var nodeChildren = nodeElement.children(),
48 nodeChildren.forEach(function(child) {
50 var text = child.getText();
52 text = text.substr(0,13) + '...';
53 children.push({repr: '"' + text + '"', bold: child.sameNode(textElement)});
55 children.push({repr: child.getWlxmlTag() + (child.getWlxmlClass() ? ' / ' + child.getWlxmlClass() : '')});
59 this.dom.append($(template({parent: parent, children: children})));
62 this.dom.find('.rng-module-nodeFamilyTree-parent').data('element', nodeElementParent)
64 this.dom.find('li a').each(function(idx, a) {
65 $(a).data('element', nodeChildren[idx]);
68 highlightNode: function(canvasNode) {
69 this.dom.find('a[data-id="'+canvasNode.getId()+'"]').addClass('rng-common-hoveredNode');
71 dimNode: function(canvasNode) {
72 this.dom.find('a[data-id="'+canvasNode.getId()+'"]').removeClass('rng-common-hoveredNode');
80 sandbox.publish('ready');
82 setElement: function(element) {
83 if(!(element.sameNode(view.currentNodeElement)))
84 view.setElement(element);
89 highlightNode: function(canvasNode) {
90 view.highlightNode(canvasNode);
92 dimNode: function(canvasNode) {
93 view.dimNode(canvasNode);