1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
$('.site-content').on('click', '.manage-article', function(e){
e.preventDefault();
e.stopPropagation();
var $a = $(this);
var $url = $a.attr('href');
$.ajax($url)
.done(function(data, text, jqxhr){
$a.parents('.article').replaceWith($(data)).fadeOut(500).fadeIn(500);
var $carousel_id = $a.parents('.dropdown').siblings('.slideshow-carousel').children().attr('id');
$("#" + $carousel_id).each(function(index, item) {
var containerWidth = 0;
var containerHeight = 0;
if ($(window).width() < 640)
{
containerWidth = $(item).width();
containerHeight = $(item).width() / 2;
}
else
{
containerWidth = 180;
containerHeight = 180;
}
$(item).find("img").each(function(index, img) {
// Cette fonction est censée me renvoyer un tableau avec les dimensions de l'image
var imgDimensions[] = getMeta($(img).attr('src'));
// imgDimensions[0] me renverrait la largeur et imgDimensions[1] me renverrait la hauteur
var pictureWidth = imgDimensions[0]; // renvoie 0
var pictureHeight = imgDimensions[1]; // renvoie 0
var ratioWidth = containerWidth / pictureWidth;
var ratioHeight = containerHeight / pictureHeight;
var ratio = ratioWidth;
if (ratioWidth > ratioHeight)
{
ratio = ratioHeight;
}
var thumbWidth = pictureWidth * ratio;
var thumbHeight = pictureHeight * ratio;
$(img).css({
'width': thumbWidth + 'px',
'height': thumbHeight + 'px'
});
}),
$(item).owlCarousel({
autoplay: true,
autoplayTimeout: 10000,
loop: true,
responsive:{
0:{
items: 1
},
640:{
items: 1
},
769:{
items: 1
},
1025:{
items: 1
}
}
});
});
})
.fail(function(jqxhr){
alert(jqxhr.responseText);
})
.always(function(){
$a.text('Actions');
});
});
});
function getMeta(url){
var img = new Image();
img.addEventListener("load", function(){
alert( "width: " + this.naturalWidth +' et Height : '+ this.naturalHeight );
});
img.src = url;
} |
Partager