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 = $htmlView.offset().top +
69 $("[name=" + anchor + "]", $htmlView).offset().top -
70 $htmlView.children().eq(0).offset().top;
72 $htmlView.animate({scrollTop: top}, 250);
80 var persp = $.wiki.activePerspective();
81 if (persp == 'CodeMirrorPerspective') {
82 xml = $.wiki.perspectives[persp].codemirror.getValue();
84 else if (persp == 'VisualPerspective') {
86 element: $('#html-view').find('div').get(0),
87 success: function(text){
90 error: function(text){
91 self.$error.html('<div class="alert alert-danger"><p>Wystąpił błąd:</p><pre>' + text + '</pre></div>');
96 self.updateAnnotationIds();
102 var parser = new DOMParser();
103 var serializer = new XMLSerializer();
104 var doc = parser.parseFromString(xml, 'text/xml');
105 var error = $('parsererror', doc);
107 if (error.length > 0) {
108 self.$error.html('<div class="alert alert-danger">Błąd parsowania XML.</a>');
109 self.$spinner.hide();
113 self.$annos.html('');
115 var annos = $(atype, doc);
116 var counter = annos.length;
117 var atype_rx = atype.replace(/,/g, '|');
118 var ann_expr = new RegExp("^<("+atype_rx+")[^>]*>|</("+atype_rx+")>$", "g");
120 if (annos.length == 0)
122 self.$annos.html('<div class="alert alert-info">Nie ma żadnych przypisów</div>');
123 self.$spinner.hide();
126 annos.each(function (i, elem) {
127 var xml_text = serializer.serializeToString(elem).replace(ann_expr, "");
129 xml: "<akap>" + xml_text + "</akap>",
130 success: function(xml_text){
131 return function(elem){
132 elem.sortby = $(elem).text().trim();
133 $(elem).append("<div class='src'>"+ xml_text.replace(/&/g, "&").replace(/</g, "<") +"</div>");
134 anno_list.push(elem);
135 $(".src", elem).click(function() { self.goToAnnotation(this); });
139 anno_list.sort(function(a, b){return a.sortby.localeCompare(b.sortby);});
141 self.$annos.append(anno_list[i]);
142 self.$spinner.hide();
147 error: function(text) {
149 self.$error.html('<div class="alert alert-danger">' + text + '</div>');
150 self.$spinner.hide();
160 this.$refresh.filter('.active').trigger('click');
163 onExit(success, failure) {};
165 $.wiki.AnnotationsPerspective = AnnotationsPerspective;