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 xml_text = serializer.serializeToString(annos[i]).replace(/^<pe[^>]*>|<\/pe>$/g, "");
73 xml: "<akap>" + xml_text + "</akap>",
74 success: function(xml_text){
75 return function(elem){
76 elem.sortby = $(elem).text().trim();
77 $(elem).append("<div class='src'>"+ xml_text.replace("&", "&", "g").replace("<", "<", "g") +"</div>")
82 anno_list.sort(function(a, b){return a.sortby.localeCompare(b.sortby);});
83 self.$annos.append(anno_list);
88 error: function(text) {
90 self.$error.html(text);
99 AnnotationsPerspective.prototype.onEnter = function(success, failure){
102 $.wiki.Perspective.prototype.onEnter.call(this);
104 $('.vsplitbar').not('.active').trigger('click');
105 $(".vsplitbar-title").html("↓ PRZYPISY ↓");
111 AnnotationsPerspective.prototype.onExit = function(success, failure) {
115 $.wiki.AnnotationsPerspective = AnnotationsPerspective;