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>'),
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) {
55 element = element || this.currentNodeElement;
56 var textElement = element.getText ? element : null,
57 nodeElement = element.getText ? element.parent() : element, // TODO: better type detection
58 nodeElementParent = nodeElement.parent(),
61 this.currentNodeElement = nodeElement;
64 if(nodeElementParent) {
65 items.push(nodeElementParent);
68 repr: wlxmlUtils.wlxmlTagNames[nodeElementParent.getTagName()] + (nodeElementParent.getClass() ? ' / ' + wlxmlUtils.wlxmlClassNames[nodeElementParent.getClass()] : '')
73 var nodeContents = nodeElement.contents(),
75 nodeContents.forEach(function(child) {
77 var text = child.getText();
79 text = '<pusty tekst>';
82 if(text.length > 13) {
83 text = text.substr(0,13) + '...';
85 text = '"' + text + '"';
89 repr: _.escape(text), bold: child.sameNode(textElement)
94 repr: wlxmlUtils.wlxmlTagNames[child.getTagName()] + (child.getClass() ? ' / ' + wlxmlUtils.wlxmlClassNames[child.getClass()] : '')
100 this.dom.append($(template({parent: parent, contents: contents})));
103 this.dom.find('.rng-module-nodeFamilyTree-parent').data('element', nodeElementParent);
105 this.dom.find('li a').each(function(idx, a) {
106 $(a).data('element', nodeContents[idx]);
109 highlightNode: function(canvasNode) {
110 var id = getItemId(canvasNode);
111 this.dom.find('a[rng-module-nodeFamilyTree-item-id="'+id+'"]').addClass('rng-common-hoveredNode');
113 dimNode: function(canvasNode) {
114 var id = getItemId(canvasNode);
115 this.dom.find('a[rng-module-nodeFamilyTree-item-id="'+id+'"]').removeClass('rng-common-hoveredNode');
123 sandbox.publish('ready');
125 setElement: function(element) {
127 startListening(element.document);
129 if(!(element.sameNode(view.currentNodeElement))) {
130 view.setElement(element);
133 getView: function() {
136 highlightElement: function(canvasNode) {
137 view.highlightNode(canvasNode);
139 dimElement: function(canvasNode) {
140 view.dimNode(canvasNode);