Verified Commit dee01014 authored by Luc Didry's avatar Luc Didry
Browse files

[gallery] Fix #99 — Use JS to find images width/heigth if not provided

parent 6cdcd9a8
......@@ -214,6 +214,26 @@ function addAlert(e) {
].join(''));
}
function appendToGallery(url, width, height) {
$('.gallery').append(
[
'<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">',
' <a href="', url, '" itemprop="contentUrl" data-size="', width, 'x', height, '">',
' <img src="', url, '?width=275" itemprop="thumbnail" alt="" class="img-responsive"/>',
' </a>',
'</figure>'
].join('')
);
}
function nextOrInitGallery(keys) {
if (keys.length > 0) {
addElement(keys);
} else {
initPhotoSwipeFromDOM('.gallery');
}
}
function addElement(keys) {
element = keys.shift();
if (!element.match('xcf')) {
......@@ -223,29 +243,29 @@ function addElement(keys) {
dataType: 'json',
success: function(data, textStatus, jqXHR) {
if (data.success) {
$('.gallery').append(
[
'<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">',
' <a href="', absUrl+element, '" itemprop="contentUrl" data-size="', data.data.width, 'x', data.data.height, '">',
' <img src="', absUrl+element, '?width=275" itemprop="thumbnail" alt="" class="img-responsive"/>',
' </a>',
'</figure>'
].join('')
);
if (data.data.width && data.data.height) {
appendToGallery(absUrl+element, data.data.width, data.data.height);
nextOrInitGallery(keys);
} else {
var img = new Image();
img.onload = function(){
appendToGallery(absUrl+element, img.width, img.height);
nextOrInitGallery(keys);
}
img.src = absUrl+element;
}
} else {
addAlert(data.msg);
nextOrInitGallery(keys);
}
},
complete: function() {
if (keys.length > 0) {
addElement(keys);
} else {
initPhotoSwipeFromDOM('.gallery');
}
error: function(jqXHR, textStatus, errorThrown) {
nextOrInitGallery(keys);
}
});
}
}
$(document).ready(function() {
var key = window.location.hash.substring(1); // Get key
// First, strip everything after the equal sign (=) which signals end of base64 string.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment