fixing one typo and making string formatting consistent.
[oweals/karmaworld.git] / karmaworld / assets / js / note-detail.js
1 // resize the iframe based on internal contents on page load
2 function autoResize(id){
3   var newheight;
4   var newwidth;
5
6   if(document.getElementById){
7     newheight = document.getElementById(id).contentWindow.document .body.scrollHeight;
8     newwidth = document.getElementById(id).contentWindow.document .body.scrollWidth;
9   }
10
11   document.getElementById(id).height = (newheight + 10) + "px";
12   document.getElementById(id).width= (newwidth + 5) + "px";
13 }
14
15 function rescalePdf(viewer, frameWidth) {
16   var scaleBase = 750;
17   var outlineWidth = 250;
18   var pdfWidth = frameWidth;
19
20   if ($(viewer.sidebar).hasClass('opened')){
21     pdfWidth = pdfWidth - 250;
22   }
23
24   var newPdfScale = pdfWidth / scaleBase;
25   viewer.rescale(newPdfScale);
26 }
27
28 function setupPdfViewer() {
29   var noteFrame = document.getElementById("noteframe")
30   var pdfViewer = noteFrame.contentWindow.pdf2htmlEX.defaultViewer;
31
32   $('#plus-btn').click(function (){
33     pdfViewer.rescale(1.20, true, [0,0]);
34   });
35
36   $('#minus-btn').click(function (){
37     pdfViewer.rescale(0.80, true, [0,0]);
38   });
39
40   // detect if the PDF viewer wants to show an outline
41   // at all
42   if ($(pdfViewer.sidebar).hasClass('opened')) {
43     var body = $('body');
44     // if the screen is less than 64em wide, hide the outline
45     if (parseInt($(body.width()).toEm({scope: body})) < 64) {
46       $(pdfViewer.sidebar).removeClass('opened');
47     }
48   }
49
50   $('#outline-btn').click(function() {
51     $(pdfViewer.sidebar).toggleClass('opened');
52     // rescale the PDF to fit the available space
53     rescalePdf(pdfViewer, parseInt(noteFrame.width));
54   });
55
56   $('#scroll-to').change(function() {
57     page = parseInt($(this).val());
58     pdfViewer.scroll_to(page, [0,0]);
59   });
60
61   // rescale the PDF to fit the available space
62   rescalePdf(pdfViewer, parseInt(noteFrame.width));
63 }
64
65 $(function() {
66   $("#thank-button").click(function() {
67     event.preventDefault();
68
69     // increment number in page right away
70     var thankNumber = $("#thank-number");
71     thankNumber.text(parseInt(thankNumber.text()) + 1);
72
73     // disable thank button so it can't
74     // be pressed again
75     $(this).hide();
76     $('#thank-button-disabled').show();
77     $(this).unbind('click');
78
79     // tell server that somebody thanked
80     // this note
81     $.ajax({
82       url: note_thank_url,
83       dataType: "json",
84       type: 'POST'
85     });
86   });
87 });