Refactoring - using DocumentNodeElement.createDOM when creating document from wlxml
[fnpeditor.git] / modules / documentToolbar / documentToolbar.js
index e364e99..e4d5039 100644 (file)
@@ -1,57 +1,56 @@
-define(['libs/jquery-1.9.1.min', 'libs/underscore-min', 'libs/text!./template.html'], function($, _, template) {\r
-\r
-'use strict';\r
-\r
-return function(sandbox) {\r
-    \r
-    var view = {\r
-        node: $(_.template(template)()),\r
-        setup: function() {\r
-            var view = this;\r
-            \r
-            this.node.find('button').click(function(e) {\r
-                e.stopPropagation();\r
-                var btn = $(e.currentTarget);\r
-                if(btn.attr('data-btn-type') === 'toggle') {\r
-                    btn.toggleClass('active')\r
-                    var event;\r
-                    var btnId = btn.attr('data-btn');\r
-                    if(btnId === 'grid')\r
-                        event = 'toggleGrid';\r
-                    if(btnId === 'tags')\r
-                        event = 'toggleTags';\r
-                    sandbox.publish(event, btn.hasClass('active'));\r
-                }\r
-                if(btn.attr('data-btn-type') === 'cmd') {\r
-                    var command = btn.attr('data-btn');\r
-                    var meta = btn.attr('data-meta');\r
-                    if(command === 'new-node') {\r
-                        var wlxmlTag = view.getOption('newTag-tag');\r
-                        var wlxmlClass = view.getOption('newTag-class');\r
-                        if(meta) {\r
-                            var split = meta.split('/');\r
-                            wlxmlTag = split[0];\r
-                            wlxmlClass = split[1];\r
-                        }\r
-                        sandbox.publish('newNodeRequested', wlxmlTag, wlxmlClass);\r
-                    } else {\r
-                        sandbox.publish('command', btn.attr('data-btn'), btn.attr('data-meta'));\r
-                    }\r
-                }\r
-            });\r
-        },\r
-        getOption: function(option) {\r
-            return this.node.find('.rng-module-documentToolbar-toolbarOption[data-option=' + option +']').val();\r
-        }\r
-    }\r
-    \r
-    view.setup();\r
-\r
-    return {\r
-        start: function() { sandbox.publish('ready'); },\r
-        getView: function() { return view.node; },\r
-        getOption: function(option) { return view.getOption(option); }\r
-    }\r
-}\r
-\r
+define(['libs/jquery-1.9.1.min', 'libs/underscore-min', 'libs/text!./template.html'], function($, _, template) {
+
+'use strict';
+
+return function(sandbox) {
+    
+    var view = {
+        node: $(_.template(template)()),
+        setup: function() {
+            var view = this;
+            
+            this.node.find('button').click(function(e) {
+                e.stopPropagation();
+                var btn = $(e.currentTarget),
+                    btnName = btn.attr('data-name'),
+                    meta = btn.attr('data-meta'),
+                    params = {},
+                    command = btnName;
+
+                if(btn.attr('data-btn-type') === 'toggle') {
+                    command = 'toggle-' + command;
+                    btn.toggleClass('active');
+                    params.toggle = btn.hasClass('active');
+                }
+
+                if(btnName === 'new-node') {
+                    command = 'newNodeRequested';
+                    params.wlxmlTag = view.getOption('newTag-tag');
+                    params.wlxmlClass = view.getOption('newTag-class');
+                    if(meta) {
+                        var split = meta.split('/');
+                        params.wlxmlTag = split[0];
+                        params.wlxmlClass = split[1];
+                    }
+                } else {
+                    params.meta = meta;
+                }
+
+                sandbox.publish('command', command, params);
+            });
+        },
+        getOption: function(option) {
+            return this.node.find('.rng-module-documentToolbar-toolbarOption[data-option=' + option +']').val();
+        }
+    };
+    
+    view.setup();
+
+    return {
+        start: function() { sandbox.publish('ready'); },
+        getView: function() { return view.node; },
+        getOption: function(option) { return view.getOption(option); }
+    };
+};
+
 });
\ No newline at end of file