4a787f41e742d26fa9b7b9a724927538fd42c1b5
[fnpeditor.git] / modules / nodeBreadCrumbs / nodeBreadCrumbs.js
1 define([\r
2 'libs/jquery-1.9.1.min',\r
3 'libs/underscore-min',\r
4 'libs/text!./template.html'], function($, _, templateSrc) {\r
5 \r
6 'use strict';\r
7 \r
8 return function(sandbox) {\r
9     \r
10     var template = _.template(templateSrc);\r
11     \r
12     var view = {\r
13         dom: $('<div>' + template({node:null, parents: null}) + '</div>'),\r
14         setup: function() {\r
15             this.dom.on('mouseenter', 'a', function(e) {\r
16                 var target = $(e.target);\r
17                 sandbox.publish('nodeHighlighted', target.attr('data-id'));\r
18             });\r
19             this.dom.on('mouseleave', 'a', function(e) {\r
20                 var target = $(e.target);\r
21                 sandbox.publish('nodeDimmed', target.attr('data-id'));\r
22             });\r
23             this.dom.on('click', 'a', function(e) {\r
24                 e.preventDefault();\r
25                 var target = $(e.target);\r
26                 sandbox.publish('nodeSelected', target.attr('data-id'));\r
27             });\r
28         },\r
29         \r
30         setNode: function(node) {\r
31             this.dom.empty();\r
32             this.dom.html(template({node: node, parents: node.parents('[wlxml-tag]')}));\r
33         },\r
34         \r
35         highlightNode: function(id) {\r
36             this.dom.find('a[data-id="'+id+'"]').addClass('rng-common-hoveredNode');\r
37         },\r
38         dimNode: function(id) {\r
39             this.dom.find('a[data-id="' +id+'"]').removeClass('rng-common-hoveredNode');\r
40         }\r
41     }\r
42     \r
43     view.setup();\r
44     \r
45     return {\r
46         start: function() { sandbox.publish('ready'); },\r
47         getView: function() { return view.dom; },\r
48         setNode: function(node) { view.setNode(node); },\r
49         highlightNode: function(id) { view.highlightNode(id); },\r
50         dimNode: function(id) { view.dimNode(id); }\r
51     }\r
52 }\r
53 \r
54 });