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');
26 atype = $this.attr('data-tag');
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 = $(atype, doc);
81 var counter = annos.length;
82 var atype_rx = atype.replace(/,/g, '|');
83 var ann_expr = new RegExp("^<("+atype_rx+")[^>]*>|</("+atype_rx+")>$", "g")
85 if (annos.length == 0)
87 self.$annos.html('Nie ma żadnych przypisów');
91 annos.each(function (i, elem) {
92 xml_text = serializer.serializeToString(elem).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;