Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/gridstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@

GridStack.prototype.cellWidth = function() {
var o = this.container.children('.' + this.opts.itemClass).first();
return Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
return Math.ceil(o.outerWidth() / parseInt(o.attr('data-gs-width'), 10));
};

GridStack.prototype.getCellFromPixel = function(position, useOffset) {
Expand Down
2 changes: 1 addition & 1 deletion dist/gridstack.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gridstack.min.map

Large diffs are not rendered by default.

243 changes: 242 additions & 1 deletion spec/gridstack-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ describe('gridstack', function() {

var e;
var w;
var gridstackHTML =
'<div class="grid-stack">' +
' <div class="grid-stack-item"' +
' data-gs-x="0" data-gs-y="0"' +
' data-gs-width="4" data-gs-height="2">' +
' <div class="grid-stack-item-content"></div>' +
' </div>' +
' <div class="grid-stack-item"' +
' data-gs-x="4" data-gs-y="0"' +
' data-gs-width="4" data-gs-height="4">' +
' <div class="grid-stack-item-content"></div>' +
' </div>' +
'</div>';

beforeEach(function() {
w = window;
Expand Down Expand Up @@ -87,6 +100,234 @@ describe('gridstack', function() {

});

describe('grid.setAnimation', function() {
beforeEach(function() {
document.body.insertAdjacentHTML(
'afterbegin', gridstackHTML);
});
afterEach(function() {
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
});
it('should add class grid-stack-animate to the container.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
};
$('.grid-stack').gridstack(options);
$('.grid-stack').removeClass('grid-stack-animate');
var grid = $('.grid-stack').data('gridstack');
grid.setAnimation(true);
expect($('.grid-stack').hasClass('grid-stack-animate')).toBe(true);
});
it('should remove class grid-stack-animate from the container.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
};
$('.grid-stack').gridstack(options);
$('.grid-stack').addClass('grid-stack-animate');
var grid = $('.grid-stack').data('gridstack');
grid.setAnimation(false);
expect($('.grid-stack').hasClass('grid-stack-animate')).toBe(false);
});
});

describe('grid._setStaticClass', function() {
beforeEach(function() {
document.body.insertAdjacentHTML(
'afterbegin', gridstackHTML);
});
afterEach(function() {
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
});
it('should add class grid-stack-static to the container.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10,
staticGrid: true
};
$('.grid-stack').gridstack(options);
$('.grid-stack').removeClass('grid-stack-static');
var grid = $('.grid-stack').data('gridstack');
grid._setStaticClass();
expect($('.grid-stack').hasClass('grid-stack-static')).toBe(true);
});
it('should remove class grid-stack-static from the container.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10,
staticGrid: false
};
$('.grid-stack').gridstack(options);
$('.grid-stack').addClass('grid-stack-static');
var grid = $('.grid-stack').data('gridstack');
grid._setStaticClass();
expect($('.grid-stack').hasClass('grid-stack-static')).toBe(false);
});
});

});
describe('grid.getCellFromPixel', function() {
beforeEach(function() {
document.body.insertAdjacentHTML(
'afterbegin', gridstackHTML);
});
afterEach(function() {
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
});
it('should return {x: 2, y: 1}.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
var pixel = {top: 100, left: 72};
var cell = grid.getCellFromPixel(pixel);
expect(cell.x).toBe(2);
expect(cell.y).toBe(1);
});
it('should return {x: 2, y: 1}.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
var pixel = {top: 100, left: 72};
var cell = grid.getCellFromPixel(pixel, false);
expect(cell.x).toBe(2);
expect(cell.y).toBe(1);
});
it('should return {x: 2, y: 1}.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
var pixel = {top: 100, left: 72};
var cell = grid.getCellFromPixel(pixel, true);
expect(cell.x).toBe(2);
expect(cell.y).toBe(1);
});
});

describe('grid.cellWidth', function() {
beforeEach(function() {
document.body.insertAdjacentHTML(
'afterbegin', gridstackHTML);
});
afterEach(function() {
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
});
it('should return 96.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
expect(grid.cellWidth()).toBe(96);
});
});

describe('grid.minWidth', function() {
beforeEach(function() {
document.body.insertAdjacentHTML(
'afterbegin', gridstackHTML);
});
afterEach(function() {
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
});
it('should set data-gs-min-width to 2.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
var items = $('.grid-stack-item');
for (var i = 0; i < items.length; i++) {
grid.minWidth(items[i], 2);
}
for (var j = 0; j < items.length; j++) {
expect(parseInt($(items[j]).attr('data-gs-min-width'), 10)).toBe(2);
}
});
});

describe('grid.maxWidth', function() {
beforeEach(function() {
document.body.insertAdjacentHTML(
'afterbegin', gridstackHTML);
});
afterEach(function() {
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
});
it('should set data-gs-min-width to 2.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
var items = $('.grid-stack-item');
for (var i = 0; i < items.length; i++) {
grid.maxWidth(items[i], 2);
}
for (var j = 0; j < items.length; j++) {
expect(parseInt($(items[j]).attr('data-gs-max-width'), 10)).toBe(2);
}
});
});

describe('grid.minHeight', function() {
beforeEach(function() {
document.body.insertAdjacentHTML(
'afterbegin', gridstackHTML);
});
afterEach(function() {
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
});
it('should set data-gs-min-height to 2.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
var items = $('.grid-stack-item');
for (var i = 0; i < items.length; i++) {
grid.minHeight(items[i], 2);
}
for (var j = 0; j < items.length; j++) {
expect(parseInt($(items[j]).attr('data-gs-min-height'), 10)).toBe(2);
}
});
});

describe('grid.maxHeight', function() {
beforeEach(function() {
document.body.insertAdjacentHTML(
'afterbegin', gridstackHTML);
});
afterEach(function() {
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
});
it('should set data-gs-min-height to 2.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
var items = $('.grid-stack-item');
for (var i = 0; i < items.length; i++) {
grid.maxHeight(items[i], 2);
}
for (var j = 0; j < items.length; j++) {
expect(parseInt($(items[j]).attr('data-gs-max-height'), 10)).toBe(2);
}
});
});
});
2 changes: 1 addition & 1 deletion src/gridstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@

GridStack.prototype.cellWidth = function() {
var o = this.container.children('.' + this.opts.itemClass).first();
return Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
return Math.ceil(o.outerWidth() / parseInt(o.attr('data-gs-width'), 10));
};

GridStack.prototype.getCellFromPixel = function(position, useOffset) {
Expand Down