diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-05-04 09:48:27 -0700 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-05-04 09:48:27 -0700 |
commit | 247f5d615539784c46b5c7c5b35b6ee348e04151 (patch) | |
tree | 6744bd1584ad1239417e4c8e148f98d1d27909eb /view.coffee |
Diffstat (limited to 'view.coffee')
-rw-r--r-- | view.coffee | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/view.coffee b/view.coffee new file mode 100644 index 0000000..8987630 --- /dev/null +++ b/view.coffee @@ -0,0 +1,54 @@ +$ = jQuery + +toReplace = 0 +replaced = 0 + +class imageReplacer + constructor: (@orig, @src) -> + @replacement = new Image() + @replacement.onload = @replace + @replacement.src = @src + toReplace++ + @updateText() + replace: => + $(@orig).replaceWith(@replacement) + replaced++ + @updateText() + updateText: => + if ((toReplace-replaced)>0) + $('.loading').text('Please be patient, loading high-quality images ('+replaced+'/'+toReplace+')') + else + $('.loading').text('') + +loadHighRes = -> + images = $('img') + for image in images + new imageReplacer(image, image.src.replace('.small.', '.')) + +zoomIn = -> + width = $('.paper').width() + $('.paper').width(width*1.1) + +zoomOut = -> + width = $('.paper').width() + $('.paper').width(width*(1/1.1)) + +fitPageHeight = -> + page_height = $('.paper img').height() + page_width = $('.paper img').width() + window_height = $(window).height() - $('.menu').height() + # We now want to set page_height=window_height, but through page_width + $('.paper').width(window_height*(2*page_width/page_height)) + +updatePageNumber = -> + + +$ -> + menu = $('.menu').text('') + $('<button>').text("Zoom Out").click(zoomOut).appendTo(menu) + $('<button>').text("Zoom In").click(zoomIn).appendTo(menu) + $('<button>').text("Fit Page Height").click(fitPageHeight).appendTo(menu) + $('<div>').addClass('loading').appendTo(menu) + $('.spacer').height(menu.height()) + $('.paper').scroll(updatePageNumber) + loadHighRes() |