X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/73ef2b8442dc95f8b7279de812c30ac8626d5f39..3b0d1718ec6c9dddcee4a4620384a83e30ff6f2f:/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 5bac593c..b55effd0 100644
--- a/redakcja/static/js/wiki/view_annotations.js
+++ b/redakcja/static/js/wiki/view_annotations.js
@@ -19,11 +19,11 @@
this.$refresh = $('.refresh', this.$element);
this.$refresh.click(function() {
- $this = $(this);
+ var $this = $(this);
self.$refresh.removeClass('active');
$this.addClass('active');
- atype = $this.attr('data-tag');
+ var atype = $this.attr('data-tag');
self.$annos.hide();
self.$error.hide();
@@ -32,24 +32,63 @@
});
});
- old_callback.call(this);
+ old_callback.call(this);
};
$.wiki.Perspective.call(this, options);
- };
+ }
AnnotationsPerspective.prototype = new $.wiki.Perspective();
+ AnnotationsPerspective.prototype.updateAnnotationIds = function(self){
+ self.annotationToAnchor = {};
+ $('#html-view').find('.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;
- persp = $.wiki.activePerspective();
+ var persp = $.wiki.activePerspective();
if (persp == 'CodeMirrorPerspective') {
xml = $.wiki.perspectives[persp].codemirror.getCode();
}
else if (persp == 'VisualPerspective') {
html2text({
- element: $('#html-view div').get(0),
+ element: $('#html-view').find('div').get(0),
success: function(text){
xml = text;
},
@@ -59,6 +98,7 @@
self.$error.show();
}
});
+ self.updateAnnotationIds(self);
}
else {
xml = this.doc.text;
@@ -76,11 +116,11 @@
}
else {
self.$annos.html('');
- var anno_list = new Array();
+ var anno_list = [];
var annos = $(atype, doc);
var counter = annos.length;
var atype_rx = atype.replace(/,/g, '|');
- var ann_expr = new RegExp("^<("+atype_rx+")[^>]*>|("+atype_rx+")>$", "g")
+ var ann_expr = new RegExp("^<("+atype_rx+")[^>]*>|("+atype_rx+")>$", "g");
if (annos.length == 0)
{
@@ -89,14 +129,15 @@
self.$annos.show();
}
annos.each(function (i, elem) {
- xml_text = serializer.serializeToString(elem).replace(ann_expr, "");
+ var xml_text = serializer.serializeToString(elem).replace(ann_expr, "");
xml2html({
xml: "" + xml_text + "",
success: function(xml_text){
return function(elem){
elem.sortby = $(elem).text().trim();
- $(elem).append("
"+ xml_text.replace("&", "&", "g").replace("<", "<", "g") +"
")
+ $(elem).append(""+ xml_text.replace(/&/g, "&").replace(/");
anno_list.push(elem);
+ $(".src", elem).click(function() { self.goToAnnotation(self, this); });
counter--;
if (!counter) {
@@ -118,12 +159,10 @@
});
});
}
- }
-
+ };
- AnnotationsPerspective.prototype.onEnter = function(success, failure){
- var self = this;
+ AnnotationsPerspective.prototype.onEnter = function(){
$.wiki.Perspective.prototype.onEnter.call(this);
$('.vsplitbar').not('.active').trigger('click');
@@ -132,9 +171,9 @@
};
- AnnotationsPerspective.prototype.onExit = function(success, failure) {
+ AnnotationsPerspective.prototype.onExit = function(success, failure) {
- };
+ };
$.wiki.AnnotationsPerspective = AnnotationsPerspective;