|
51 | 51 | if (!can_be_moved) {
|
52 | 52 | break;
|
53 | 53 | }
|
| 54 | + n._dirty = n.y != new_y; |
54 | 55 | n.y = new_y;
|
55 | 56 | }
|
56 | 57 | }, this);
|
|
96 | 97 | };
|
97 | 98 |
|
98 | 99 | GridStackEngine.prototype._notify = function () {
|
99 |
| - this.onchange(this.nodes); |
| 100 | + var deleted_nodes = Array.prototype.slice.call(arguments, 1).concat(this.get_dirty_nodes()); |
| 101 | + deleted_nodes = deleted_nodes.concat(this.get_dirty_nodes()); |
| 102 | + this.onchange(deleted_nodes); |
| 103 | + }; |
| 104 | + |
| 105 | + GridStackEngine.prototype.clean_nodes = function () { |
| 106 | + _.each(this.nodes, function (n) {n._dirty = false }); |
| 107 | + }; |
| 108 | + |
| 109 | + GridStackEngine.prototype.get_dirty_nodes = function () { |
| 110 | + return _.filter(this.nodes, function (n) { return n._dirty; }); |
100 | 111 | };
|
101 | 112 |
|
102 | 113 | GridStackEngine.prototype.add_node = function(node) {
|
|
108 | 119 | if (typeof node.min_height != 'undefined') node.height = Math.max(node.height, node.min_height);
|
109 | 120 |
|
110 | 121 | node._id = ++id_seq;
|
| 122 | + node._dirty = true; |
111 | 123 | this.nodes.push(node);
|
112 | 124 | this._fix_collisions(node);
|
113 | 125 | this._pack_nodes();
|
|
138 | 150 | }
|
139 | 151 |
|
140 | 152 | var moving = node.x != x;
|
| 153 | + node._dirty = true; |
141 | 154 |
|
142 | 155 | node.x = x;
|
143 | 156 | node.y = y;
|
|
175 | 188 |
|
176 | 189 | this.grid = new GridStackEngine(this.opts.width, function (nodes) {
|
177 | 190 | _.each(nodes, function (n) {
|
178 |
| - n.el |
179 |
| - .attr('data-gs-x', n.x) |
180 |
| - .attr('data-gs-y', n.y) |
181 |
| - .attr('data-gs-width', n.width) |
182 |
| - .attr('data-gs-height', n.height); |
| 191 | + if (n._id == null) { |
| 192 | + n.el.remove(); |
| 193 | + } |
| 194 | + else { |
| 195 | + n.el |
| 196 | + .attr('data-gs-x', n.x) |
| 197 | + .attr('data-gs-y', n.y) |
| 198 | + .attr('data-gs-width', n.width) |
| 199 | + .attr('data-gs-height', n.height); |
| 200 | + } |
183 | 201 | });
|
184 | 202 | });
|
185 | 203 |
|
|
219 | 237 |
|
220 | 238 | var on_start_moving = function (event, ui) {
|
221 | 239 | var o = $(this);
|
| 240 | + self.grid.clean_nodes(); |
222 | 241 | cell_width = Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
|
223 | 242 | self.placeholder
|
224 | 243 | .attr('data-gs-x', o.attr('data-gs-x'))
|
|
240 | 259 | .attr('data-gs-height', node.height)
|
241 | 260 | .removeAttr('style');
|
242 | 261 | self._update_container_height();
|
| 262 | + self.container.trigger('change', [self.grid.get_dirty_nodes()]); |
243 | 263 | };
|
244 | 264 |
|
245 | 265 | el.draggable({
|
|
0 commit comments