Fixing breaking node into two
[fnpeditor.git] / modules / documentToolbar / documentToolbar.js
1 define(['libs/jquery-1.9.1.min', 'libs/underscore-min', 'libs/text!./template.html'], function($, _, template) {\r
2 \r
3 'use strict';\r
4 \r
5 return function(sandbox) {\r
6     \r
7     var view = {\r
8         node: $(_.template(template)()),\r
9         setup: function() {\r
10             var view = this;\r
11             \r
12             this.node.find('button').click(function(e) {\r
13                 e.stopPropagation();\r
14                 var btn = $(e.currentTarget);\r
15                 if(btn.attr('data-btn-type') === 'toggle') {\r
16                     btn.toggleClass('active')\r
17                     var event;\r
18                     var btnId = btn.attr('data-btn');\r
19                     if(btnId === 'grid')\r
20                         event = 'toggleGrid';\r
21                     if(btnId === 'tags')\r
22                         event = 'toggleTags';\r
23                     sandbox.publish(event, btn.hasClass('active'));\r
24                 }\r
25                 if(btn.attr('data-btn-type') === 'cmd') {\r
26                     var command = btn.attr('data-btn');\r
27                     var meta = btn.attr('data-meta');\r
28                     if(command === 'new-node') {\r
29                         var wlxmlTag = view.getOption('newTag-tag');\r
30                         var wlxmlClass = view.getOption('newTag-class');\r
31                         if(meta) {\r
32                             var split = meta.split('/');\r
33                             wlxmlTag = split[0];\r
34                             wlxmlClass = split[1];\r
35                         }\r
36                         sandbox.publish('newNodeRequested', wlxmlTag, wlxmlClass);\r
37                     } else {\r
38                         sandbox.publish('command', btn.attr('data-btn'), btn.attr('data-meta'));\r
39                     }\r
40                 }\r
41             });\r
42         },\r
43         getOption: function(option) {\r
44             return this.node.find('.rng-module-documentToolbar-toolbarOption[data-option=' + option +']').val();\r
45         }\r
46     }\r
47     \r
48     view.setup();\r
49 \r
50     return {\r
51         start: function() { sandbox.publish('ready'); },\r
52         getView: function() { return view.node; },\r
53         getOption: function(option) { return view.getOption(option); }\r
54     }\r
55 }\r
56 \r
57 });