X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/8132fc186eb0c5fd02c86828c3a4735754296d02..5913c54d19b8f6775633176032161d49f9b2f1aa:/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
new file mode 100644
index 00000000..b55effd0
--- /dev/null
+++ b/src/redakcja/static/js/wiki/view_annotations.js
@@ -0,0 +1,180 @@
+(function($){
+
+ /*
+ * Perspective
+ */
+ function AnnotationsPerspective(options){
+ var old_callback = options.callback || function() { };
+
+ this.noupdate_hash_onenter = true;
+ this.vsplitbar = 'PRZYPISY';
+
+ options.callback = function(){
+ var self = this;
+
+ this.$element = $("#side-annotations");
+ this.$error = $('.error-message', this.$element);
+ this.$annos = $('.annotations-list', this.$element);
+ this.$spinner = $('.spinner', this.$element);
+ this.$refresh = $('.refresh', this.$element);
+
+ this.$refresh.click(function() {
+ var $this = $(this);
+
+ self.$refresh.removeClass('active');
+ $this.addClass('active');
+ var atype = $this.attr('data-tag');
+
+ self.$annos.hide();
+ self.$error.hide();
+ self.$spinner.show(100, function(){
+ self.refresh(self, 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: '
WystÄ piÅ bÅÄ d:
' + 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); + + 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: "