From 9201c5810622e27a19de7e331046108d7110c46b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 19 Apr 2013 11:14:18 +0200 Subject: [PATCH] Visual editor: simple tagging capability --- editor.css | 20 ++++++++++++++++++-- modules/visualEditor.js | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/editor.css b/editor.css index 916239e..aa920c8 100644 --- a/editor.css +++ b/editor.css @@ -68,6 +68,7 @@ body { } +#rng-visualEditor-sidebar, #rng-visualEditor-sidebar p, #rng-visualEditor-sidebar td, #rng-visualEditor-sidebar label, @@ -109,15 +110,30 @@ body { margin-bottom: 0px; } -.rng-visualEditor-editPaneNodeForm label { +.rng-visualEditor-editPaneNodeForm label , +.rng-visualEditor-editPaneSelectionForm label +{ width: 50px; display: inline-block; } -.rng-visualEditor-editPaneNodeForm select { +.rng-visualEditor-editPaneNodeForm select, +.rng-visualEditor-editPaneSelectionForm select + { width: 100px; } + + +.rng-visualEditor-sidebarContentItem fieldset { + margin-bottom: 10px; +} + +.rng-visualEditor-sidebarContentItem legend { + font-size:11px; + height:30px; +} + #rng-visualEditor-meta table { margin-bottom:10px; } diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 8a96cb9..70fc435 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -127,6 +127,26 @@ rng.modules.visualEditor = function(sandbox) { mediator.getCurrentNode().attr('wlxml-'+attr, target.val()); isDirty = true; }); + + view.node.on('change', '.rng-visualEditor-editPaneSelectionForm select', function(e) { + var target = $(e.target); + var selection = window.getSelection(); + if(selection.anchorNode.isSameNode(selection.focusNode) && selection.anchorNode.nodeType === Node.TEXT_NODE) { + var startOffset = selection.anchorOffset; + var endOffset = selection.focusOffset; + if(startOffset > endOffset) { + var tmp = startOffset; + startOffset = endOffset; + endOffset = tmp; + } + var node = selection.anchorNode; + var prefix = node.data.substr(0, startOffset); + var suffix = node.data.substr(endOffset); + var core = node.data.substr(startOffset, endOffset - startOffset); + $(node).replaceWith(prefix + '' + core + '' + suffix); + isDirty = true; + } + }); }, selectTab: function(id) { this.node.find('.rng-visualEditor-sidebarContentItem').hide(); -- 2.20.1