2 'libs/jquery-1.9.1.min',
5 'libs/text!./template.html'
6 ], function($, _, wlxmlUtils, templateSrc) {
10 return function(sandbox) {
12 var template = _.template(templateSrc);
15 dom: $('<div>' + template({children: null, parent: null}) + '</div>'),
18 this.dom.on('click', 'a', function(e) {
19 var target = $(e.target);
20 sandbox.publish('elementClicked', target.data('element'));
23 this.dom.on('mouseenter', 'a', function(e) {
24 var target = $(e.target);
25 sandbox.publish('elementEntered', target.data('element'));
27 this.dom.on('mouseleave', 'a', function(e) {
28 var target = $(e.target);
29 sandbox.publish('elementLeft', target.data('element'));
32 setElement: function(element) {
33 console.log('familyTree sets node');
34 var textElement = element.getText ? element : null,
35 nodeElement = element.getText ? element.parent() : element, // TODO: better type detection
36 nodeElementParent = nodeElement.parent(),
39 this.currentNodeElement = nodeElement;
41 if(nodeElementParent) {
43 repr: wlxmlUtils.wlxmlTagNames[nodeElementParent.getWlxmlTag()] + (nodeElementParent.getWlxmlClass() ? ' / ' + wlxmlUtils.wlxmlClassNames[nodeElementParent.getWlxmlClass()] : '')
47 var nodeChildren = nodeElement.children(),
49 nodeChildren.forEach(function(child) {
51 var text = child.getText();
53 text = '<pusty tekst>';
55 if(text.length > 13) {
56 text = text.substr(0,13) + '...';
58 text = '"' + text + '"';
60 children.push({repr: _.escape(text), bold: child.sameNode(textElement)});
62 children.push({repr: wlxmlUtils.wlxmlTagNames[child.getWlxmlTag()] + (child.getWlxmlClass() ? ' / ' + wlxmlUtils.wlxmlClassNames[child.getWlxmlClass()] : '')});
66 this.dom.append($(template({parent: parent, children: children})));
69 this.dom.find('.rng-module-nodeFamilyTree-parent').data('element', nodeElementParent)
71 this.dom.find('li a').each(function(idx, a) {
72 $(a).data('element', nodeChildren[idx]);
75 highlightNode: function(canvasNode) {
76 this.dom.find('a[data-id="'+canvasNode.getId()+'"]').addClass('rng-common-hoveredNode');
78 dimNode: function(canvasNode) {
79 this.dom.find('a[data-id="'+canvasNode.getId()+'"]').removeClass('rng-common-hoveredNode');
87 sandbox.publish('ready');
89 setElement: function(element) {
90 if(!(element.sameNode(view.currentNodeElement)))
91 view.setElement(element);
96 highlightNode: function(canvasNode) {
97 view.highlightNode(canvasNode);
99 dimNode: function(canvasNode) {
100 view.dimNode(canvasNode);