6 function AnnotationsPerspective(options){
7 var old_callback = options.callback || function() { };
9 this.noupdate_hash_onenter = true;
10 this.vsplitbar = 'PRZYPISY';
12 options.callback = function(){
15 this.$element = $("#side-annotations");
16 this.$error = $('.error-message', this.$element);
17 this.$annos = $('.annotations-list', this.$element);
18 $('.refresh', this.$element).click(function() {
22 old_callback.call(this);
25 $.wiki.Perspective.call(this, options);
28 AnnotationsPerspective.prototype = new $.wiki.Perspective();
30 AnnotationsPerspective.prototype.refresh = function(self) {
33 persp = $.wiki.activePerspective();
34 if (persp == 'CodeMirrorPerspective') {
35 xml = $.wiki.perspectives[persp].codemirror.getCode();
37 else if (persp == 'VisualPerspective') {
39 element: $('#html-view div').get(0),
40 success: function(text){
43 error: function(text){
44 self.$error.html('<p>Wystąpił błąd:</p><pre>' + text + '</pre>');
52 var parser = new DOMParser();
53 var serializer = new XMLSerializer();
54 var doc = parser.parseFromString(xml, 'text/xml');
55 var error = $('parsererror', doc);
57 if (error.length > 0) {
58 self.$error.html('Błąd parsowania XML.');
66 var anno_list = new Array();
67 var annos = doc.getElementsByTagName('pe');
68 var counter = annos.length;
70 for (var i=0; i<annos.length; i++)
72 xml_text = serializer.serializeToString(annos[i]).replace(/^<pe[^>]*>|<\/pe>$/g, "");
74 xml: "<akap>" + xml_text + "</akap>",
75 success: function(xml_text){
76 return function(elem){
77 elem.sortby = $(elem).text().trim();
78 $(elem).append("<div class='src'>"+ xml_text.replace("&", "&", "g").replace("<", "<", "g") +"</div>")
83 anno_list.sort(function(a, b){return a.sortby.localeCompare(b.sortby);});
84 self.$annos.append(anno_list);
89 error: function(text) {
91 self.$error.html(text);
100 AnnotationsPerspective.prototype.onEnter = function(success, failure){
103 $.wiki.Perspective.prototype.onEnter.call(this);
105 $('.vsplitbar').not('.active').trigger('click');
106 $(".vsplitbar-title").html("↓ PRZYPISY ↓");
112 AnnotationsPerspective.prototype.onExit = function(success, failure) {
116 $.wiki.AnnotationsPerspective = AnnotationsPerspective;