Fixing Canvas.getDocumentElement
[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                     if(btnId === 'list')
24                         event = 'toggleList'
25                     sandbox.publish(event, btn.hasClass('active'));
26                 }
27                 if(btn.attr('data-btn-type') === 'cmd') {
28                     var command = btn.attr('data-btn');
29                     var meta = btn.attr('data-meta');
30                     if(command === 'new-node') {
31                         var wlxmlTag = view.getOption('newTag-tag');
32                         var wlxmlClass = view.getOption('newTag-class');
33                         if(meta) {
34                             var split = meta.split('/');
35                             wlxmlTag = split[0];
36                             wlxmlClass = split[1];
37                         }
38                         sandbox.publish('newNodeRequested', wlxmlTag, wlxmlClass);
39                     } else {
40                         sandbox.publish('command', btn.attr('data-btn'), btn.attr('data-meta'));
41                     }
42                 }
43             });
44         },
45         getOption: function(option) {
46             return this.node.find('.rng-module-documentToolbar-toolbarOption[data-option=' + option +']').val();
47         }
48     };
49     
50     view.setup();
51
52     return {
53         start: function() { sandbox.publish('ready'); },
54         getView: function() { return view.node; },
55         getOption: function(option) { return view.getOption(option); }
56     };
57 };
58
59 });