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 this.$spinner = $('.spinner', this.$element);
19 this.$refresh = $('.refresh', this.$element);
21 this.$refresh.click(function() {
24 self.$refresh.removeClass('active');
25 $this.addClass('active');
30 self.$spinner.show(100, function(){
31 self.refresh(self, atype);
35 old_callback.call(this);
38 $.wiki.Perspective.call(this, options);
41 AnnotationsPerspective.prototype = new $.wiki.Perspective();
43 AnnotationsPerspective.prototype.refresh = function(self, atype) {
46 persp = $.wiki.activePerspective();
47 if (persp == 'CodeMirrorPerspective') {
48 xml = $.wiki.perspectives[persp].codemirror.getCode();
50 else if (persp == 'VisualPerspective') {
52 element: $('#html-view div').get(0),
53 success: function(text){
56 error: function(text){
57 self.$error.html('<p>Wystąpił błąd:</p><pre>' + text + '</pre>');
67 var parser = new DOMParser();
68 var serializer = new XMLSerializer();
69 var doc = parser.parseFromString(xml, 'text/xml');
70 var error = $('parsererror', doc);
72 if (error.length > 0) {
73 self.$error.html('Błąd parsowania XML.');
79 var anno_list = new Array();
80 var annos = doc.getElementsByTagName(atype);
81 var counter = annos.length;
83 if (annos.length == 0)
85 self.$annos.html('Nie ma żadnych przypisów');
89 for (var i=0; i<annos.length; i++)
91 ann_expr = new RegExp("^<"+atype+"[^>]*>|</"+atype+">$", "g")
92 xml_text = serializer.serializeToString(annos[i]).replace(ann_expr, "");
94 xml: "<akap>" + xml_text + "</akap>",
95 success: function(xml_text){
96 return function(elem){
97 elem.sortby = $(elem).text().trim();
98 $(elem).append("<div class='src'>"+ xml_text.replace("&", "&", "g").replace("<", "<", "g") +"</div>")
103 anno_list.sort(function(a, b){return a.sortby.localeCompare(b.sortby);});
104 self.$annos.append(anno_list);
105 self.$spinner.hide();
111 error: function(text) {
113 self.$error.html(text);
114 self.$spinner.hide();
123 AnnotationsPerspective.prototype.onEnter = function(success, failure){
126 $.wiki.Perspective.prototype.onEnter.call(this);
128 $('.vsplitbar').not('.active').trigger('click');
129 $(".vsplitbar-title").html("↓ PRZYPISY ↓");
130 this.$refresh.filter('.active').trigger('click');
134 AnnotationsPerspective.prototype.onExit = function(success, failure) {
138 $.wiki.AnnotationsPerspective = AnnotationsPerspective;