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 @@ -6,71 +6,64 @@ function addImgPreview() { } }); - $('.thumb').each(function() { - $(this).on('click', function() { - var el = $(this); - 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 win_w = $(window).width(); - var win_h = $(window).height(); + $('body').on('click', '.thumb', function() { + var el = $(this); + var thumb_id = 'full' + el.find('img').attr('alt'); - //new image size - if (img_w > win_w) { - img_h = img_h * (win_w/img_w); - img_w = win_w; - } - if (img_h > win_h) { - img_w = img_w * (win_h/img_h); - img_h = win_h; - } - - var img_pv = new Image(); + if(!$('#'+thumb_id).length) { + var img_w = el.find('img').attr('data-width'); + var img_h = el.find('img').attr('data-height'); - $(img_pv) - .addClass('img-full') - .attr('id', thumb_id) - .attr('src', $(el).attr('href')) - .appendTo($(el)) - .css({ - 'width': img_w, - 'height': img_h, - 'left': (win_w - img_w) / 2, - 'top': ((win_h - img_h) / 2) - }) - - //scaling preview - .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()), - 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); - - //set position - $(img_pv) - .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) - }); - - return false; - } - ).draggable() + var win_w = $(window).width(); + var win_h = $(window).height(); + //new image size + if (img_w > win_w) { + img_h = img_h * (win_w/img_w); + img_w = win_w; } - else { - $('#'+thumb_id).remove(); + if (img_h > win_h) { + img_w = img_w * (win_h/img_h); + img_h = win_h; } - //prevent default - return false; - }); + var img_pv = new Image(); + $(img_pv) + .addClass('img-full') + .attr('id', thumb_id) + .attr('src', $(el).attr('href')) + .appendTo($(el)) + .css({ + 'width': img_w, + 'height': img_h, + 'left': (win_w - img_w) / 2, + 'top': ((win_h - img_h) / 2) + }) + //scaling preview + .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()), + 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); + //set position + $(img_pv) + .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) + }); + + return false; + } + ).draggable() + } + else { + $('#'+thumb_id).remove(); + } + //prevent default + return false; }); } \ No newline at end of file diff --git a/boards/static/js/thread.js b/boards/static/js/thread.js --- a/boards/static/js/thread.js +++ b/boards/static/js/thread.js @@ -49,6 +49,9 @@ function tab_handler(ev) $('#posts').replaceWith(table_dom); break; } + + //TODO: временно + addImgPreview(); } function make_normal_dom() @@ -70,8 +73,6 @@ function make_table_dom() ); } ); - //TODO: временно - addImgPreview(); } function moveCaretToEnd(el) {