X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..54612c196135c939a7d17d51b81b1357f6eac9c3:/src/redakcja/static/js/wiki/view_annotations.js
diff --git a/src/redakcja/static/js/wiki/view_annotations.js b/src/redakcja/static/js/wiki/view_annotations.js
index b55effd0..8e3671ab 100644
--- a/src/redakcja/static/js/wiki/view_annotations.js
+++ b/src/redakcja/static/js/wiki/view_annotations.js
@@ -3,15 +3,13 @@
/*
* Perspective
*/
- function AnnotationsPerspective(options){
- var old_callback = options.callback || function() { };
+ class AnnotationsPerspective extends $.wiki.SidebarPerspective {
+ vsplitbar = 'PRZYPISY';
- this.noupdate_hash_onenter = true;
- this.vsplitbar = 'PRZYPISY';
+ constructor(options) {
+ super(options);
- options.callback = function(){
var self = this;
-
this.$element = $("#side-annotations");
this.$error = $('.error-message', this.$element);
this.$annos = $('.annotations-list', this.$element);
@@ -27,154 +25,144 @@
self.$annos.hide();
self.$error.hide();
- self.$spinner.show(100, function(){
- self.refresh(self, atype);
+ self.$spinner.fadeIn(100, function() {
+ self.refresh(atype);
});
});
-
- 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;
- var persp = $.wiki.activePerspective();
- if (persp == 'CodeMirrorPerspective') {
- xml = $.wiki.perspectives[persp].codemirror.getCode();
+ updateAnnotationIds() {
+ let self = this;
+ 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');
+ }
+ );
}
- else if (persp == 'VisualPerspective') {
- html2text({
- element: $('#html-view').find('div').get(0),
- success: function(text){
- xml = text;
+
+ goToAnnotation(srcNode) {
+ let self = this;
+ var content = $(srcNode).html();
+ content = content.replace(/>/g, '>').replace(/</g, '<').replace(/&/g, '&');
+ xml2html({
+ xml: ''+content+'',
+ success: function(txt) {
+ content = $(txt).html();
},
- error: function(text){
- self.$error.html('
WystÄ
piÅ bÅÄ
d:
' + text + '
');
+ error: function(text) {
+ $.unblockUI();
+ self.$error.html('' + text + '
');
self.$spinner.hide();
self.$error.show();
}
});
- self.updateAnnotationIds(self);
- }
- else {
- xml = this.doc.text;
- }
- var parser = new DOMParser();
- var serializer = new XMLSerializer();
- var doc = parser.parseFromString(xml, 'text/xml');
- var error = $('parsererror', doc);
+ var anchor = self.annotationToAnchor[content];
+ if (anchor != undefined) {
+ var $htmlView = $("#html-view");
+ var top = $("[name=" + anchor + "]", $htmlView).offset().top -
+ $htmlView.offset().top +
+ $htmlView.scrollTop()
+ ;
- if (error.length > 0) {
- self.$error.html('BÅÄ
d parsowania XML.');
- self.$spinner.hide();
- self.$error.show();
- }
- else {
- self.$annos.html('');
- 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");
-
- if (annos.length == 0)
- {
- self.$annos.html('Nie ma żadnych przypisów');
- self.$spinner.hide();
- self.$annos.show();
+ $htmlView.animate({scrollTop: top}, 250);
}
- annos.each(function (i, elem) {
- 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(/");
- 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);});
- for (i in anno_list)
- self.$annos.append(anno_list[i]);
- self.$spinner.hide();
- self.$annos.show();
- }
+ }
- }
- }(xml_text),
- error: function(text) {
- $.unblockUI();
- self.$error.html(text);
+ refresh(atype) {
+ let self = this;
+ var xml;
+
+ var persp = $.wiki.activePerspective();
+ if (persp == 'CodeMirrorPerspective') {
+ xml = $.wiki.perspectives[persp].codemirror.getValue();
+ }
+ else if (persp == 'VisualPerspective') {
+ html2text({
+ element: $('#html-view').find('div').get(0),
+ success: function(text){
+ xml = text;
+ },
+ error: function(text){
+ self.$error.html('
WystÄ
piÅ bÅÄ
d:
' + text + '
');
self.$spinner.hide();
self.$error.show();
}
});
- });
- }
- };
-
-
- AnnotationsPerspective.prototype.onEnter = function(){
- $.wiki.Perspective.prototype.onEnter.call(this);
-
- $('.vsplitbar').not('.active').trigger('click');
- $(".vsplitbar-title").html("↓ PRZYPISY ↓");
- this.$refresh.filter('.active').trigger('click');
+ self.updateAnnotationIds();
+ }
+ else {
+ xml = this.doc.text;
+ }
- };
+ var parser = new DOMParser();
+ var serializer = new XMLSerializer();
+ var doc = parser.parseFromString(xml, 'text/xml');
+ var error = $('parsererror', doc);
- AnnotationsPerspective.prototype.onExit = function(success, failure) {
+ if (error.length > 0) {
+ self.$error.html('
BÅÄ
d parsowania XML.');
+ self.$spinner.hide();
+ self.$error.show();
+ }
+ else {
+ self.$annos.html('');
+ 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");
+
+ if (annos.length == 0)
+ {
+ self.$annos.html('
Nie ma żadnych przypisów
');
+ self.$spinner.hide();
+ self.$annos.show();
+ }
+ annos.each(function (i, elem) {
+ 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(/");
+ anno_list.push(elem);
+ $(".src", elem).click(function() { self.goToAnnotation(this); });
+ counter--;
+
+ if (!counter) {
+ anno_list.sort(function(a, b){return a.sortby.localeCompare(b.sortby);});
+ for (i in anno_list)
+ self.$annos.append(anno_list[i]);
+ self.$spinner.hide();
+ self.$annos.show();
+ }
+ }
+ }(xml_text),
+ error: function(text) {
+ $.unblockUI();
+ self.$error.html('
' + text + '
');
+ self.$spinner.hide();
+ self.$error.show();
+ }
+ });
+ });
+ }
+ }
+ onEnter() {
+ super.onEnter();
+ this.$refresh.filter('.active').trigger('click');
};
+ onExit(success, failure) {};
+ }
$.wiki.AnnotationsPerspective = AnnotationsPerspective;
})(jQuery);