5 'libs/text!./template.html'
6 ], function($, _, wlxmlUtils, templateSrc) {
10 return function(sandbox) {
12 var template = _.template(templateSrc),
15 var startListening = function(document) {
17 document.on('change', function(event) {
18 if(event.type === 'nodeTextChange' && event.meta.node.parent().sameNode(view.currentNodeElement)) {
25 dom: $('<div>' + template({contents: null, parent: null}) + '</div>'),
28 this.dom.on('click', 'a', function(e) {
29 var target = $(e.target);
30 sandbox.publish('elementClicked', target.data('element'));
33 this.dom.on('mouseenter', 'a', function(e) {
34 var target = $(e.target);
35 sandbox.publish('elementEntered', target.data('element'));
37 this.dom.on('mouseleave', 'a', function(e) {
38 var target = $(e.target);
39 sandbox.publish('elementLeft', target.data('element'));
42 setElement: function(element) {
43 element = element || this.currentNodeElement;
44 console.log('familyTree sets node');
45 var textElement = element.getText ? element : null,
46 nodeElement = element.getText ? element.parent() : element, // TODO: better type detection
47 nodeElementParent = nodeElement.parent(),
50 this.currentNodeElement = nodeElement;
52 if(nodeElementParent) {
54 repr: wlxmlUtils.wlxmlTagNames[nodeElementParent.getTagName()] + (nodeElementParent.getClass() ? ' / ' + wlxmlUtils.wlxmlClassNames[nodeElementParent.getClass()] : '')
58 var nodeContents = nodeElement.contents(),
60 nodeContents.forEach(function(child) {
62 var text = child.getText();
64 text = '<pusty tekst>';
66 if(text.length > 13) {
67 text = text.substr(0,13) + '...';
69 text = '"' + text + '"';
71 contents.push({repr: _.escape(text), bold: child.sameNode(textElement)});
73 contents.push({repr: wlxmlUtils.wlxmlTagNames[child.getTagName()] + (child.getClass() ? ' / ' + wlxmlUtils.wlxmlClassNames[child.getClass()] : '')});
77 this.dom.append($(template({parent: parent, contents: contents})));
80 this.dom.find('.rng-module-nodeFamilyTree-parent').data('element', nodeElementParent)
82 this.dom.find('li a').each(function(idx, a) {
83 $(a).data('element', nodeContents[idx]);
86 highlightNode: function(canvasNode) {
87 this.dom.find('a[data-id="'+canvasNode.getId()+'"]').addClass('rng-common-hoveredNode');
89 dimNode: function(canvasNode) {
90 this.dom.find('a[data-id="'+canvasNode.getId()+'"]').removeClass('rng-common-hoveredNode');
98 sandbox.publish('ready');
100 setElement: function(element) {
102 startListening(element.document);
104 if(!(element.sameNode(view.currentNodeElement)))
105 view.setElement(element);
107 getView: function() {
110 highlightNode: function(canvasNode) {
111 view.highlightNode(canvasNode);
113 dimNode: function(canvasNode) {
114 view.dimNode(canvasNode);