documentCanvas - removing yellow "glow" around contenteditable element in Chrome
[fnpeditor.git] / modules / nodeFamilyTree / nodeFamilyTree.js
1 define([\r
2 'libs/jquery-1.9.1.min',\r
3 'libs/underscore-min',\r
4 'libs/text!./template.html'\r
5 ], function($, _, templateSrc) {\r
6 \r
7 'use strict';\r
8 \r
9 return function(sandbox) {\r
10     \r
11     var template = _.template(templateSrc);\r
12     \r
13     var view = {\r
14         dom: $('<div>' + template({children: null, parent: null}) + '</div>'),\r
15         setup: function() {\r
16             this.dom.on('click', 'a', function(e) {\r
17                 var target = $(e.target);\r
18                 sandbox.publish('nodeSelected', target.attr('data-id'));\r
19             });\r
20             \r
21             this.dom.on('mouseenter', 'a', function(e) {\r
22                 var target = $(e.target);\r
23                 sandbox.publish('nodeEntered', target.attr('data-id'));\r
24             });\r
25             this.dom.on('mouseleave', 'a', function(e) {\r
26                 var target = $(e.target);\r
27                 sandbox.publish('nodeLeft', target.attr('data-id'));\r
28             });\r
29         },\r
30         setNode: function(node) {\r
31             var parentClass = node.parent().attr('wlxml-class');\r
32             var parent = node.parent('[wlxml-tag]').length ? {\r
33                 repr: node.parent().attr('wlxml-tag') + (parentClass ? ' / ' + parentClass : ''),\r
34                 id: node.parent().attr('id')\r
35             } : undefined;\r
36             var children = [];\r
37             node.children('[wlxml-tag]').each(function() {\r
38                 var child = $(this);\r
39                 var childClass = child.attr('wlxml-class');\r
40                 children.push({repr: child.attr('wlxml-tag') + (childClass ? ' / ' + childClass : ''), id: child.attr('id')});\r
41             });\r
42             this.dom.empty();\r
43             this.dom.append($(template({parent: parent, children: children})));\r
44         }\r
45     }\r
46     \r
47     view.setup();\r
48     \r
49     return {\r
50         start: function() {\r
51             sandbox.publish('ready');\r
52         },\r
53         setNode: function(node) {\r
54             view.setNode(node);\r
55         },\r
56         getView: function() {\r
57             return view.dom;\r
58         },\r
59         highlightNode: function(id) {\r
60             view.dom.find('a[data-id="'+id+'"]').addClass('rng-common-hoveredNode');\r
61         },\r
62         dimNode: function(id) {\r
63             view.dom.find('a[data-id="'+id+'"]').removeClass('rng-common-hoveredNode');\r
64         }\r
65     };\r
66 };\r
67 \r
68 });