|
8 | 8 |
|
9 | 9 | var id_seq = 0;
|
10 | 10 |
|
11 |
| - var GridStackEngine = function (width, onchange) { |
| 11 | + var GridStackEngine = function (width, onchange, float) { |
12 | 12 | this.width = width;
|
| 13 | + this.float = float || false; |
13 | 14 |
|
14 | 15 | this.nodes = [];
|
15 | 16 | this.onchange = onchange || function () {};
|
|
38 | 39 | GridStackEngine.prototype._pack_nodes = function () {
|
39 | 40 | this._sort_nodes();
|
40 | 41 |
|
41 |
| - _.each(this.nodes, function (n, i) { |
42 |
| - while (n.y > 0) { |
43 |
| - var new_y = n.y - 1; |
44 |
| - var can_be_moved = i == 0; |
45 |
| - |
46 |
| - if (i > 0) { |
47 |
| - var collision_node = _.chain(this.nodes) |
48 |
| - .first(i) |
49 |
| - .find(function (bn) { |
50 |
| - return Utils.is_intercepted({x: n.x, y: new_y, width: n.width, height: n.height}, bn); |
51 |
| - }) |
52 |
| - .value(); |
53 |
| - can_be_moved = typeof collision_node == 'undefined'; |
| 42 | + if (this.float) { |
| 43 | + _.each(this.nodes, function (n, i) { |
| 44 | + if (n._updating || typeof n._orig_y == 'undefined' || n.y == n._orig_y) |
| 45 | + return; |
| 46 | + |
| 47 | + var collision_node = _.chain(this.nodes) |
| 48 | + .find(function (bn) { |
| 49 | + return n != bn && Utils.is_intercepted({x: n.x, y: n._orig_y, width: n.width, height: n.height}, bn); |
| 50 | + }) |
| 51 | + .value(); |
| 52 | + |
| 53 | + if (!collision_node) { |
| 54 | + n._dirty = true; |
| 55 | + n.y = n._orig_y; |
54 | 56 | }
|
| 57 | + }, this); |
| 58 | + } |
| 59 | + else { |
| 60 | + _.each(this.nodes, function (n, i) { |
| 61 | + while (n.y > 0) { |
| 62 | + var new_y = n.y - 1; |
| 63 | + var can_be_moved = i == 0; |
| 64 | + |
| 65 | + if (i > 0) { |
| 66 | + var collision_node = _.chain(this.nodes) |
| 67 | + .first(i) |
| 68 | + .find(function (bn) { |
| 69 | + return Utils.is_intercepted({x: n.x, y: new_y, width: n.width, height: n.height}, bn); |
| 70 | + }) |
| 71 | + .value(); |
| 72 | + can_be_moved = typeof collision_node == 'undefined'; |
| 73 | + } |
55 | 74 |
|
56 |
| - if (!can_be_moved) { |
57 |
| - break; |
| 75 | + if (!can_be_moved) { |
| 76 | + break; |
| 77 | + } |
| 78 | + n._dirty = n.y != new_y; |
| 79 | + n.y = new_y; |
58 | 80 | }
|
59 |
| - n._dirty = n.y != new_y; |
60 |
| - n.y = new_y; |
61 |
| - } |
62 |
| - }, this); |
| 81 | + }, this); |
| 82 | + } |
63 | 83 | };
|
64 | 84 |
|
65 | 85 | GridStackEngine.prototype._prepare_node = function (node, moving) {
|
|
194 | 214 | return _.reduce(this.nodes, function (memo, n) { return Math.max(memo, n.y + n.height); }, 0);
|
195 | 215 | };
|
196 | 216 |
|
| 217 | + GridStackEngine.prototype.begin_update = function (node) { |
| 218 | + _.each(this.nodes, function (n) { |
| 219 | + n._orig_y = n.y; |
| 220 | + }); |
| 221 | + node._updating = true; |
| 222 | + }; |
| 223 | + |
| 224 | + GridStackEngine.prototype.end_update = function () { |
| 225 | + var n = _.find(this.nodes, function (n) { return n._updating; }); |
| 226 | + if (n) { |
| 227 | + n._updating = false; |
| 228 | + } |
| 229 | + }; |
| 230 | + |
197 | 231 | var GridStack = function (el, opts) {
|
198 | 232 | var self = this, one_column_mode;
|
199 | 233 |
|
|
207 | 241 | cell_height: 60,
|
208 | 242 | vertical_margin: 20,
|
209 | 243 | auto: true,
|
210 |
| - min_width: 768 |
| 244 | + min_width: 768, |
| 245 | + float: false |
211 | 246 | });
|
212 | 247 |
|
213 | 248 | this.grid = new GridStackEngine(this.opts.width, function (nodes) {
|
|
223 | 258 | .attr('data-gs-height', n.height);
|
224 | 259 | }
|
225 | 260 | });
|
226 |
| - }); |
| 261 | + }, this.opts.float); |
227 | 262 |
|
228 | 263 | if (this.opts.auto) {
|
229 | 264 | this.container.find('.' + this.opts.item_class).each(function (index, el) {
|
|
299 | 334 | var on_start_moving = function (event, ui) {
|
300 | 335 | var o = $(this);
|
301 | 336 | self.grid.clean_nodes();
|
| 337 | + self.grid.begin_update(node); |
302 | 338 | cell_width = Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
|
303 | 339 | self.placeholder
|
304 | 340 | .attr('data-gs-x', o.attr('data-gs-x'))
|
|
322 | 358 | self._update_container_height();
|
323 | 359 | self.container.trigger('change', [self.grid.get_dirty_nodes()]);
|
324 | 360 |
|
| 361 | + self.grid.end_update(); |
| 362 | + |
325 | 363 | self.grid._sort_nodes();
|
326 | 364 | _.each(self.grid.nodes, function (node) {
|
327 | 365 | node.el.detach();
|
|
0 commit comments