From 75b7209eaa096a8d3bff42fa83eec838791b6f3a Mon Sep 17 00:00:00 2001 From: zuber Date: Thu, 14 Jan 2010 17:41:35 +0100 Subject: [PATCH] =?utf8?q?Edycja=20fragment=C3=B3w.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- platforma/static/js/main.js | 47 +++++++++++++++++++------------------ platforma/static/js/xslt.js | 14 ++++++++--- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/platforma/static/js/main.js b/platforma/static/js/main.js index ed22f590..de848350 100644 --- a/platforma/static/js/main.js +++ b/platforma/static/js/main.js @@ -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 = $('
'); + var $overlay = $('
').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() + '', 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) { diff --git a/platforma/static/js/xslt.js b/platforma/static/js/xslt.js index f6ddb878..71a68598 100644 --- a/platforma/static/js/xslt.js +++ b/platforma/static/js/xslt.js @@ -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'); }); }; -- 2.20.1