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