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 @@ -38,11 +38,15 @@ function addImgPreview() { var thumb_id = 'full' + el.find('img').attr('alt'); if(!$('#'+thumb_id).length) { - var img_w = el.find('img').attr('data-width'); - var img_h = el.find('img').attr('data-height'); + var imgElement= el.find('img'); + + var img_w = imgElement.attr('data-width'); + var img_h = imgElement.attr('data-height'); - var win_w = $(window).width(); - var win_h = $(window).height(); + var win = $(window); + + var win_w = win.width(); + var win_h = win.height(); //new image size if (img_w > win_w) { img_h = img_h * (win_w/img_w) - margin; @@ -54,8 +58,8 @@ function addImgPreview() { } var img_pv = new Image(); - $(img_pv) - .addClass('img-full') + var newImage = $(img_pv); + newImage.addClass('img-full') .attr('id', thumb_id) .attr('src', $(el).attr('href')) .appendTo($(el)) @@ -69,16 +73,15 @@ function addImgPreview() { .mousewheel(function(event, delta) { var cx = event.originalEvent.clientX, cy = event.originalEvent.clientY, - i_w = parseFloat($(img_pv).width()), - i_h = parseFloat($(img_pv).height()), + i_w = parseFloat(newImage.width()), + i_h = parseFloat(newImage.height()), newIW = i_w * (delta > 0 ? 1.25 : 0.8), newIH = i_h * (delta > 0 ? 1.25 : 0.8); - $(img_pv).width(newIW); - $(img_pv).height(newIH); + newImage.width(newIW); + newImage.height(newIH); //set position - $(img_pv) - .css({ + newImage.css({ left: parseInt(cx - (newIW/i_w) * (cx - parseInt($(img_pv).position().left, 10)), 10), top: parseInt(cy - (newIH/i_h) * (cy - parseInt($(img_pv).position().top, 10)), 10) }); @@ -89,11 +92,10 @@ function addImgPreview() { addClasses: false, stack: '.img-full' }) - } - else { + } else { $('#'+thumb_id).remove(); } //prevent default return false; }); -} \ No newline at end of file +}