5 'libs/text!./template.html'
6 ], function($, _, wlxmlUtils, templateSrc) {
10 return function(sandbox) {
12 var template = _.template(templateSrc),
16 var getItemId = function(item) {
18 var found = _.find(items, function(i) {
20 return item.sameNode(i);
28 var startListening = function(document) {
30 document.on('change', function(event) {
31 if(event.type === 'nodeTextChange' && event.meta.node.parent().sameNode(view.currentNodeElement)) {
38 dom: $('<div>' + template({contents: null, parent: null}) + '</div>'),
41 this.dom.on('click', 'a', function(e) {
42 var target = $(e.target);
43 sandbox.publish('nodeClicked', target.data('element'));
46 this.dom.on('mouseenter', 'a', function(e) {
47 var target = $(e.target);
48 sandbox.publish('nodeEntered', target.data('element'));
50 this.dom.on('mouseleave', 'a', function(e) {
51 var target = $(e.target);
52 sandbox.publish('nodeLeft', target.data('element'));
55 setElement: function(element) {
56 element = element || this.currentNodeElement;
57 console.log('familyTree sets node');
58 var textElement = element.getText ? element : null,
59 nodeElement = element.getText ? element.parent() : element, // TODO: better type detection
60 nodeElementParent = nodeElement.parent(),
63 this.currentNodeElement = nodeElement;
66 if(nodeElementParent) {
67 items.push(nodeElementParent);
70 repr: wlxmlUtils.wlxmlTagNames[nodeElementParent.getTagName()] + (nodeElementParent.getClass() ? ' / ' + wlxmlUtils.wlxmlClassNames[nodeElementParent.getClass()] : '')
75 var nodeContents = nodeElement.contents(),
77 nodeContents.forEach(function(child) {
79 var text = child.getText();
81 text = '<pusty tekst>';
83 if(text.length > 13) {
84 text = text.substr(0,13) + '...';
86 text = '"' + text + '"';
90 repr: _.escape(text), bold: child.sameNode(textElement)
95 repr: wlxmlUtils.wlxmlTagNames[child.getTagName()] + (child.getClass() ? ' / ' + wlxmlUtils.wlxmlClassNames[child.getClass()] : '')
101 this.dom.append($(template({parent: parent, contents: contents})));
104 this.dom.find('.rng-module-nodeFamilyTree-parent').data('element', nodeElementParent)
106 this.dom.find('li a').each(function(idx, a) {
107 $(a).data('element', nodeContents[idx]);
110 highlightNode: function(canvasNode) {
111 var id = getItemId(canvasNode);
112 this.dom.find('a[rng-module-nodeFamilyTree-item-id="'+id+'"]').addClass('rng-common-hoveredNode');
114 dimNode: function(canvasNode) {
115 var id = getItemId(canvasNode);
116 this.dom.find('a[rng-module-nodeFamilyTree-item-id="'+id+'"]').removeClass('rng-common-hoveredNode');
124 sandbox.publish('ready');
126 setElement: function(element) {
128 startListening(element.document);
130 if(!(element.sameNode(view.currentNodeElement)))
131 view.setElement(element);
133 getView: function() {
136 highlightElement: function(canvasNode) {
137 view.highlightNode(canvasNode);
139 dimElement: function(canvasNode) {
140 view.dimNode(canvasNode);