# HG changeset patch # User neko259 # Date 2015-10-02 19:07:47 # Node ID 3a3fc639af52432676fa7fc040062eb2cdcac8c6 # Parent 4d767fbf75ddc3d6b842db17dc3398c70eb09d37 Fixed image popup margin in rare cases diff --git a/boards/static/js/image.js b/boards/static/js/image.js --- a/boards/static/js/image.js +++ b/boards/static/js/image.js @@ -23,6 +23,8 @@ for the JavaScript code in this page. */ +var IMAGE_POPUP_MARGIN = 10; + var IMAGE_VIEWERS = [ ['simple', new SimpleImageViewer()], @@ -69,8 +71,6 @@ SimpleImageViewer.prototype.view = funct function PopupImageViewer() {} PopupImageViewer.prototype.view = function (post) { - var margin = 20; //..change - var el = post; var thumb_id = 'full' + el.find('img').attr('alt'); @@ -89,11 +89,15 @@ PopupImageViewer.prototype.view = functi // New image size var w_scale = 1; var h_scale = 1; - if (full_img_w > win_w) { - w_scale = full_img_w / (win_w - margin); + + var freeWidth = win_w - 2 * IMAGE_POPUP_MARGIN; + var freeHeight = win_h - 2 * IMAGE_POPUP_MARGIN; + + if (full_img_w > freeWidth) { + w_scale = full_img_w / freeWidth; } - if (full_img_h > win_h) { - h_scale = full_img_h / (win_h - margin); + if (full_img_h > freeHeight) { + h_scale = full_img_h / freeHeight; } var scale = Math.max(w_scale, h_scale)