Edycja paragrafów.
authorzuber <marek@stepniowski.com>
Tue, 12 Jan 2010 15:58:00 +0000 (16:58 +0100)
committerzuber <marek@stepniowski.com>
Tue, 12 Jan 2010 15:58:00 +0000 (16:58 +0100)
platforma/static/css/html.css
platforma/static/js/main.js
platforma/static/js/xslt.js
platforma/static/xsl/wl2html_client.xsl

index 57eed6d..2c78efa 100755 (executable)
 
 .html-editarea textarea
 {
 
 .html-editarea textarea
 {
-    border: 2px solid black;
+/*    border: 2px solid black;*/
     
     margin: 0px;
     padding: 0px;
     
     margin: 0px;
     padding: 0px;
index a49cb6a..e5566a8 100644 (file)
@@ -295,52 +295,78 @@ function html(element) {
         }
     };
     
         }
     };
     
-    // function openForEdit($origin)
-    // {       
-    //     // if(this.currentOpen && this.currentOpen != $origin) {
-    //     //     this.closeWithSave(this.currentOpen);
-    //     // }
-    //     
-    //     var $box = null
-    // 
-    //     // annotations overlay their sub box - not their own box //
-    //     if($origin.is(".annotation-inline-box"))
-    //         $box = $("*[x-annotation-box]", $origin);
-    //     else
-    //         $box = $origin;
-    //     
-    //     var x = $box[0].offsetLeft;
-    //     var y = $box[0].offsetTop;
-    //     var w = $box.outerWidth();
-    //     var h = $box.innerHeight();
-    // 
-    //     console.log("Edit origin:", $origin, " box:", $box);
-    //     console.log("offsetParent:", $box[0].offsetParent);
-    //     console.log("Dimensions: ", x, y, w , h);
-    // 
-    //     // start edition on this node
-    //     var $overlay = $('<div class="html-editarea"><textarea></textarea></div>');
-    // 
-    //     h = Math.max(h - 20, 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() {
-    //     openForEdit($(this).parent());
-    // });
-    // 
+    function openForEdit($origin)
+    {       
+        // if(this.currentOpen && this.currentOpen != $origin) {
+        //     this.closeWithSave(this.currentOpen);
+        // }
+        
+        var $box = null
+    
+        // annotations overlay their sub box - not their own box //
+        if($origin.is(".annotation-inline-box"))
+            $box = $("*[x-annotation-box]", $origin);
+        else
+            $box = $origin;
+        
+        var x = $box[0].offsetLeft;
+        var y = $box[0].offsetTop;
+        var w = $box.outerWidth();
+        var h = $box.innerHeight();
+    
+        console.log("Edit origin:", $origin, " box:", $box);
+        console.log("offsetParent:", $box[0].offsetParent);
+        console.log("Dimensions: ", x, y, w , h);
+    
+        // start edition on this node
+        var $overlay = $('<div class="html-editarea"><textarea></textarea></div>');
+        var serializer = new XMLSerializer();
+    
+        html2xml({
+            xml: serializer.serializeToString($box.get(0)),
+            success: function(text) {
+                $('textarea', $overlay).focus().val($.trim(text));
+                
+                $('textarea', $overlay).one('blur', function(event) {
+                    xml2html({
+                        xml: $('textarea', $overlay).val(),
+                        success: function(element) {
+                            $box.after(element);
+                            $overlay.remove();
+                            $box.remove();
+                        },
+                        error: function(text) {
+                            $overlay.remove();
+                            alert('Błąd! ' + text);
+                        }
+                    })
+                });
+            }, error: function(text) {
+                alert('Błąd! ' + text);
+            }
+        });
+        
+        h = Math.max(h - 20, 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) {
+        openForEdit($(this).parent());
+        return false;
+    });
+    
     var button = $('<button class="edit-button">Edytuj</button>');
     $(element).bind('mousemove', function(event) {
         var editable = $(event.target).closest('*[x-editable]');
     var button = $('<button class="edit-button">Edytuj</button>');
     $(element).bind('mousemove', function(event) {
         var editable = $(event.target).closest('*[x-editable]');
index e098a7d..48543e6 100644 (file)
@@ -168,9 +168,11 @@ function xml2html(options) {
         if (error.length > 0 && options.error) {
             options.error(error.text());
         } else {
         if (error.length > 0 && options.error) {
             options.error(error.text());
         } else {
+            // console.log(options.xml);
+            console.log(doc, doc.firstChild);
             options.success(doc.firstChild);
         }
             options.success(doc.firstChild);
         }
-    }, function() { options.error && options.success('Nie udało się załadować XSLT'); });
+    }, function() { options.error && options.error('Nie udało się załadować XSLT'); });
 }
 
 
 }
 
 
@@ -194,6 +196,6 @@ function html2xml(options) {
         } else {
             options.success(serialize(doc.documentElement).join(''));                              
         }
         } else {
             options.success(serialize(doc.documentElement).join(''));                              
         }
-    }, function() { options.error && options.success('Nie udało się załadować XSLT'); });
+    }, function() { options.error && options.error('Nie udało się załadować XSLT'); });
 };
 
 };
 
index fa3665b..d9758ea 100755 (executable)
@@ -7,9 +7,9 @@
     -->        
     <xsl:output method="xml" encoding="utf-8" indent="no" omit-xml-declaration="yes" />
 
     -->        
     <xsl:output method="xml" encoding="utf-8" indent="no" omit-xml-declaration="yes" />
 
-    <xsl:template match="/">
+    <!-- <xsl:template match="/">
         <xsl:apply-templates select="chunk|utwor" />
         <xsl:apply-templates select="chunk|utwor" />
-    </xsl:template>
+    </xsl:template> -->
 
     <!--
         Base tag for rendering a fragment of text
 
     <!--
         Base tag for rendering a fragment of text