cover previews
[redakcja.git] / 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                 this.doc.refreshCover({
24                         success: function(text) {
25                                 $('#summary-cover').attr('src', text);
26                         }
27                 });
28         };
29
30     SummaryPerspective.prototype.showCharCount = function() {
31         var cc;
32         try {
33             cc = this.doc.getLength();
34             $('#charcount_untagged').hide();
35         }
36         catch (e) {
37             $('#charcount_untagged').show();
38             cc = this.doc.text.replace(/\s{2,}/g, ' ').length;
39         }
40         $('#charcount').html(cc);
41         $('#charcount_pages').html((Math.round(cc/18)/100).toLocaleString());
42     }
43
44     SummaryPerspective.prototype.freezeState = function(){
45         // must
46     };
47
48         SummaryPerspective.prototype.onEnter = function(success, failure){
49                 $.wiki.Perspective.prototype.onEnter.call(this);
50                 
51                 this.showCharCount();
52
53                 console.log("Entered summery view");
54         };
55
56         $.wiki.SummaryPerspective = SummaryPerspective;
57
58 })(jQuery);
59