Minor editing improvements.
[redakcja.git] / src / redakcja / static / js / wiki / view_editor_wysiwyg.js
index c5fa8c1..3d4ca02 100644 (file)
             success: function(text){
                 var t = $(text);
                 tag.replaceWith(t);
-                openForEdit(t);
+                openForEdit(t, trim=false);
             },
             error: function(){
                 tag.remove();
     }
 
     /* open edition window for selected fragment */
-    function openForEdit($origin){
+    function openForEdit($origin, trim=true){
         var $box = null
 
         // annotations overlay their sub box - not their own box //
             element: source,
             stripOuter: true,
             success: function(text){
-               let ttext = $.trim(text);
+               let ttext = text;
+               if (trim) {
+                   ttext = ttext.trim();
+               }
                 $('textarea', $overlay).val(ttext);
 
                 setTimeout(function(){
                     callback();
             }
 
+           let self = this;
             xml2html({
                 xml: this.doc.text,
                 base: this.doc.getBase(),
 
                     var htmlView = $('#html-view');
                     htmlView.html(element);
+                   self.renumber();
                     if ('PropertiesPerspective' in $.wiki.perspectives)
                         $.wiki.perspectives.PropertiesPerspective.enable();
 
                 }
             })
         }
+
+       renumber() {
+           let number = 0;
+            $('#html-view *').each((i, e) => {
+               let $e = $(e);
+               if ($e.closest('[x-node="abstrakt"]').length) return;
+               if ($e.closest('[x-node="nota_red"]').length) return;
+               if ($e.closest('[x-annotation-box="true"]').length) return;
+               let node = $e.attr('x-node');
+               if (node == 'numeracja') {
+                   number = 0;
+               } else if (['werset', 'akap', 'wers'].includes(node)) {
+                   number ++;
+                   $e.attr('x-number', number);
+               }
+           })
+       }
     }
 
     $.wiki.VisualPerspective = VisualPerspective;