merge with master

This commit is contained in:
Pavel Reznikov 2016-08-18 20:10:50 -07:00
commit 0b3b47cefe
6 changed files with 106 additions and 26 deletions

View file

@ -482,6 +482,7 @@ Changes
- add oneColumnModeClass option to grid.
- remove 768px CSS styles, moved to grid-stack-one-column-mode class.
- add max-width override on grid-stck-one-column-mode ([#462](https://github.com/troolee/gridstack.js/issues/462)).
- add internal function`isNodeChangedPosition`, minor optimization to move/drag.
#### v0.2.6 (2016-08-17)

23
dist/gridstack.js vendored
View file

@ -405,6 +405,9 @@
};
GridStackEngine.prototype.canMoveNode = function(node, x, y, width, height) {
if (!this.isNodeChangedPosition(node, x, y, width, height)) {
return false;
}
var hasLocked = Boolean(_.find(this.nodes, function(n) { return n.locked; }));
if (!this.height && !hasLocked) {
@ -460,7 +463,27 @@
return clone.getGridHeight() <= this.height;
};
GridStackEngine.prototype.isNodeChangedPosition = function(node, x, y, width, height) {
if (typeof x != 'number') { x = node.x; }
if (typeof y != 'number') { y = node.y; }
if (typeof width != 'number') { width = node.width; }
if (typeof height != 'number') { height = node.height; }
if (typeof node.maxWidth != 'undefined') { width = Math.min(width, node.maxWidth); }
if (typeof node.maxHeight != 'undefined') { height = Math.min(height, node.maxHeight); }
if (typeof node.minWidth != 'undefined') { width = Math.max(width, node.minWidth); }
if (typeof node.minHeight != 'undefined') { height = Math.max(height, node.minHeight); }
if (node.x == x && node.y == y && node.width == width && node.height == height) {
return false;
}
return true;
};
GridStackEngine.prototype.moveNode = function(node, x, y, width, height, noPack) {
if (!this.isNodeChangedPosition(node, x, y, width, height)) {
return node;
}
if (typeof x != 'number') { x = node.x; }
if (typeof y != 'number') { y = node.y; }
if (typeof width != 'number') { width = node.width; }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -14,7 +14,7 @@ describe('gridstack engine', function() {
beforeAll(function() {
engine = new GridStackUI.Engine(12);
})
});
it('should be setup properly', function() {
expect(engine.width).toEqual(12);
@ -29,7 +29,7 @@ describe('gridstack engine', function() {
beforeAll(function() {
engine = new GridStackUI.Engine(12);
})
});
it('should prepare a node', function() {
expect(engine._prepareNode({}, false)).toEqual(jasmine.objectContaining({x: 0, y: 0, width: 1, height: 1}));
@ -57,7 +57,7 @@ describe('gridstack engine', function() {
engine.nodes = [
engine._prepareNode({x: 3, y: 2, width: 3, height: 2})
];
})
});
it('should be true', function() {
expect(engine.isAreaEmpty(0, 0, 3, 2)).toEqual(true);
@ -112,7 +112,7 @@ describe('gridstack engine', function() {
var engine;
beforeAll(function() {
engine = new GridStackUI.Engine(12)
engine = new GridStackUI.Engine(12);
});
it('should work on not float grids', function() {
@ -130,7 +130,7 @@ describe('gridstack engine', function() {
var engine;
beforeAll(function() {
engine = new GridStackUI.Engine(12, null, true)
engine = new GridStackUI.Engine(12, null, true);
});
it('should work on float grids', function() {
@ -151,7 +151,7 @@ describe('gridstack engine', function() {
beforeEach(function() {
spy = {
callback: function() {}
}
};
spyOn(spy, 'callback');
engine = new GridStackUI.Engine(12, spy.callback, true);
@ -209,8 +209,8 @@ describe('gridstack engine', function() {
var engine;
var findNode = function(engine, id) {
return _.find(engine.nodes, function(i) { return i._id === id });
}
return _.find(engine.nodes, function(i) { return i._id === id; });
};
beforeEach(function() {
engine = new GridStackUI.Engine(12, null, false);
@ -275,4 +275,37 @@ describe('gridstack engine', function() {
});
});
});
describe('test isNodeChangedPosition', function() {
var engine;
beforeAll(function() {
engine = new GridStackUI.Engine(12);
});
it('should return true for changed x', function() {
var widget = { x: 1, y: 2, width: 3, height: 4 };
expect(engine.isNodeChangedPosition(widget, 2, 2)).toEqual(true);
});
it('should return true for changed y', function() {
var widget = { x: 1, y: 2, width: 3, height: 4 };
expect(engine.isNodeChangedPosition(widget, 1, 1)).toEqual(true);
});
it('should return true for changed width', function() {
var widget = { x: 1, y: 2, width: 3, height: 4 };
expect(engine.isNodeChangedPosition(widget, 2, 2, 4, 4)).toEqual(true);
});
it('should return true for changed height', function() {
var widget = { x: 1, y: 2, width: 3, height: 4 };
expect(engine.isNodeChangedPosition(widget, 1, 2, 3, 3)).toEqual(true);
});
it('should return false for unchanged position', function() {
var widget = { x: 1, y: 2, width: 3, height: 4 };
expect(engine.isNodeChangedPosition(widget, 1, 2, 3, 4)).toEqual(false);
});
});
});

View file

@ -405,6 +405,9 @@
};
GridStackEngine.prototype.canMoveNode = function(node, x, y, width, height) {
if (!this.isNodeChangedPosition(node, x, y, width, height)) {
return false;
}
var hasLocked = Boolean(_.find(this.nodes, function(n) { return n.locked; }));
if (!this.height && !hasLocked) {
@ -460,7 +463,27 @@
return clone.getGridHeight() <= this.height;
};
GridStackEngine.prototype.isNodeChangedPosition = function(node, x, y, width, height) {
if (typeof x != 'number') { x = node.x; }
if (typeof y != 'number') { y = node.y; }
if (typeof width != 'number') { width = node.width; }
if (typeof height != 'number') { height = node.height; }
if (typeof node.maxWidth != 'undefined') { width = Math.min(width, node.maxWidth); }
if (typeof node.maxHeight != 'undefined') { height = Math.min(height, node.maxHeight); }
if (typeof node.minWidth != 'undefined') { width = Math.max(width, node.minWidth); }
if (typeof node.minHeight != 'undefined') { height = Math.max(height, node.minHeight); }
if (node.x == x && node.y == y && node.width == width && node.height == height) {
return false;
}
return true;
};
GridStackEngine.prototype.moveNode = function(node, x, y, width, height, noPack) {
if (!this.isNodeChangedPosition(node, x, y, width, height)) {
return node;
}
if (typeof x != 'number') { x = node.x; }
if (typeof y != 'number') { y = node.y; }
if (typeof width != 'number') { width = node.width; }