|
141 | 141 |
|
142 | 142 | sources.forEach(function(source) { |
143 | 143 | for (var prop in source) { |
144 | | - if (source.hasOwnProperty(prop) && !target.hasOwnProperty(prop)) { |
| 144 | + if (source.hasOwnProperty(prop) && (!target.hasOwnProperty(prop) || target[prop] === undefined)) { |
145 | 145 | target[prop] = source[prop]; |
146 | 146 | } |
147 | 147 | } |
|
393 | 393 | }; |
394 | 394 |
|
395 | 395 | GridStackEngine.prototype._prepareNode = function(node, resizing) { |
396 | | - node = Utils.defaults(node || {}, {width: 1, height: 1, x: 0, y: 0}); |
| 396 | + node = node || {}; |
| 397 | + // if we're missing position, have grid position us automatically (before we set them to 0,0) |
| 398 | + if (node.x === undefined || node.y === undefined) { |
| 399 | + node.autoPosition = true; |
| 400 | + } |
| 401 | + node = Utils.defaults(node, {width: 1, height: 1, x: 0, y: 0}); |
397 | 402 |
|
398 | 403 | node.x = parseInt('' + node.x); |
399 | 404 | node.y = parseInt('' + node.y); |
|
802 | 807 | el = $(el); |
803 | 808 | elements.push({ |
804 | 809 | el: el, |
805 | | - i: parseInt(el.attr('data-gs-x')) + parseInt(el.attr('data-gs-y')) * _this.opts.width |
| 810 | + // if x,y are missing (autoPosition) add them to end of list - keep their respective DOM order |
| 811 | + i: (parseInt(el.attr('data-gs-x')) || 100) + |
| 812 | + (parseInt(el.attr('data-gs-y')) || 100) * _this.opts.width |
806 | 813 | }); |
807 | 814 | }); |
808 | | - Utils.sortBy(elements, function(x) { return x.i; }).forEach(function(i) { |
809 | | - this._prepareElement(i.el); |
| 815 | + Utils.sortBy(elements, function(x) { return x.i; }).forEach(function(item) { |
| 816 | + this._prepareElement(item.el); |
810 | 817 | }, this); |
811 | 818 | } |
812 | 819 |
|
|
1388 | 1395 |
|
1389 | 1396 | el.addClass(this.opts.itemClass); |
1390 | 1397 | var node = self.grid.addNode({ |
1391 | | - x: parseInt(el.attr('data-gs-x'), 10), |
1392 | | - y: parseInt(el.attr('data-gs-y'), 10), |
| 1398 | + x: el.attr('data-gs-x'), |
| 1399 | + y: el.attr('data-gs-y'), |
1393 | 1400 | width: el.attr('data-gs-width'), |
1394 | 1401 | height: el.attr('data-gs-height'), |
1395 | 1402 | maxWidth: el.attr('data-gs-max-width'), |
|
0 commit comments