mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51:40 +09:00
Fix #1948 use naturalWidth/naturalHeight of original image tag, if possible, when loading PhotoSwipe
This commit is contained in:
parent
8b611e9d08
commit
4a08c67f67
1 changed files with 12 additions and 10 deletions
|
|
@ -1,12 +1,14 @@
|
|||
/* Modified version of a http://photoswipe.com/documentation/getting-started.html example. Modified by misol for rhymix */
|
||||
var getPSImageSize = function(src) {
|
||||
var testImg = new Image();
|
||||
testImg.src = src;
|
||||
|
||||
var getPSImageSize = function(el) {
|
||||
var size = new Array();
|
||||
size[0] = testImg.width;
|
||||
size[1] = testImg.height;
|
||||
|
||||
size[0] = el.naturalWidth ? el.naturalWidth : (el.width ? el.width : 0);
|
||||
size[1] = el.naturalHeight ? el.naturalHeight : (el.height ? el.height : 0);
|
||||
if (!size[0] || !size[1]) {
|
||||
var test = new Image();
|
||||
test.src = el.src;
|
||||
size[0] = test.naturalWidth ? test.naturalWidth : (test.width ? test.width : 0);
|
||||
size[1] = test.naturalHeight ? test.naturalHeight : (test.height ? test.height : 0);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
@ -38,11 +40,11 @@ var initPhotoSwipeFromDOM = function(gallerySelector) {
|
|||
imgEl = imgElements.get(i); // <img> element
|
||||
|
||||
// include only element nodes
|
||||
if(imgEl.nodeType !== 1 || !$(imgEl).attr('data-pswp-pid')) {
|
||||
if (imgEl.nodeType !== 1 || !imgEl.src || !$(imgEl).attr('data-pswp-pid')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
size = getPSImageSize($(imgEl).attr('src'));
|
||||
size = getPSImageSize(imgEl);
|
||||
|
||||
// create slide object
|
||||
item = {
|
||||
|
|
@ -256,4 +258,4 @@ var initPhotoSwipeFromDOM = function(gallerySelector) {
|
|||
|
||||
|
||||
// execute above function
|
||||
initPhotoSwipeFromDOM('.rhymix_content, .xe_content');
|
||||
initPhotoSwipeFromDOM('.rhymix_content, .xe_content');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue