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