6 class AnnotationsPerspective extends $.wiki.SidebarPerspective {
7 vsplitbar = 'PRZYPISY';
13 this.$element = $("#side-annotations");
14 this.$error = $('.error-message', this.$element);
15 this.$annos = $('.annotations-list', this.$element);
16 this.$spinner = $('.spinner', this.$element);
17 this.$refresh = $('.refresh', this.$element);
19 this.$refresh.click(function() {
22 self.$refresh.removeClass('active');
23 $this.addClass('active');
24 var atype = $this.attr('data-tag');
28 self.$spinner.fadeIn(100, function() {
34 updateAnnotationIds() {
36 self.annotationToAnchor = {};
37 $('#html-view').find('.annotation-inline-box').each(
38 function(i, annoBox) {
39 var $annoBox = $(annoBox);
40 var $anchor = $("a[name|=anchor]", $annoBox);
41 var htmlContent = $('span', $annoBox).html();
42 // TBD: perhaps use a hash of htmlContent as key
43 self.annotationToAnchor[htmlContent] = $anchor.attr('name');
48 goToAnnotation(srcNode) {
50 var content = $(srcNode).html();
51 content = content.replace(/>/g, '>').replace(/</g, '<').replace(/&/g, '&');
53 xml: '<root>'+content+'</root>',
54 success: function(txt) {
55 content = $(txt).html();
57 error: function(text) {
59 self.$error.html('<div class="alert alert-danger">' + text + '</div>');
65 var anchor = self.annotationToAnchor[content];
66 if (anchor != undefined) {
67 var $htmlView = $("#html-view");
68 var top = $("[name=" + anchor + "]", $htmlView).offset().top -
69 $htmlView.offset().top +
73 $htmlView.animate({scrollTop: top}, 250);
81 var persp = $.wiki.activePerspective();
82 if (persp == 'CodeMirrorPerspective') {
83 xml = $.wiki.perspectives[persp].codemirror.getValue();
85 else if (persp == 'VisualPerspective') {
87 element: $('#html-view').find('div').get(0),
88 success: function(text){
91 error: function(text){
92 self.$error.html('<div class="alert alert-danger"><p>Wystąpił błąd:</p><pre>' + text + '</pre></div>');
97 self.updateAnnotationIds();
103 var parser = new DOMParser();
104 var serializer = new XMLSerializer();
105 var doc = parser.parseFromString(xml, 'text/xml');
106 var error = $('parsererror', doc);
108 if (error.length > 0) {
109 self.$error.html('<div class="alert alert-danger">Błąd parsowania XML.</a>');
110 self.$spinner.hide();
114 self.$annos.html('');
116 var annos = $(atype, doc);
117 var counter = annos.length;
118 var atype_rx = atype.replace(/,/g, '|');
119 var ann_expr = new RegExp("^<("+atype_rx+")[^>]*>|</("+atype_rx+")>$", "g");
121 if (annos.length == 0)
123 self.$annos.html('<div class="alert alert-info">Nie ma żadnych przypisów</div>');
124 self.$spinner.hide();
127 annos.each(function (i, elem) {
128 var xml_text = serializer.serializeToString(elem).replace(ann_expr, "");
130 xml: "<akap>" + xml_text + "</akap>",
131 success: function(xml_text){
132 return function(elem){
133 elem.sortby = $(elem).text().trim();
134 $(elem).append("<div class='src'>"+ xml_text.replace(/&/g, "&").replace(/</g, "<") +"</div>");
135 anno_list.push(elem);
136 $(".src", elem).click(function() { self.goToAnnotation(this); });
140 anno_list.sort(function(a, b){return a.sortby.localeCompare(b.sortby);});
142 self.$annos.append(anno_list[i]);
143 self.$spinner.hide();
148 error: function(text) {
150 self.$error.html('<div class="alert alert-danger">' + text + '</div>');
151 self.$spinner.hide();
161 this.$refresh.filter('.active').trigger('click');
164 onExit(success, failure) {};
166 $.wiki.AnnotationsPerspective = AnnotationsPerspective;