Merge pull request #506 from troolee/fix/460

fix #460: fix cellWidth method
This commit is contained in:
Pavel Reznikov 2016-08-16 22:03:26 -07:00 committed by GitHub
commit 703c52dc59
5 changed files with 30 additions and 15 deletions

5
dist/gridstack.js vendored
View file

@ -1043,7 +1043,7 @@
var o = $(this);
self.grid.cleanNodes();
self.grid.beginUpdate(node);
cellWidth = Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
cellWidth = self.cellWidth();
var strictCellHeight = Math.ceil(o.outerHeight() / o.attr('data-gs-height'));
cellHeight = self.container.height() / parseInt(self.container.attr('data-gs-current-height'));
self.placeholder
@ -1494,8 +1494,7 @@
};
GridStack.prototype.cellWidth = function() {
var o = this.container.children('.' + this.opts.itemClass).first();
return Math.ceil(o.outerWidth() / parseInt(o.attr('data-gs-width'), 10));
return Math.round(this.container.outerWidth() / this.opts.width);
};
GridStack.prototype.getCellFromPixel = function(position, useOffset) {

14
dist/gridstack.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -220,14 +220,27 @@ describe('gridstack', function() {
afterEach(function() {
document.body.removeChild(document.getElementsByClassName('grid-stack')[0]);
});
it('should return 96.', function() {
it('should return 1/12th of container width.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10
verticalMargin: 10,
width: 12
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
expect(grid.cellWidth()).toBe(96);
var res = Math.round($('.grid-stack').outerWidth() / 12);
expect(grid.cellWidth()).toBe(res);
});
it('should return 1/10th of container width.', function() {
var options = {
cellHeight: 80,
verticalMargin: 10,
width: 10
};
$('.grid-stack').gridstack(options);
var grid = $('.grid-stack').data('gridstack');
var res = Math.round($('.grid-stack').outerWidth() / 10);
expect(grid.cellWidth()).toBe(res);
});
});

View file

@ -1043,7 +1043,7 @@
var o = $(this);
self.grid.cleanNodes();
self.grid.beginUpdate(node);
cellWidth = Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
cellWidth = self.cellWidth();
var strictCellHeight = Math.ceil(o.outerHeight() / o.attr('data-gs-height'));
cellHeight = self.container.height() / parseInt(self.container.attr('data-gs-current-height'));
self.placeholder
@ -1494,8 +1494,7 @@
};
GridStack.prototype.cellWidth = function() {
var o = this.container.children('.' + this.opts.itemClass).first();
return Math.ceil(o.outerWidth() / parseInt(o.attr('data-gs-width'), 10));
return Math.round(this.container.outerWidth() / this.opts.width);
};
GridStack.prototype.getCellFromPixel = function(position, useOffset) {