##// END OF EJS Templates
Refactored image preview code
neko259 -
r1081:6ec3505c default
parent child Browse files
Show More
@@ -38,11 +38,15 b' function addImgPreview() {'
38 var thumb_id = 'full' + el.find('img').attr('alt');
38 var thumb_id = 'full' + el.find('img').attr('alt');
39
39
40 if(!$('#'+thumb_id).length) {
40 if(!$('#'+thumb_id).length) {
41 var img_w = el.find('img').attr('data-width');
41 var imgElement= el.find('img');
42 var img_h = el.find('img').attr('data-height');
42
43 var img_w = imgElement.attr('data-width');
44 var img_h = imgElement.attr('data-height');
43
45
44 var win_w = $(window).width();
46 var win = $(window);
45 var win_h = $(window).height();
47
48 var win_w = win.width();
49 var win_h = win.height();
46 //new image size
50 //new image size
47 if (img_w > win_w) {
51 if (img_w > win_w) {
48 img_h = img_h * (win_w/img_w) - margin;
52 img_h = img_h * (win_w/img_w) - margin;
@@ -54,8 +58,8 b' function addImgPreview() {'
54 }
58 }
55
59
56 var img_pv = new Image();
60 var img_pv = new Image();
57 $(img_pv)
61 var newImage = $(img_pv);
58 .addClass('img-full')
62 newImage.addClass('img-full')
59 .attr('id', thumb_id)
63 .attr('id', thumb_id)
60 .attr('src', $(el).attr('href'))
64 .attr('src', $(el).attr('href'))
61 .appendTo($(el))
65 .appendTo($(el))
@@ -69,16 +73,15 b' function addImgPreview() {'
69 .mousewheel(function(event, delta) {
73 .mousewheel(function(event, delta) {
70 var cx = event.originalEvent.clientX,
74 var cx = event.originalEvent.clientX,
71 cy = event.originalEvent.clientY,
75 cy = event.originalEvent.clientY,
72 i_w = parseFloat($(img_pv).width()),
76 i_w = parseFloat(newImage.width()),
73 i_h = parseFloat($(img_pv).height()),
77 i_h = parseFloat(newImage.height()),
74 newIW = i_w * (delta > 0 ? 1.25 : 0.8),
78 newIW = i_w * (delta > 0 ? 1.25 : 0.8),
75 newIH = i_h * (delta > 0 ? 1.25 : 0.8);
79 newIH = i_h * (delta > 0 ? 1.25 : 0.8);
76
80
77 $(img_pv).width(newIW);
81 newImage.width(newIW);
78 $(img_pv).height(newIH);
82 newImage.height(newIH);
79 //set position
83 //set position
80 $(img_pv)
84 newImage.css({
81 .css({
82 left: parseInt(cx - (newIW/i_w) * (cx - parseInt($(img_pv).position().left, 10)), 10),
85 left: parseInt(cx - (newIW/i_w) * (cx - parseInt($(img_pv).position().left, 10)), 10),
83 top: parseInt(cy - (newIH/i_h) * (cy - parseInt($(img_pv).position().top, 10)), 10)
86 top: parseInt(cy - (newIH/i_h) * (cy - parseInt($(img_pv).position().top, 10)), 10)
84 });
87 });
@@ -89,11 +92,10 b' function addImgPreview() {'
89 addClasses: false,
92 addClasses: false,
90 stack: '.img-full'
93 stack: '.img-full'
91 })
94 })
92 }
95 } else {
93 else {
94 $('#'+thumb_id).remove();
96 $('#'+thumb_id).remove();
95 }
97 }
96 //prevent default
98 //prevent default
97 return false;
99 return false;
98 });
100 });
99 } No newline at end of file
101 }
General Comments 0
You need to be logged in to leave comments. Login now