Skip to content

Added new option (minHeight) to have a different height to width #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions jquery.nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ if (!Object.keys) {
$.Nested.settings = {
selector: '.box',
minWidth: 50,
minHeight: 50,
minColumns: 1,
gutter: 1,
resizeToFit: true, // will resize block bigger than the gap
Expand Down Expand Up @@ -112,6 +113,7 @@ if (!Object.keys) {

// build columns
var minWidth = this.options.minWidth;
var minHeight = this.options.minHeight;
var gutter = this.options.gutter;
var display = "block";

Expand All @@ -124,7 +126,7 @@ if (!Object.keys) {
var y = (dim[1] == "a") ? 1 : parseFloat(dim[1]);

var currWidth = minWidth * x + gutter * (x - 1);
var currHeight = minWidth * y + gutter * (y - 1);
var currHeight = minHeight * y + gutter * (y - 1);

$(this).css({
'display': display,
Expand All @@ -133,7 +135,7 @@ if (!Object.keys) {
'height': currHeight,
'top': $(this).offset().top,
'left': $(this).offset().left
}).removeClass('nested-moved').attr('data-box', self.idCounter).attr('data-width', currWidth);
}).removeClass('nested-moved').attr('data-box', self.idCounter).attr('data-width', currWidth).attr('data-height', currHeight);

self.idCounter++;

Expand Down Expand Up @@ -170,7 +172,7 @@ if (!Object.keys) {
var height = 0;
var t = parseInt(el['y']) - this.box.offset().top;
var l = parseInt(el['x']) - this.box.offset().left;
for (var h = 0; h < el['height']; h += (this.options.minWidth + this.options.gutter)) {
for (var h = 0; h < el['height']; h += (this.options.minHeight + this.options.gutter)) {
for (var w = 0; w < el['width']; w += (this.options.minWidth + this.options.gutter)) {
var x = l + w;
var y = t + h;
Expand Down Expand Up @@ -223,7 +225,7 @@ if (!Object.keys) {
if (!box.y) box.y = y;
if (!box.x) box.x = x;
if (!box.w) box.w = 0;
if (!box.h) box.h = self.options.minWidth;
if (!box.h) box.h = self.options.minHeight;
box.w += (box.w) ? (self.options.minWidth + self.options.gutter) : self.options.minWidth;

var addonHeight = 0;
Expand All @@ -235,7 +237,7 @@ if (!Object.keys) {
} else break;
}

box.h + (parseInt(addonHeight) / (self.options.minWidth + self.options.gutter) == rowsLeft) ? 0 : parseInt(addonHeight);
box.h + (parseInt(addonHeight) / (self.options.minHeight + self.options.gutter) == rowsLeft) ? 0 : parseInt(addonHeight);
box.ready = true;

} else if (box.ready) {
Expand Down Expand Up @@ -280,7 +282,7 @@ if (!Object.keys) {

// Calculate row and col
var col = Math.ceil(width / (this.options.minWidth + this.options.gutter));
var row = Math.ceil(height / (this.options.minWidth + this.options.gutter));
var row = Math.ceil(height / (this.options.minHeight + this.options.gutter));

// lock widest box to match minColumns
if (col > this.options.minColumns) {
Expand All @@ -300,7 +302,7 @@ if (!Object.keys) {
for (var column = 0; column < (this.columns - col); column++) {

// Add default empty matrix, used to calculate and update matrix for each box
matrixY = gridy * (this.options.minWidth + this.options.gutter);
matrixY = gridy * (this.options.minHeight + this.options.gutter);
this._addMatrixRow(matrixY);

var fits = true;
Expand Down Expand Up @@ -334,7 +336,7 @@ if (!Object.keys) {
}

// Push to elements array
this._pushItem($box, column * (this.options.minWidth + this.options.gutter), gridy * (this.options.minWidth + this.options.gutter), width, height, col, row, direction);
this._pushItem($box, column * (this.options.minWidth + this.options.gutter), gridy * (this.options.minHeight + this.options.gutter), width, height, col, row, direction);
return;
}
}
Expand All @@ -347,8 +349,8 @@ if (!Object.keys) {
if (method == "prepend") {
this.elements.unshift({
$el: $el,
x: x + this.box.offset().left,
y: y + this.box.offset().top,
x: x,// + this.box.offset().left, changed as it was causing some odd positioning issue in our setup
y: y,// + this.box.offset().top, changed as it was causing some odd positioning issue in our setup
width: w,
height: h,
cols: cols,
Expand All @@ -357,12 +359,12 @@ if (!Object.keys) {
} else {
this.elements.push({
$el: $el,
x: x + this.box.offset().left,
y: y + this.box.offset().top,
x: x,// + this.box.offset().left, changed as it was causing some odd positioning issue in our setup
y: y,// + this.box.offset().top, changed as it was causing some odd positioning issue in our setup
width: w,
height: h,
cols: cols,
rows: rows,
rows: rows
});
}
},
Expand All @@ -371,7 +373,7 @@ if (!Object.keys) {
var self = this;
$.each($els, function (index, value) {
// set maxHeight
var colY = (value['y'] + value['height']) - self.box.offset().top;
var colY = (value['y'] + value['height']);// - self.box.offset().top; changed as it was causing some odd positioning issue in our setup
if (colY > self.maxHeight) {
self.maxHeight = colY;
}
Expand Down Expand Up @@ -401,7 +403,7 @@ if (!Object.keys) {
$currLeft = $(value['$el']).offset().left;
$currTop = $(value['$el']).offset().top;
$currWidth = $(value['$el']).width();
$currHeight = $(value['$el']).width();
$currHeight = $(value['$el']).height();


value['$el'].attr('data-y', $currTop).attr('data-x', $currLeft);
Expand Down