Visual editor - making sure only wlxml-tags are put into edit pane navigation
[fnpeditor.git] / modules / visualEditor.js
index 4c8af20..82ee13e 100644 (file)
@@ -15,8 +15,8 @@ rng.modules.visualEditor = function(sandbox) {
                 isDirty = true;\r
             });\r
 
-            this.node.on('mouseover', '[wlxml-tag]', function(e) { view.highlightNode($(e.target));});\r
-            this.node.on('mouseout', '[wlxml-tag]', function(e) { view.dimNode($(e.target));});\r
+            this.node.on('mouseover', '[wlxml-tag]', function(e) { mediator.nodeHovered($(e.target));});\r
+            this.node.on('mouseout', '[wlxml-tag]', function(e) { mediator.nodeBlured($(e.target));});\r
             this.node.on('click', '[wlxml-tag]', function(e) {\r
                 console.log('clicked node type: '+e.target.nodeType);\r
                 view._markSelected($(e.target));\r
@@ -91,7 +91,9 @@ rng.modules.visualEditor = function(sandbox) {
               });    \r
             });\r
             var config = { attributes: true, childList: true, characterData: true, subtree: true };\r
-            observer.observe(this.node.find('#rng-visualEditor-contentWrapper')[0], config);
+            observer.observe(this.node.find('#rng-visualEditor-contentWrapper')[0], config);\r
+            \r
+            this.gridToggled = false;
         },\r
         getMetaData: function() {\r
             var toret = {};\r
@@ -140,12 +142,12 @@ rng.modules.visualEditor = function(sandbox) {
                 this.selectNode(node);\r
         },\r
         highlightNode: function(node) {\r
-            node.addClass('rng-hover');\r
-            mediator.nodeHighlighted(node);\r
+            if(!this.gridToggled)\r
+                node.addClass('rng-hover');\r
         },\r
         dimNode: function(node) {\r
-            node.removeClass('rng-hover');\r
-            mediator.nodeDimmed(node);\r
+            if(!this.gridToggled)\r
+                node.removeClass('rng-hover');\r
         },\r
         highlightNodeById: function(id) {\r
             var node = this.node.find('#'+id);\r
@@ -173,6 +175,13 @@ rng.modules.visualEditor = function(sandbox) {
             var newRow = $(sandbox.getTemplate('metaItem')({key: key || '', value: value || ''}));\r
             newRow.appendTo(this.metaTable);\r
             return newRow;\r
+        },\r
+        toggleGrid: function(toggle) {\r
+            this.node.find('[wlxml-tag]').toggleClass('rng-hover', toggle);\r
+            this.gridToggled = toggle;\r
+        },\r
+        toggleTags: function(toggle) {\r
+        \r
         }\r
     };\r
     \r
@@ -252,7 +261,7 @@ rng.modules.visualEditor = function(sandbox) {
                 id: node.parent().attr('id')\r
             }\r
             var children = [];\r
-            node.children().each(function() {\r
+            node.children('[wlxml-tag]').each(function() {\r
                 var child = $(this);\r
                 children.push({repr: child.attr('wlxml-tag') + ' / ' + (child.attr('wlxml-class') || '[[no class]]'), id: child.attr('id')});\r
             });\r
@@ -269,8 +278,24 @@ rng.modules.visualEditor = function(sandbox) {
         }\r
     }\r
     \r
+    var toolbarView = {\r
+        node: view.node.find('#rng-visualEditor-toolbar'),\r
+        setup: function() {\r
+            var view = this;\r
+            \r
+            view.node.find('button').click(function(e) {\r
+                var btn = $(e.currentTarget);\r
+                if(btn.attr('data-btn-type') === 'toggle') {\r
+                    btn.toggleClass('active')\r
+                    mediator.toolbarButtonToggled(btn.attr('data-btn'), btn.hasClass('active'));\r
+                }\r
+            });\r
+        }\r
+    }\r
+    \r
     view.setup();\r
     sideBarView.setup();\r
+    toolbarView.setup();\r
     \r
     var mediator = {\r
         getCurrentNode: function() {\r
@@ -292,12 +317,21 @@ rng.modules.visualEditor = function(sandbox) {
         nodeDimmedById: function(id) {\r
             view.dimNodeById(id);\r
         },\r
-        nodeHighlighted: function(node) {\r
+        toolbarButtonToggled: function(btn, toggle) {\r
+            if(btn === 'grid')\r
+                view.toggleGrid(toggle);\r
+            if(btn === 'tags')\r
+                view.toggleTags(toggle);\r
+        },\r
+        nodeHovered: function(node) {\r
+            view.highlightNode(node);\r
             sideBarView.highlightNode(node.attr('id'));\r
         },\r
-        nodeDimmed: function(node) {\r
+        nodeBlured: function(node) {\r
+            view.dimNode(node);\r
             sideBarView.dimNode(node.attr('id'));\r
         }\r
+        \r
     }\r
     \r
     var isDirty = false;\r