6 function AnnotationsPerspective(options){
7 var old_callback = options.callback || function() { };
9 this.noupdate_hash_onenter = true;
11 options.callback = function(){
14 this.$element = $("#side-annotations");
15 this.$error = $('.error-message', this.$element);
16 this.$annos = $('.annotations-list', this.$element);
17 $('.refresh', this.$element).click(function() {
21 old_callback.call(this);
24 $.wiki.Perspective.call(this, options);
27 AnnotationsPerspective.prototype = new $.wiki.Perspective();
29 AnnotationsPerspective.prototype.refresh = function(self) {
32 persp = $.wiki.activePerspective();
33 if (persp == 'CodeMirrorPerspective') {
34 xml = $.wiki.perspectives[persp].codemirror.getCode();
36 else if (persp == 'VisualPerspective') {
38 element: $('#html-view div').get(0),
39 success: function(text){
42 error: function(text){
43 self.$error.html('<p>Wystąpił błąd:</p><pre>' + text + '</pre>');
51 var parser = new DOMParser();
52 var serializer = new XMLSerializer();
53 var doc = parser.parseFromString(xml, 'text/xml');
54 var error = $('parsererror', doc);
56 if (error.length > 0) {
57 self.$error.html('Błąd parsowania XML.');
65 var anno_list = new Array();
66 var annos = doc.getElementsByTagName('pe');
67 var counter = annos.length;
69 for (var i=0; i<annos.length; i++)
71 text = serializer.serializeToString(annos[i]).replace(/<(\/?)pe[^>]*>/g, "<$1akap>");
74 success: function(elem){
75 elem.txt = $(elem).text().trim();
80 anno_list.sort(function(a, b){return (a.txt < b.txt) ? -1 : (a.txt > b.txt ? 1 : 0)});
81 self.$annos.append(anno_list);
85 error: function(text) {
87 self.$error.html(text);
96 AnnotationsPerspective.prototype.onEnter = function(success, failure){
99 $.wiki.Perspective.prototype.onEnter.call(this);
101 $('.vsplitbar').not('.active').trigger('click');
102 $(".vsplitbar-title").html("↓ PRZYPISY ↓");
108 AnnotationsPerspective.prototype.onExit = function(success, failure) {
112 $.wiki.AnnotationsPerspective = AnnotationsPerspective;