Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b3b47c

Browse files
committed
merge with master
2 parents 78f0073 + 67dc2dd commit 0b3b47c

File tree

6 files changed

+106
-26
lines changed

6 files changed

+106
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ Changes
482482
- add oneColumnModeClass option to grid.
483483
- remove 768px CSS styles, moved to grid-stack-one-column-mode class.
484484
- add max-width override on grid-stck-one-column-mode ([#462](https://github.com/troolee/gridstack.js/issues/462)).
485+
- add internal function`isNodeChangedPosition`, minor optimization to move/drag.
485486

486487
#### v0.2.6 (2016-08-17)
487488

dist/gridstack.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@
405405
};
406406

407407
GridStackEngine.prototype.canMoveNode = function(node, x, y, width, height) {
408+
if (!this.isNodeChangedPosition(node, x, y, width, height)) {
409+
return false;
410+
}
408411
var hasLocked = Boolean(_.find(this.nodes, function(n) { return n.locked; }));
409412

410413
if (!this.height && !hasLocked) {
@@ -460,7 +463,27 @@
460463
return clone.getGridHeight() <= this.height;
461464
};
462465

466+
GridStackEngine.prototype.isNodeChangedPosition = function(node, x, y, width, height) {
467+
if (typeof x != 'number') { x = node.x; }
468+
if (typeof y != 'number') { y = node.y; }
469+
if (typeof width != 'number') { width = node.width; }
470+
if (typeof height != 'number') { height = node.height; }
471+
472+
if (typeof node.maxWidth != 'undefined') { width = Math.min(width, node.maxWidth); }
473+
if (typeof node.maxHeight != 'undefined') { height = Math.min(height, node.maxHeight); }
474+
if (typeof node.minWidth != 'undefined') { width = Math.max(width, node.minWidth); }
475+
if (typeof node.minHeight != 'undefined') { height = Math.max(height, node.minHeight); }
476+
477+
if (node.x == x && node.y == y && node.width == width && node.height == height) {
478+
return false;
479+
}
480+
return true;
481+
};
482+
463483
GridStackEngine.prototype.moveNode = function(node, x, y, width, height, noPack) {
484+
if (!this.isNodeChangedPosition(node, x, y, width, height)) {
485+
return node;
486+
}
464487
if (typeof x != 'number') { x = node.x; }
465488
if (typeof y != 'number') { y = node.y; }
466489
if (typeof width != 'number') { width = node.width; }

dist/gridstack.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gridstack.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)