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)) {
32 view.setElement(view.currentNodeElement);
38 dom: $('<div>' + template({contents: null, parent: null}) + '</div>'),
40 this.dom.on('click', 'a', function(e) {
41 var target = $(e.target);
42 sandbox.publish('nodeClicked', target.data('element'));
45 this.dom.on('mouseenter', 'a', function(e) {
46 var target = $(e.target);
47 sandbox.publish('nodeEntered', target.data('element'));
49 this.dom.on('mouseleave', 'a', function(e) {
50 var target = $(e.target);
51 sandbox.publish('nodeLeft', target.data('element'));
54 setElement: function(element) {
56 parent, nodeElementParent;
59 element = element || this.currentNodeElement;
60 var textElement = element.getText ? element : null,
61 nodeElement = element.getText ? element.parent() : element, // TODO: better type detection
64 this.currentNodeElement = nodeElement;
66 nodeElementParent = nodeElement.parent();
68 if(nodeElementParent) {
69 items.push(nodeElementParent);
72 repr: wlxmlUtils.getTagLabel(nodeElementParent.getTagName()) + (nodeElementParent.getClass() ? ' / ' + wlxmlUtils.getClassLabel(nodeElementParent.getClass()) : '')
77 var nodeContents = nodeElement.contents();
78 nodeContents.forEach(function(child) {
80 var text = child.getText();
82 text = '<pusty tekst>';
85 if(text.length > 13) {
86 text = text.substr(0,13) + '...';
88 text = '"' + text + '"';
92 repr: _.escape(text), bold: child.sameNode(textElement)
97 repr: wlxmlUtils.getTagLabel(child.getTagName()) + (child.getClass() ? ' / ' + wlxmlUtils.getClassLabel(child.getClass()) : '')
104 this.dom.append($(template({parent: parent, contents: contents})));
107 this.dom.find('.rng-module-nodeFamilyTree-parent').data('element', nodeElementParent);
109 this.dom.find('li a').each(function(idx, a) {
110 $(a).data('element', nodeContents[idx]);
113 highlightNode: function(canvasNode) {
114 var id = getItemId(canvasNode);
115 this.dom.find('a[rng-module-nodeFamilyTree-item-id="'+id+'"]').addClass('rng-common-hoveredNode');
117 dimNode: function(canvasNode) {
118 var id = getItemId(canvasNode);
119 this.dom.find('a[rng-module-nodeFamilyTree-item-id="'+id+'"]').removeClass('rng-common-hoveredNode');
127 sandbox.publish('ready');
129 setElement: function(element) {
130 if(!listens && element) {
131 startListening(element.document);
133 if(!element || !(element.sameNode(view.currentNodeElement))) {
134 view.setElement(element);
137 getView: function() {
140 highlightElement: function(canvasNode) {
141 view.highlightNode(canvasNode);
143 dimElement: function(canvasNode) {
144 view.dimNode(canvasNode);