Visual editor: simple tagging capability
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 19 Apr 2013 09:14:18 +0000 (11:14 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 19 Apr 2013 09:14:18 +0000 (11:14 +0200)
editor.css
modules/visualEditor.js

index 916239e..aa920c8 100644 (file)
@@ -68,6 +68,7 @@ body {
 \r
 }\r
 \r
+#rng-visualEditor-sidebar,\r
 #rng-visualEditor-sidebar p,\r
 #rng-visualEditor-sidebar td,\r
 #rng-visualEditor-sidebar label,\r
@@ -109,15 +110,30 @@ body {
     margin-bottom: 0px;\r
 }\r
 \r
-.rng-visualEditor-editPaneNodeForm  label {\r
+.rng-visualEditor-editPaneNodeForm  label ,\r
+.rng-visualEditor-editPaneSelectionForm  label\r
+{\r
     width: 50px;\r
     display: inline-block;\r
 }\r
 \r
-.rng-visualEditor-editPaneNodeForm  select {\r
+.rng-visualEditor-editPaneNodeForm  select,\r
+.rng-visualEditor-editPaneSelectionForm  select\r
+ {\r
     width: 100px;\r
 }\r
 \r
+\r
+\r
+.rng-visualEditor-sidebarContentItem fieldset {\r
+    margin-bottom: 10px;\r
+}\r
+\r
+.rng-visualEditor-sidebarContentItem  legend {\r
+    font-size:11px;\r
+    height:30px;\r
+}\r
+\r
 #rng-visualEditor-meta table {\r
     margin-bottom:10px;\r
 }\r
index 8a96cb9..70fc435 100644 (file)
@@ -127,6 +127,26 @@ rng.modules.visualEditor = function(sandbox) {
                 mediator.getCurrentNode().attr('wlxml-'+attr, target.val());\r
                 isDirty = true;\r
             });\r
+            \r
+            view.node.on('change', '.rng-visualEditor-editPaneSelectionForm select', function(e) {\r
+                var target = $(e.target);\r
+                var selection = window.getSelection();\r
+                if(selection.anchorNode.isSameNode(selection.focusNode) && selection.anchorNode.nodeType === Node.TEXT_NODE) {                   \r
+                    var startOffset = selection.anchorOffset;\r
+                    var endOffset = selection.focusOffset;\r
+                    if(startOffset > endOffset) {\r
+                        var tmp = startOffset;\r
+                        startOffset = endOffset;\r
+                        endOffset = tmp;\r
+                    }\r
+                    var node = selection.anchorNode;\r
+                    var prefix = node.data.substr(0, startOffset);\r
+                    var suffix = node.data.substr(endOffset);\r
+                    var core = node.data.substr(startOffset, endOffset - startOffset);\r
+                    $(node).replaceWith(prefix + '<span wlxml-tag="' + target.val() + '">' + core + '</span>' + suffix);                   \r
+                    isDirty = true;\r
+                }\r
+            });\r
         },\r
         selectTab: function(id) {\r
            this.node.find('.rng-visualEditor-sidebarContentItem').hide();\r