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