Show More
@@ -36,6 +36,37 b" var FULL_IMG_CLASS = 'post-image-full';" | |||||
36 | var ATTR_SCALE = 'scale'; |
|
36 | var ATTR_SCALE = 'scale'; | |
37 |
|
37 | |||
38 |
|
38 | |||
|
39 | // Init image viewer | |||
|
40 | var viewerName = $('body').attr('data-image-viewer'); | |||
|
41 | var viewer = ImageViewer(); | |||
|
42 | for (var i = 0; i < IMAGE_VIEWERS.length; i++) { | |||
|
43 | var item = IMAGE_VIEWERS[i]; | |||
|
44 | if (item[0] === viewerName) { | |||
|
45 | viewer = item[1]; | |||
|
46 | break; | |||
|
47 | } | |||
|
48 | } | |||
|
49 | ||||
|
50 | ||||
|
51 | function getFullImageWidth(previewImage) { | |||
|
52 | var full_img_w = previewImage.attr('data-width'); | |||
|
53 | if (full_img_w == null) { | |||
|
54 | full_img_w = previewImage[0].naturalWidth; | |||
|
55 | } | |||
|
56 | ||||
|
57 | return full_img_w; | |||
|
58 | } | |||
|
59 | ||||
|
60 | function getFullImageHeight(previewImage) { | |||
|
61 | var full_img_h = previewImage.attr('data-height'); | |||
|
62 | if (full_img_h == null) { | |||
|
63 | full_img_h = previewImage[0].naturalHeight; | |||
|
64 | } | |||
|
65 | ||||
|
66 | return full_img_h; | |||
|
67 | } | |||
|
68 | ||||
|
69 | ||||
39 | function ImageViewer() {} |
|
70 | function ImageViewer() {} | |
40 | ImageViewer.prototype.view = function (post) {}; |
|
71 | ImageViewer.prototype.view = function (post) {}; | |
41 |
|
72 | |||
@@ -48,8 +79,8 b' SimpleImageViewer.prototype.view = funct' | |||||
48 | if (images.length == 1) { |
|
79 | if (images.length == 1) { | |
49 | var thumb = images.first(); |
|
80 | var thumb = images.first(); | |
50 |
|
81 | |||
51 |
var width = thumb |
|
82 | var width = getFullImageWidth(thumb); | |
52 | var height = thumb.attr('data-height'); |
|
83 | var height = getFullImageHeight(thumb); | |
53 |
|
84 | |||
54 | if (width == null || height == null) { |
|
85 | if (width == null || height == null) { | |
55 | width = '100%'; |
|
86 | width = '100%'; | |
@@ -76,10 +107,10 b' PopupImageViewer.prototype.view = functi' | |||||
76 |
|
107 | |||
77 | var existingPopups = $('#' + thumb_id); |
|
108 | var existingPopups = $('#' + thumb_id); | |
78 | if (!existingPopups.length) { |
|
109 | if (!existingPopups.length) { | |
79 | var imgElement= el.find('img'); |
|
110 | var imgElement = el.find('img'); | |
80 |
|
111 | |||
81 |
var full_img_w = imgElement |
|
112 | var full_img_w = getFullImageWidth(imgElement); | |
82 |
var full_img_h = imgElement |
|
113 | var full_img_h = getFullImageHeight(imgElement); | |
83 |
|
114 | |||
84 | var win = $(window); |
|
115 | var win = $(window); | |
85 |
|
116 | |||
@@ -156,16 +187,6 b' PopupImageViewer.prototype.view = functi' | |||||
156 | }; |
|
187 | }; | |
157 |
|
188 | |||
158 | function addImgPreview() { |
|
189 | function addImgPreview() { | |
159 | var viewerName = $('body').attr('data-image-viewer'); |
|
|||
160 | var viewer = ImageViewer(); |
|
|||
161 | for (var i = 0; i < IMAGE_VIEWERS.length; i++) { |
|
|||
162 | var item = IMAGE_VIEWERS[i]; |
|
|||
163 | if (item[0] === viewerName) { |
|
|||
164 | viewer = item[1]; |
|
|||
165 | break; |
|
|||
166 | } |
|
|||
167 | } |
|
|||
168 |
|
||||
169 | //keybind |
|
190 | //keybind | |
170 | $(document).on('keyup.removepic', function(e) { |
|
191 | $(document).on('keyup.removepic', function(e) { | |
171 | if(e.which === 27) { |
|
192 | if(e.which === 27) { |
@@ -20,7 +20,7 b' function mkPreview(cln, html) {' | |||||
20 |
|
20 | |||
21 | highlightCode($(cln)); |
|
21 | highlightCode($(cln)); | |
22 | addRefLinkPreview(cln); |
|
22 | addRefLinkPreview(cln); | |
23 |
} |
|
23 | } | |
24 |
|
24 | |||
25 | function isElementInViewport (el) { |
|
25 | function isElementInViewport (el) { | |
26 | //special bonus for those using jQuery |
|
26 | //special bonus for those using jQuery |
General Comments 0
You need to be logged in to leave comments.
Login now