|
62 | 62 | width = Math.max.apply(Math, widths);
|
63 | 63 | }
|
64 | 64 |
|
65 |
| - dir = dir !== -1 ? 1 : -1; |
66 |
| - return Utils.sortBy(nodes, function(n) { return dir * (n.x + n.y * width); }); |
| 65 | + if (dir === -1) |
| 66 | + return Utils.sortBy(nodes, function(n) { return -(n.x + n.y * width); }); |
| 67 | + else |
| 68 | + return Utils.sortBy(nodes, function(n) { return (n.x + n.y * width); }); |
67 | 69 | },
|
68 | 70 |
|
69 | 71 | createStylesheet: function(id) {
|
|
942 | 944 | }
|
943 | 945 | })
|
944 | 946 | .on(self.container, 'dropover', function(event, ui) {
|
945 |
| - var offset = self.container.offset(); |
946 | 947 | var el = $(ui.draggable);
|
947 |
| - var cellWidth = self.cellWidth(); |
948 |
| - var cellHeight = self.cellHeight(); |
| 948 | + var width, height; |
| 949 | + |
| 950 | + // see if we already have a node with widget/height and check for attributes |
949 | 951 | var origNode = el.data('_gridstack_node');
|
950 |
| - var verticalMargin = self.opts.verticalMargin; |
| 952 | + if (!origNode || !origNode.width || !origNode.height) { |
| 953 | + var w = parseInt(el.attr('data-gs-width')); |
| 954 | + if (w > 0) { origNode = origNode || {}; origNode.width = w; } |
| 955 | + var h = parseInt(el.attr('data-gs-height')); |
| 956 | + if (h > 0) { origNode = origNode || {}; origNode.height = h; } |
| 957 | + } |
951 | 958 |
|
| 959 | + // if not calculate the grid size based on element outer size |
952 | 960 | // height: Each row is cellHeight + verticalMargin, until last one which has no margin below
|
953 |
| - var width = origNode ? origNode.width : Math.ceil(el.outerWidth() / cellWidth); |
954 |
| - var height = origNode ? origNode.height : Math.round((el.outerHeight() + verticalMargin) / (cellHeight + verticalMargin)); |
| 961 | + var cellWidth = self.cellWidth(); |
| 962 | + var cellHeight = self.cellHeight(); |
| 963 | + var verticalMargin = self.opts.verticalMargin; |
| 964 | + width = origNode && origNode.width ? origNode.width : Math.ceil(el.outerWidth() / cellWidth); |
| 965 | + height = origNode && origNode.height ? origNode.height : Math.round((el.outerHeight() + verticalMargin) / (cellHeight + verticalMargin)); |
955 | 966 |
|
956 | 967 | draggingElement = el;
|
957 | 968 |
|
|
0 commit comments