Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Adding fixes #26

Merged
merged 3 commits into from Dec 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions .jshintrc
Expand Up @@ -8,6 +8,7 @@
"latedef": false,
"newcap": true,
"undef": true,
"camelcase": true,
"globals": {
"Modernizr": true
}
Expand Down
37 changes: 34 additions & 3 deletions jquery.mosaicflow.js
Expand Up @@ -59,7 +59,7 @@
Mosaicflow.prototype = {
init: function() {
this.__uid = cnt++;
this.__uid_item_counter = 0;
this.__uidItemCounter = 0;
this.items = this.container.find(this.options.itemSelector);
this.columns = $([]);
this.columnsHeights = [];
Expand Down Expand Up @@ -206,6 +206,7 @@
var height = 0;

if (this.autoCalculation) {

// Get height of elm
elm.css({
position: 'static',
Expand All @@ -215,6 +216,19 @@

height = elm.outerHeight();

var inlineImages = elm.find('img');
if (inlineImages.length !== 0) {

inlineImages.each(function() {
var image = $(this);
var imageSizes = getImageSizes(image);
var actualHeight = (image.width()*imageSizes.height)/imageSizes.width;

height += actualHeight;
});

}

elm.detach().css({
position: 'static',
visibility: 'visible'
Expand Down Expand Up @@ -304,10 +318,10 @@

generateUniqueId: function() {
// Increment the counter
this.__uid_item_counter++;
this.__uidItemCounter++;

// Return an unique ID
return 'mosaic-' + this.__uid + '-itemid-' + this.__uid_item_counter;
return 'mosaic-' + this.__uid + '-itemid-' + this.__uidItemCounter;
}
};

Expand All @@ -324,6 +338,23 @@
return options;
}

function getImageSizes(image) {
var sizes = {};

sizes.height = parseInt(image.attr('height'), 10);
sizes.width = parseInt(image.attr('width'), 10);

if (sizes.height === 0 || sizes.width === 0) {
var utilImage = new Image();
utilImage.src = image.attr('src');

sizes.width = utilImage.width;
sizes.height = utilImage.height;
}

return sizes;
}

// Auto init
$(function() { $('.mosaicflow').mosaicflow(); });

Expand Down