X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/8f0bfbd922b46c4d9e484343694aaa141de5b4fc..c58ede829174b66ec4d2b0c949b771a3eed27e1b:/redakcja/static/js/wiki/view_annotations.js diff --git a/redakcja/static/js/wiki/view_annotations.js b/redakcja/static/js/wiki/view_annotations.js index f62cd65c..76a0ae9e 100644 --- a/redakcja/static/js/wiki/view_annotations.js +++ b/redakcja/static/js/wiki/view_annotations.js @@ -23,7 +23,7 @@ self.$refresh.removeClass('active'); $this.addClass('active'); - atype = $this.text(); + atype = $this.attr('data-tag'); self.$annos.hide(); self.$error.hide(); @@ -40,6 +40,45 @@ AnnotationsPerspective.prototype = new $.wiki.Perspective(); + AnnotationsPerspective.prototype.updateAnnotationIds = function(self){ + self.annotationToAnchor = {}; + $('#html-view .annotation-inline-box').each( + function(i, annoBox) { + var $annoBox = $(annoBox); + var $anchor = $("a[name|=anchor]", $annoBox); + var htmlContent = $('span', $annoBox).html(); + // TBD: perhaps use a hash of htmlContent as key + self.annotationToAnchor[htmlContent] = $anchor.attr('name'); + }); + } + + AnnotationsPerspective.prototype.goToAnnotation = function(self, srcNode){ + var content = $(srcNode).html(); + content = content.replace('>', '>', 'g').replace('<', '<', 'g').replace('&', '&', 'g'); + xml2html({ + xml: ''+content+'', + success: function(txt) { + content = $(txt).html(); + }, + error: function(text) { + $.unblockUI(); + self.$error.html(text); + self.$spinner.hide(); + self.$error.show(); + } + }); + + var anchor = self.annotationToAnchor[content]; + if (anchor != undefined) { + var $htmlView = $("#html-view"); + var top = $htmlView.offset().top + + $("[name=" + anchor + "]", $htmlView).offset().top - + $htmlView.children().eq(0).offset().top + + $htmlView.animate({scrollTop: top}, 250); + } + } + AnnotationsPerspective.prototype.refresh = function(self, atype) { var xml; @@ -59,6 +98,7 @@ self.$error.show(); } }); + self.updateAnnotationIds(self); } else { xml = this.doc.text; @@ -77,8 +117,10 @@ else { self.$annos.html(''); var anno_list = new Array(); - var annos = doc.getElementsByTagName(atype); + var annos = $(atype, doc); var counter = annos.length; + var atype_rx = atype.replace(/,/g, '|'); + var ann_expr = new RegExp("^<("+atype_rx+")[^>]*>|$", "g") if (annos.length == 0) { @@ -86,10 +128,8 @@ self.$spinner.hide(); self.$annos.show(); } - for (var i=0; i]*>|$", "g") - xml_text = serializer.serializeToString(annos[i]).replace(ann_expr, ""); + annos.each(function (i, elem) { + xml_text = serializer.serializeToString(elem).replace(ann_expr, ""); xml2html({ xml: "" + xml_text + "", success: function(xml_text){ @@ -97,11 +137,13 @@ elem.sortby = $(elem).text().trim(); $(elem).append("
"+ xml_text.replace("&", "&", "g").replace("<", "<", "g") +"
") anno_list.push(elem); + $(".src", elem).click(function() { self.goToAnnotation(self, this); }); counter--; if (!counter) { anno_list.sort(function(a, b){return a.sortby.localeCompare(b.sortby);}); - self.$annos.append(anno_list); + for (i in anno_list) + self.$annos.append(anno_list[i]); self.$spinner.hide(); self.$annos.show(); } @@ -115,7 +157,7 @@ self.$error.show(); } }); - } + }); } }