Visual Editor: Moving wlxml information to its own attribute
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 17 Apr 2013 08:31:39 +0000 (10:31 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 17 Apr 2013 08:31:39 +0000 (10:31 +0200)
editor.css
modules/visualEditor.js
modules/visualEditor.transformations.js

index 667db19..a6691f2 100644 (file)
@@ -65,20 +65,20 @@ body {
     height: 500px;\r
 }\r
 \r
-.rng {\r
+[wlxml-tag] {\r
     float: none !important; /* temporaty workaround for Bootstrap's influence via [class*="span"] { float: left; } */\r
     border-color: white;\r
     border-style:solid;\r
     border-width:1px;\r
 }\r
 \r
-.rng-header {\r
+[wlxml-tag=header] {\r
     font-size: 19px;\r
     font-style: bold;\r
     margin-bottom: 10px;\r
 }\r
 \r
-.rng-section {\r
+[wlxml-tag=section] {\r
     margin-top: 10px;\r
     margin-bottom: 10px;\r
 }\r
index 38f3302..132c70f 100644 (file)
@@ -14,9 +14,10 @@ rng.modules.visualEditor = function(sandbox) {
                 isDirty = true;\r
             });\r
 
-            this.node.on('mouseover', '.rng', function(e) { $(e.target).addClass('rng-hover')});\r
-            this.node.on('mouseout', '.rng', function(e) { $(e.target).removeClass('rng-hover')});\r
-            this.node.on('click', '.rng', function(e) {\r
+            this.node.on('mouseover', '[wlxml-tag]', function(e) { $(e.target).addClass('rng-hover')});\r
+            this.node.on('mouseout', '[wlxml-tag]', function(e) { $(e.target).removeClass('rng-hover')});\r
+            this.node.on('click', '[wlxml-tag]', function(e) {\r
+                console.log('clicked node type: '+e.target.nodeType);\r
                 view._markSelected($(e.target));\r
             });\r
 \r
@@ -24,7 +25,7 @@ rng.modules.visualEditor = function(sandbox) {
                 var anchor = $(window.getSelection().anchorNode);\r
                 if(anchor[0].nodeType === Node.TEXT_NODE)\r
                     anchor = anchor.parent();\r
-                if(!anchor.hasClass('rng'))\r
+                if(!anchor.is('[wlxml-tag]'))\r
                     return;\r
                 view._markSelected(anchor);\r
             });
@@ -54,7 +55,7 @@ rng.modules.visualEditor = function(sandbox) {
             return this.node.find('#rng-visualEditor-content').html();\r
         }, \r
         _markSelected: function(node) {\r
-            this.node.find('.rng').removeClass('rng-current');\r
+            this.node.find('.rng-current').removeClass('rng-current');\r
             node.addClass('rng-current');\r
         }\r
     };\r
index cfb5877..c2b0d3a 100644 (file)
@@ -21,7 +21,7 @@ if(typeof module !== 'undefined' && module.exports) {
                 console.log('running ' + tagName);
                 toret.find(tagName).replaceWith(function() {
                     var suffix = tagName !== 'div'  ? tagName : 'block';
-                    return $('<div></div>').addClass('rng rng-' + suffix).append($(this).contents());
+                    return $('<div></div>').attr('wlxml-tag', suffix).append($(this).contents());
                 });
             });
             
@@ -29,7 +29,7 @@ if(typeof module !== 'undefined' && module.exports) {
                 tagName = tagName.toLowerCase();
                 toret.find(tagName).replaceWith(function() {
                     var node = this;
-                    return $('<span></span>').addClass('rng rng-' + tagName).append($(this).contents());
+                    return $('<span></span>').attr('wlxml-tag', tagName).append($(this).contents());
                 });
             });
             return toret.children();
@@ -59,7 +59,7 @@ if(typeof module !== 'undefined' && module.exports) {
             
             toret.find('div, span').replaceWith(function() {
                 var div = $(this);
-                var tagName = div.attr('class').split('rng-')[1];
+                var tagName = div.attr('wlxml-tag');
                 return $('<'+tagName+'>').append(div.contents());
             });