Edycja fragmentów.
authorzuber <marek@stepniowski.com>
Thu, 14 Jan 2010 16:41:35 +0000 (17:41 +0100)
committerzuber <marek@stepniowski.com>
Thu, 14 Jan 2010 16:41:35 +0000 (17:41 +0100)
platforma/static/js/main.js
platforma/static/js/xslt.js

index ed22f59..de84835 100644 (file)
@@ -306,37 +306,53 @@ function html(element) {
         var $box = null
     
         // annotations overlay their sub box - not their own box //
-        if($origin.is(".annotation-inline-box"))
+        if($origin.is(".annotation-inline-box")) {
             $box = $("*[x-annotation-box]", $origin);
-        else
+            console.log('annotation!', $box);
+        } else {
             $box = $origin;
+        }
         
         var x = $box[0].offsetLeft;
         var y = $box[0].offsetTop;
         var w = $box.outerWidth();
         var h = $box.innerHeight();
     
+        console.log('width:', w, 'height:', h);
+
         // start edition on this node
-        var $overlay = $('<div class="html-editarea"><textarea></textarea></div>');
+        var $overlay = $('<div class="html-editarea"><textarea></textarea></div>').css({
+            position: 'absolute',
+            height: h,
+            left: x,
+            top: y,
+            width: w
+            // right: 0
+        }).appendTo($box[0].offsetParent || element).show();
+        
+        console.log($overlay, $box[0].offsetParent || element);
+        
         var serializer = new XMLSerializer();
     
+        console.log($box.html());
         html2xml({
-            xml: serializer.serializeToString($box.get(0)),
+            xml: serializer.serializeToString($box[0]),
+            inner: true,
             success: function(text) {
                 $('textarea', $overlay).val($.trim(text));
+                console.log($.trim(text));
                 
                 setTimeout(function() {
-                    console.log('focus!');
                     $('textarea', $overlay).focus();
                 }, 100);
                 
                 $('textarea', $overlay).one('blur', function(event) {
+                    var nodeName = $box.attr('x-node') || 'pe';
                     xml2html({
-                        xml: $('textarea', $overlay).val(),
+                        xml: '<' + nodeName + '>' + $('textarea', $overlay).val() + '</' + nodeName + '>',
                         success: function(element) {
-                            $box.after(element);
+                            $box.html($(element).html());
                             $overlay.remove();
-                            $box.remove();
                         },
                         error: function(text) {
                             $overlay.remove();
@@ -348,21 +364,6 @@ function html(element) {
                 alert('Błąd! ' + text);
             }
         });
-        
-        // h = Math.max(h, 2*parseInt($box.css('line-height')));
-        
-        console.log(h);
-        
-        $overlay.css({
-            position: 'absolute',
-            height: h,
-            left: x,
-            top: y,
-            right: 0
-        });
-        
-        $($box[0].offsetParent).append($overlay);
-        console.log($overlay);
     }
     
     $('.edit-button').live('click', function(event) {
index f6ddb87..71a6859 100644 (file)
@@ -181,16 +181,24 @@ function html2xml(options) {
         var serializer = new XMLSerializer();
         var doc = parser.parseFromString(xml, 'text/xml');
         var error = $('parsererror', doc.documentElement);
-        
+
         if (error.length == 0) {
-            doc = html2xmlStylesheet.transformToDocument(doc, document);
+            doc = html2xmlStylesheet.transformToDocument(doc);
             error = $('parsererror', doc.documentElement);
         }
         
         if (error.length > 0 && options.error) {
             options.error(error.text());
         } else {
-            options.success(serialize(doc.documentElement).join(''));                              
+            if (options.inner) {
+                var result = [];
+                for (var i = 0; i < doc.documentElement.childNodes.length; i++) {
+                    result.push(serialize(doc.documentElement.childNodes[i]).join(''));
+                };
+                options.success(result.join(''));
+            } else {
+                options.success(serialize(doc.documentElement).join(''));
+            }
         }
     }, function() { options.error && options.error('Nie udało się załadować XSLT'); });
 };