171e9b728aaa1fbd0d19e05fb02ec8fe4aa8c57b
[redakcja.git] / src / redakcja / static / js / wiki / view_summary.js
1 (function($){
2
3     class SummaryPerspective extends $.wiki.Perspective {
4         constructor(options) {
5             var old_callback = options.callback || function() {};
6
7             options.callback = function() {
8                 var self = this;
9
10                 // first time page is rendered
11                 $('#summary-cover-refresh').click(function() {
12                     self.refreshCover();
13                 });
14
15                 old_callback.call(this);
16             }
17
18             super(options);
19         }
20
21         refreshCover() {
22             $('#summary-cover-refresh').attr('disabled', 'disabled');
23             this.doc.refreshCover({
24                 success: function(text) {
25                     $('#summary-cover').attr('src', text);
26                     $('#summary-cover-refresh').removeAttr('disabled');
27                 }
28             });
29         }
30
31         showCharCount() {
32             var cc;
33             try {
34                 $('#charcounts_text').show();
35                 $('#charcounts_raw').hide();
36                 cc = this.doc.getLength({noFootnotes: true, noThemes: true});
37                 $('#charcount').html(cc);
38                 $('#charcount_pages').html((Math.round(cc/18)/100).toLocaleString());
39
40                 cc = this.doc.getLength();
41                 $('#charcount_full').html(cc);
42                 $('#charcount_full_pages').html((Math.round(cc/18)/100).toLocaleString());
43             }
44             catch (e) {
45                 $('#charcounts_text').hide();
46                 $('#charcounts_raw').show();
47                 cc = this.doc.text.replace(/\s{2,}/g, ' ').length;
48                 $('#charcount_raw').html(cc);
49                 $('#charcount_raw_pages').html((Math.round(cc/18)/100).toLocaleString());
50             }
51         }
52
53         freezeState = function() {
54             // must
55         }
56
57         onEnter(success, failure){
58             super.onEnter();
59
60             this.showCharCount();
61
62             console.log("Entered summery view");
63         }
64     }
65     $.wiki.SummaryPerspective = SummaryPerspective;
66
67 })(jQuery);