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 = '<pusty tekst>';
54 if(text.length > 13) {
55 text = text.substr(0,13) + '...';
57 text = '"' + text + '"';
59 children.push({repr: _.escape(text), bold: child.sameNode(textElement)});
61 children.push({repr: child.getWlxmlTag() + (child.getWlxmlClass() ? ' / ' + child.getWlxmlClass() : '')});
65 this.dom.append($(template({parent: parent, children: children})));
68 this.dom.find('.rng-module-nodeFamilyTree-parent').data('element', nodeElementParent)
70 this.dom.find('li a').each(function(idx, a) {
71 $(a).data('element', nodeChildren[idx]);
74 highlightNode: function(canvasNode) {
75 this.dom.find('a[data-id="'+canvasNode.getId()+'"]').addClass('rng-common-hoveredNode');
77 dimNode: function(canvasNode) {
78 this.dom.find('a[data-id="'+canvasNode.getId()+'"]').removeClass('rng-common-hoveredNode');
86 sandbox.publish('ready');
88 setElement: function(element) {
89 if(!(element.sameNode(view.currentNodeElement)))
90 view.setElement(element);
95 highlightNode: function(canvasNode) {
96 view.highlightNode(canvasNode);
98 dimNode: function(canvasNode) {
99 view.dimNode(canvasNode);