From: Marcin Koziej Date: Fri, 7 Sep 2012 07:52:12 +0000 (+0200) Subject: Click on annotation in the list to scroll to it in visual editor X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/90db3bbc700e6ee98fe222cd7de72b7dccc82bcc?ds=sidebyside;hp=a494a95bf89ed6aa55b5f14b71a343e33d55bd60 Click on annotation in the list to scroll to it in visual editor --- diff --git a/redakcja/static/js/wiki/view_annotations.js b/redakcja/static/js/wiki/view_annotations.js index 5bac593c..76a0ae9e 100644 --- a/redakcja/static/js/wiki/view_annotations.js +++ b/redakcja/static/js/wiki/view_annotations.js @@ -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; @@ -97,6 +137,7 @@ 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) {