From: Charles Connell Date: Thu, 26 Dec 2013 16:20:40 +0000 (-0500) Subject: More rescaling action on PDF viewer X-Git-Tag: release-20150131~363 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=464dd42008e4e798aaaa4ee0810f6a60cb626b00;p=oweals%2Fkarmaworld.git More rescaling action on PDF viewer --- diff --git a/karmaworld/assets/js/note-detail.js b/karmaworld/assets/js/note-detail.js index 8a6cf5d..9dc0a78 100644 --- a/karmaworld/assets/js/note-detail.js +++ b/karmaworld/assets/js/note-detail.js @@ -12,8 +12,22 @@ function autoResize(id){ document.getElementById(id).width= (newwidth + 5) + "px"; } +function rescalePdf(viewer, frameWidth) { + var scaleBase = 750; + var outlineWidth = 250; + var pdfWidth = frameWidth; + + if ($(viewer.sidebar).hasClass('opened')){ + pdfWidth = pdfWidth - 250; + } + + var newPdfScale = pdfWidth / scaleBase; + viewer.rescale(newPdfScale); +} + function setupPdfViewer() { - var pdfViewer = document.getElementById("noteframe").contentWindow.pdf2htmlEX.defaultViewer; + var noteFrame = document.getElementById("noteframe") + var pdfViewer = noteFrame.contentWindow.pdf2htmlEX.defaultViewer; $('#plus-btn').click(function (){ pdfViewer.rescale(1.20, true, [0,0]); @@ -23,9 +37,11 @@ function setupPdfViewer() { pdfViewer.rescale(0.80, true, [0,0]); }); + // detect if the PDF viewer wants to show an outline + // at all if ($(pdfViewer.sidebar).hasClass('opened')) { - // only show outline on large screens var body = $('body'); + // if the screen is less than 64em wide, hide the outline if (parseInt($(body.width()).toEm({scope: body})) < 64) { $(pdfViewer.sidebar).removeClass('opened'); } @@ -33,12 +49,17 @@ function setupPdfViewer() { $('#outline-btn').click(function() { $(pdfViewer.sidebar).toggleClass('opened'); + // rescale the PDF to fit the available space + rescalePdf(pdfViewer, parseInt(noteFrame.width)); }); $('#scroll-to').change(function() { page = parseInt($(this).val()); pdfViewer.scroll_to(page, [0,0]); }); + + // rescale the PDF to fit the available space + rescalePdf(pdfViewer, parseInt(noteFrame.width)); } $(function() {