X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/800bc0a9753b761c8b3f7b2eb9320226332c8399..b5f8d214ba00903379f8716ef563f19743a120b6:/redakcja/static/js/wiki/view_annotations.js?ds=inline diff --git a/redakcja/static/js/wiki/view_annotations.js b/redakcja/static/js/wiki/view_annotations.js new file mode 100644 index 00000000..d51ce9c8 --- /dev/null +++ b/redakcja/static/js/wiki/view_annotations.js @@ -0,0 +1,114 @@ +(function($){ + + /* + * Perspective + */ + function AnnotationsPerspective(options){ + var old_callback = options.callback || function() { }; + + this.noupdate_hash_onenter = true; + + options.callback = function(){ + var self = this; + + this.$element = $("#side-annotations"); + this.$error = $('.error-message', this.$element); + this.$annos = $('.annotations-list', this.$element); + $('.refresh', this.$element).click(function() { + self.refresh(self); + }); + + old_callback.call(this); + }; + + $.wiki.Perspective.call(this, options); + }; + + AnnotationsPerspective.prototype = new $.wiki.Perspective(); + + AnnotationsPerspective.prototype.refresh = function(self) { + var xml; + + persp = $.wiki.activePerspective(); + if (persp == 'CodeMirrorPerspective') { + xml = $.wiki.perspectives[persp].codemirror.getCode(); + } + else if (persp == 'VisualPerspective') { + html2text({ + element: $('#html-view div').get(0), + success: function(text){ + xml = text; + }, + error: function(text){ + self.$error.html('

Wystąpił błąd:

' + text + '
'); + } + }); + } + 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.$error.show(); + self.$annos.hide(); + } + else { + self.$error.hide(); + self.$annos.hide(); + self.$annos.html(''); + var anno_list = new Array(); + var annos = doc.getElementsByTagName('pe'); + var counter = annos.length; + + for (var i=0; i]*>/g, "<$1akap>"); + xml2html({ + xml: text, + success: function(elem){ + elem.txt = $(elem).text().trim(); + anno_list.push(elem); + counter--; + + if (!counter) { + anno_list.sort(function(a, b){return (a.txt < b.txt) ? -1 : (a.txt > b.txt ? 1 : 0)}); + self.$annos.append(anno_list); + self.$annos.show(); + } + }, + error: function(text) { + $.unblockUI(); + self.$error.html(text); + self.$error.show(); + } + }); + } + } + } + + + AnnotationsPerspective.prototype.onEnter = function(success, failure){ + var self = this; + + $.wiki.Perspective.prototype.onEnter.call(this); + + $('.vsplitbar').not('.active').trigger('click'); + $(".vsplitbar-title").html("↓ PRZYPISY ↓"); + + this.refresh(this); + + }; + + AnnotationsPerspective.prototype.onExit = function(success, failure) { + + }; + + $.wiki.AnnotationsPerspective = AnnotationsPerspective; + +})(jQuery);