latex dir for debugging
[redakcja.git] / redakcja / static / js / wiki / view_editor_wysiwyg.js
index 1b75500..4353848 100644 (file)
         var random = Math.floor(4000000000 * Math.random());
         var id = ('' + date) + '-' + ('' + random);
 
-        var spoint = document.createRange();
-        var epoint = document.createRange();
-
-        spoint.setStart(range.startContainer, range.startOffset);
-        epoint.setStart(range.endContainer, range.endOffset);
-
+        var createPoint = function(container, offset) {
+            var offsetBetweenCommas = function(text, offset) {
+                if(text.length < 2 || offset < 1 || offset > text.length)
+                    return false;
+                return text[offset-1] === ',' && text[offset] === ',';
+            }
+            var point = document.createRange();
+            offset = offsetBetweenCommas(container.textContent, offset) ? offset - 1 : offset;
+            point.setStart(container, offset);
+            return point;
+        }
+        
+        var spoint = createPoint(range.startContainer, range.startOffset);
+        var epoint = createPoint(range.endContainer, range.endOffset);
+               
         var mtag, btag, etag, errors;
 
         // insert theme-ref
 
                 $('.accept-button', $overlay).click(function(){
                     save();
+                    $(document).unbind('click.blur-overlay');
                 });
 
                 $(document).bind('click.blur-overlay', function(event){
         xml2html({
             xml: this.doc.text,
             success: function(element){
-                $('#html-view').html(element);
+                var htmlView = $('#html-view');
+                htmlView.html(element);
+                htmlView.find('*[x-node]').dblclick(function(e) {
+                    if($(e.target).is('textarea'))
+                        return;
+                    var selection = window.getSelection();
+                    selection.collapseToStart();
+                    selection.modify('extend', 'forward', 'word');
+                    e.stopPropagation();
+                });
                 _finalize(success);
             },
             error: function(text, source){