|
355 | 355 |
|
356 | 356 | if (this.float) {
|
357 | 357 | this.nodes.forEach(function(n, i) {
|
358 |
| - if (n._updating || n._origY === undefined || n.y === n._origY) { |
| 358 | + if (n._updating || n._packY === undefined || n.y === n._packY) { |
359 | 359 | return;
|
360 | 360 | }
|
361 | 361 |
|
362 | 362 | var newY = n.y;
|
363 |
| - while (newY >= n._origY) { |
| 363 | + while (newY >= n._packY) { |
364 | 364 | var collisionNode = this.nodes
|
365 | 365 | .slice(0, i)
|
366 | 366 | .find(Utils._didCollide, {n: n, newY: newY});
|
|
653 | 653 | GridStackEngine.prototype.beginUpdate = function(node) {
|
654 | 654 | if (node._updating) return;
|
655 | 655 | node._updating = true;
|
656 |
| - this.nodes.forEach(function(n) { n._origY = n.y; }); |
| 656 | + this.nodes.forEach(function(n) { n._packY = n.y; }); |
657 | 657 | };
|
658 | 658 |
|
659 | 659 | GridStackEngine.prototype.endUpdate = function() {
|
660 | 660 | var n = this.nodes.find(function(n) { return n._updating; });
|
661 | 661 | if (n) {
|
662 | 662 | n._updating = false;
|
663 |
| - this.nodes.forEach(function(n) { delete n._origY; }); |
| 663 | + this.nodes.forEach(function(n) { delete n._packY; }); |
664 | 664 | }
|
665 | 665 | };
|
666 | 666 |
|
|
1801 | 1801 | GridStackEngine.prototype._layoutsNodesChange = function(nodes) {
|
1802 | 1802 | if (!this._layouts || this._ignoreLayoutsNodeChange) return;
|
1803 | 1803 | // remove smaller layouts - we will re-generate those on the fly... larger ones need to update
|
1804 |
| - this._layouts.forEach(function(layout, i) { |
1805 |
| - if (!layout || i === this.column) return; |
1806 |
| - if (i < this.column) { |
1807 |
| - this._layouts[i] = undefined; |
| 1804 | + this._layouts.forEach(function(layout, column) { |
| 1805 | + if (!layout || column === this.column) return; |
| 1806 | + if (column < this.column) { |
| 1807 | + this._layouts[column] = undefined; |
1808 | 1808 | }
|
1809 | 1809 | else {
|
1810 |
| - // TODO: save the original x,y,w (h isn't cached) and see what actually changed to propagate correctly ? |
| 1810 | + // we save the original x,y,w (h isn't cached) to see what actually changed to propagate better. |
| 1811 | + // Note: we don't need to check against out of bound scaling/moving as that will be done when using those cache values. |
1811 | 1812 | nodes.forEach(function(node) {
|
1812 | 1813 | var n = layout.find(function(l) { return l._id === node._id });
|
1813 |
| - if (!n) return; |
1814 |
| - var ratio = i / this.column; |
1815 |
| - n.y = node.y; |
1816 |
| - n.x = Math.round(node.x * ratio); |
1817 |
| - // width ??? |
| 1814 | + if (!n) return; // no cache for new nodes. Will use those values. |
| 1815 | + var ratio = column / this.column; |
| 1816 | + // Y changed, push down same amount |
| 1817 | + // TODO: detect doing item 'swaps' will help instead of move (especially in 1 column mode) |
| 1818 | + if (node.y !== node._origY) { |
| 1819 | + n.y += (node.y - node._origY); |
| 1820 | + } |
| 1821 | + // X changed, scale from new position |
| 1822 | + if (node.x !== node._origX) { |
| 1823 | + n.x = Math.round(node.x * ratio); |
| 1824 | + } |
| 1825 | + // width changed, scale from new width |
| 1826 | + if (node.width !== node._origW) { |
| 1827 | + n.width = Math.round(node.width * ratio); |
| 1828 | + } |
| 1829 | + // ...height always carries over from cache |
1818 | 1830 | }, this);
|
1819 | 1831 | }
|
1820 | 1832 | }, this);
|
| 1833 | + |
| 1834 | + this._saveInitial(); // reset current value now that we diffed. |
1821 | 1835 | }
|
1822 | 1836 |
|
1823 | 1837 | /**
|
|
1906 | 1920 | }, this);
|
1907 | 1921 | this.commit();
|
1908 | 1922 | delete this._ignoreLayoutsNodeChange;
|
| 1923 | + |
| 1924 | + // save this initial layout so we can see what changed and apply changes to other layouts better (diff) |
| 1925 | + this._saveInitial(); |
| 1926 | + } |
| 1927 | + |
| 1928 | + /** called to save initial position/size */ |
| 1929 | + GridStackEngine.prototype._saveInitial = function() { |
| 1930 | + this.nodes.forEach(function(n) { |
| 1931 | + n._origX = n.x; |
| 1932 | + n._origY = n.y; |
| 1933 | + n._origW = n.width; |
| 1934 | + n._origH = n.height; |
| 1935 | + }); |
1909 | 1936 | }
|
1910 | 1937 |
|
1911 | 1938 | /**
|
|
0 commit comments