Simple upgrade.
[redakcja.git] / src / redakcja / static / js / wiki / view_editor_wysiwyg.js
index f056edc..517c878 100644 (file)
     }
 
 
     }
 
 
+    function addReference(){
+        var selection = window.getSelection();
+        var n = selection.rangeCount;
+
+        if (n == 0) {
+            window.alert("Nie zaznaczono żadnego obszaru");
+            return false;
+        }
+
+        // for now allow only 1 range
+        if (n > 1) {
+            window.alert("Zaznacz jeden obszar");
+            return false;
+        }
+
+        // remember the selected range
+        var range = selection.getRangeAt(0);
+
+        if (!verifyTagInsertPoint(range.endContainer)) {
+            window.alert("Nie można wstawić w to miejsce przypisu.");
+            return false;
+        }
+
+        var tag = $('<span></span>');
+        range.collapse(false);
+        range.insertNode(tag[0]);
+
+        xml2html({
+            xml: '<ref href=""/>',
+            success: function(text){
+                var t = $(text);
+                tag.replaceWith(t);
+                openForEdit(t);
+            },
+            error: function(){
+                tag.remove();
+                alert('Błąd przy dodawaniu referncji:' + errors);
+            }
+        })
+    }
+
+
+
+    
     /* Insert theme using current selection */
 
     function addTheme(){
     /* Insert theme using current selection */
 
     function addTheme(){
                 x = 100;
             }
         }
                 x = 100;
             }
         }
+        if ($origin.is('.reference-inline-box')) {
+            w = 400;
+            h = 32;
+            y -= 32;
+            x = Math.min(
+                x,
+                $('.htmlview div').offset().left + $('.htmlview div').width() - 400
+            );
+        }
 
         // start edition on this node
         var $overlay = $('<div class="html-editarea"><button class="accept-button">Zapisz</button><button class="delete-button">Usuń</button><button class="tytul-button akap-edit-button">tytuł dzieła</button><button class="wyroznienie-button akap-edit-button">wyróżnienie</button><button class="slowo-button akap-edit-button">słowo obce</button><button class="znak-button akap-edit-button">znak spec.</button><textarea></textarea></div>').css({
 
         // start edition on this node
         var $overlay = $('<div class="html-editarea"><button class="accept-button">Zapisz</button><button class="delete-button">Usuń</button><button class="tytul-button akap-edit-button">tytuł dzieła</button><button class="wyroznienie-button akap-edit-button">wyróżnienie</button><button class="slowo-button akap-edit-button">słowo obce</button><button class="znak-button akap-edit-button">znak spec.</button><textarea></textarea></div>').css({
         }).appendTo($box[0].offsetParent || $box.parent()).show();
         
 
         }).appendTo($box[0].offsetParent || $box.parent()).show();
         
 
-        if ($origin.is('.motyw')) {
+        if ($origin.is('*[x-edit-no-format]')) {
            $('.akap-edit-button').remove();
            $('.akap-edit-button').remove();
+        }
+        
+        if ($origin.is('.motyw')) {
             $.themes.autocomplete($('textarea', $overlay));
         }
 
             $.themes.autocomplete($('textarea', $overlay));
         }
 
                 };
             });
         }
                 };
             });
         }
-        else if($box.is('*[x-annotation-box]')) {
+        else if($box.is('*[x-annotation-box]') || $origin.is('*[x-edit-attribute]')) {
             $('.delete-button', $overlay).click(function(){
                 if (window.confirm("Czy jesteś pewien, że chcesz usunąć ten przypis?")) {
                     $origin.remove();
             $('.delete-button', $overlay).click(function(){
                 if (window.confirm("Czy jesteś pewien, że chcesz usunąć ten przypis?")) {
                     $origin.remove();
 
         var serializer = new XMLSerializer();
 
 
         var serializer = new XMLSerializer();
 
+        if($box.attr("x-edit-attribute")) {
+            source = $('<span x-pass-thru="true"/>');
+            source.text($box.attr("data-wlf-" + $box.attr("x-edit-attribute")));
+            source = source[0];
+        } else {
+            source = $box[0];
+        }
+        
         html2text({
         html2text({
-            element: $box[0],
+            element: source,
             stripOuter: true,
             success: function(text){
                 $('textarea', $overlay).val($.trim(text));
             stripOuter: true,
             success: function(text){
                 $('textarea', $overlay).val($.trim(text));
                         insertedText = insertedText.replace(/,\s*$/, '');
                     }
 
                         insertedText = insertedText.replace(/,\s*$/, '');
                     }
 
+                    if($box.attr("x-edit-attribute")) {
+                        xml = '<' + nodeName + ' ' + $box.attr("x-edit-attribute") + '="' + insertedText + '"/>';
+                    } else {
+                        xml = '<' + nodeName + '>' + insertedText + '</' + nodeName + '>';
+                    }
+
+                    
                     xml2html({
                     xml2html({
-                        xml: '<' + nodeName + '>' + insertedText + '</' + nodeName + '>',
+                        xml: xml,
                         success: function(element){
                             if (nodeName == 'out-of-flow-text') {
                                 $(element).children().insertAfter($origin);
                                 $origin.remove()
                             }
                         success: function(element){
                             if (nodeName == 'out-of-flow-text') {
                                 $(element).children().insertAfter($origin);
                                 $origin.remove()
                             }
+                            else if ($box.attr('x-edit-attribute')) {
+                                $(element).insertAfter($origin);
+                                $origin.remove();
+                            }
                             else {
                                 $origin.html($(element).html());
                             }
                             else {
                                 $origin.html($(element).html());
                             }
         });
     }
 
         });
     }
 
+
     function VisualPerspective(options){
 
         var old_callback = options.callback;
     function VisualPerspective(options){
 
         var old_callback = options.callback;
                     }
                 });
 
                     }
                 });
 
+                $('#insert-reference-button').click(function(){
+                    addReference();
+                    return false;
+                });
+
                 $('#insert-annotation-button').click(function(){
                     addAnnotation();
                     return false;
                 $('#insert-annotation-button').click(function(){
                     addAnnotation();
                     return false;
 
         xml2html({
             xml: this.doc.text,
 
         xml2html({
             xml: this.doc.text,
+            base: this.doc.getBase(),
             success: function(element){
                 var htmlView = $('#html-view');
                 htmlView.html(element);
             success: function(element){
                 var htmlView = $('#html-view');
                 htmlView.html(element);