Usunięcie komunikatów do debugowania z xslt.js.
[redakcja.git] / platforma / static / js / main.js
index 41afe21..e5566a8 100644 (file)
@@ -1,3 +1,9 @@
+if (!window.console) {
+    window.console = {
+        log: function() {}
+    }
+}
+
 // Teraz nieużywane
 function highlight(colour) {
     var range, sel;
@@ -58,7 +64,6 @@ function gallery(element, url) {
     
     var pn = $('.page-number', element);
     pn.change(function(event) {
-        console.log('change!', $(this).val());
         event.preventDefault();
         var n = normalizeNumber(pn.val());
         pn.val(n);
@@ -88,7 +93,7 @@ function gallery(element, url) {
         zoom();
     });
     $('.change-gallery', element).click(function() {
-        $('.chosen-gallery').val($('#document-meta .gallery').html() || '/gallery/');
+        $('.chosen-gallery').val($('#document-meta .gallery').html() || '/platforma/gallery/');
         $('.gallery-image').animate({top: 53}, 200);
         $('.chosen-gallery').focus();
     });
@@ -114,7 +119,10 @@ function gallery(element, url) {
             galleryWidth: $(this).parent().width(),
             galleryHeight: $(this).parent().height()
         };
-        console.log('load', imageDimensions)
+        
+        if (!(imageDimensions.width && imageDimensions.height)) {
+            setTimeout(function() { $('img', element).load(); }, 100);
+        }        
         var position = normalizePosition(
             image.position().left,
             image.position().top, 
@@ -176,7 +184,6 @@ function gallery(element, url) {
             imageDimensions.width,
             imageDimensions.height
         );
-        console.log(image.position(), imageDimensions, position);
         image.css({width: imageDimensions.width, height: imageDimensions.height,
             left: position.x, top: position.y});
 
@@ -288,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]');
@@ -355,8 +388,8 @@ $(function() {
     
     CodeMirror.fromTextArea('id_text', {
         parserfile: 'parsexml.js',
-        path: "/static/js/lib/codemirror/",
-        stylesheet: "/static/css/xmlcolors.css",
+        path: STATIC_URL + "js/lib/codemirror/",
+        stylesheet: STATIC_URL + "css/xmlcolors.css",
         parserConfig: {
             useHTMLKludges: false
         },