|
17 | 17 | min_cols: 1,
|
18 | 18 | max_cols: null,
|
19 | 19 | min_rows: 15,
|
20 |
| - max_size_x: 6, |
| 20 | + max_size_x: false, |
21 | 21 | autogenerate_stylesheet: true,
|
22 | 22 | avoid_overlapped_widgets: true,
|
23 | 23 | serialize_params: function($w, wgd) {
|
|
191 | 191 |
|
192 | 192 |
|
193 | 193 | /**
|
194 |
| - * Change the size of a widget. |
| 194 | + * Change the size of a widget. Width is limited to the current grid width. |
195 | 195 | *
|
196 | 196 | * @method resize_widget
|
197 | 197 | * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
|
|
210 | 210 | size_x = this.cols;
|
211 | 211 | }
|
212 | 212 |
|
213 |
| - var old_cells_occupied = this.get_cells_occupied(wgd); |
214 |
| - var old_size_x = wgd.size_x; |
215 | 213 | var old_size_y = wgd.size_y;
|
216 | 214 | var old_col = wgd.col;
|
217 | 215 | var new_col = old_col;
|
218 |
| - var wider = size_x > old_size_x; |
219 |
| - var taller = size_y > old_size_y; |
220 | 216 |
|
221 | 217 | if (old_col + size_x - 1 > this.cols) {
|
222 | 218 | var diff = old_col + (size_x - 1) - this.cols;
|
223 | 219 | var c = old_col - diff;
|
224 | 220 | new_col = Math.max(1, c);
|
225 | 221 | }
|
226 | 222 |
|
| 223 | + if (size_y > old_size_y) { |
| 224 | + this.add_faux_rows(Math.max(size_y - old_size_y, 0)); |
| 225 | + } |
| 226 | + |
227 | 227 | var new_grid_data = {
|
228 | 228 | col: new_col,
|
229 | 229 | row: wgd.row,
|
230 | 230 | size_x: size_x,
|
231 | 231 | size_y: size_y
|
232 | 232 | };
|
233 | 233 |
|
234 |
| - var new_cells_occupied = this.get_cells_occupied(new_grid_data); |
| 234 | + this.mutate_widget_in_gridmap($widget, wgd, new_grid_data); |
| 235 | + |
| 236 | + this.set_dom_grid_height(); |
| 237 | + |
| 238 | + if (callback) { |
| 239 | + callback.call(this, new_grid_data.size_x, new_grid_data.size_y); |
| 240 | + } |
| 241 | + |
| 242 | + return $widget; |
| 243 | + }; |
| 244 | + |
| 245 | + |
| 246 | + fn.mutate_widget_in_gridmap = function($widget, wgd, new_wgd) { |
| 247 | + |
| 248 | + var old_size_x = wgd.size_x; |
| 249 | + var old_size_y = wgd.size_y; |
| 250 | + |
| 251 | + var old_cells_occupied = this.get_cells_occupied(wgd); |
| 252 | + var new_cells_occupied = this.get_cells_occupied(new_wgd); |
235 | 253 |
|
236 | 254 | var empty_cols = [];
|
237 | 255 | $.each(old_cells_occupied.cols, function(i, col) {
|
|
265 | 283 |
|
266 | 284 | if (occupied_cols.length) {
|
267 | 285 | var cols_to_empty = [
|
268 |
| - new_col, wgd.row, size_x, Math.min(old_size_y, size_y), $widget |
| 286 | + new_wgd.col, new_wgd.row, new_wgd.size_x, Math.min(old_size_y, new_wgd.size_y), $widget |
269 | 287 | ];
|
270 | 288 | this.empty_cells.apply(this, cols_to_empty);
|
271 | 289 | }
|
272 | 290 |
|
273 | 291 | if (occupied_rows.length) {
|
274 |
| - var rows_to_empty = [new_col, wgd.row, size_x, size_y, $widget]; |
| 292 | + var rows_to_empty = [new_wgd.col, new_wgd.row, new_wgd.size_x, new_wgd.size_y, $widget]; |
275 | 293 | this.empty_cells.apply(this, rows_to_empty);
|
276 | 294 | }
|
277 | 295 |
|
278 |
| - wgd.col = new_col; |
279 |
| - wgd.size_x = size_x; |
280 |
| - wgd.size_y = size_y; |
281 |
| - this.add_to_gridmap(new_grid_data, $widget); |
| 296 | + // not the same that wgd = new_wgd; |
| 297 | + wgd.col = new_wgd.col; |
| 298 | + wgd.row = new_wgd.row; |
| 299 | + wgd.size_x = new_wgd.size_x; |
| 300 | + wgd.size_y = new_wgd.size_y; |
| 301 | + |
| 302 | + this.add_to_gridmap(new_wgd, $widget); |
282 | 303 |
|
283 | 304 | //update coords instance attributes
|
284 | 305 | $widget.data('coords').update({
|
285 |
| - width: (size_x * this.options.widget_base_dimensions[0] + |
286 |
| - ((size_x - 1) * this.options.widget_margins[0]) * 2), |
287 |
| - height: (size_y * this.options.widget_base_dimensions[1] + |
288 |
| - ((size_y - 1) * this.options.widget_margins[1]) * 2) |
| 306 | + width: (new_wgd.size_x * this.options.widget_base_dimensions[0] + |
| 307 | + ((new_wgd.size_x - 1) * this.options.widget_margins[0]) * 2), |
| 308 | + height: (new_wgd.size_y * this.options.widget_base_dimensions[1] + |
| 309 | + ((new_wgd.size_y - 1) * this.options.widget_margins[1]) * 2) |
289 | 310 | });
|
290 | 311 |
|
291 |
| - if (size_y > old_size_y) { |
292 |
| - this.add_faux_rows(size_y - old_size_y); |
293 |
| - } |
294 |
| - |
295 |
| - if (size_x > old_size_x) { |
296 |
| - this.add_faux_cols(size_x - old_size_x); |
297 |
| - } |
298 |
| - |
299 | 312 | $widget.attr({
|
300 |
| - 'data-col': new_col, |
301 |
| - 'data-sizex': size_x, |
302 |
| - 'data-sizey': size_y |
| 313 | + 'data-col': new_wgd.col, |
| 314 | + 'data-row': new_wgd.row, |
| 315 | + 'data-sizex': new_wgd.size_x, |
| 316 | + 'data-sizey': new_wgd.size_y |
303 | 317 | });
|
304 | 318 |
|
305 | 319 | if (empty_cols.length) {
|
306 | 320 | var cols_to_remove_holes = [
|
307 |
| - empty_cols[0], wgd.row, |
| 321 | + empty_cols[0], new_wgd.row, |
308 | 322 | empty_cols.length,
|
309 |
| - Math.min(old_size_y, size_y), |
| 323 | + Math.min(old_size_y, new_wgd.size_y), |
310 | 324 | $widget
|
311 | 325 | ];
|
312 | 326 |
|
|
315 | 329 |
|
316 | 330 | if (empty_rows.length) {
|
317 | 331 | var rows_to_remove_holes = [
|
318 |
| - new_col, wgd.row, size_x, size_y, $widget |
| 332 | + new_wgd.col, new_wgd.row, new_wgd.size_x, new_wgd.size_y, $widget |
319 | 333 | ];
|
320 | 334 | this.remove_empty_cells.apply(this, rows_to_remove_holes);
|
321 | 335 | }
|
322 | 336 |
|
323 |
| - if (callback) { |
324 |
| - callback.call(this, size_x, size_y); |
325 |
| - } |
| 337 | + this.move_widget_up($widget); |
326 | 338 |
|
327 |
| - return $widget; |
| 339 | + return this; |
328 | 340 | };
|
329 | 341 |
|
| 342 | + |
330 | 343 | /**
|
331 | 344 | * Move down widgets in cells represented by the arguments col, row, size_x,
|
332 | 345 | * size_y
|
|
2274 | 2287 | */
|
2275 | 2288 | fn.generate_stylesheet = function(opts) {
|
2276 | 2289 | var styles = '';
|
2277 |
| - var max_size_x = this.options.max_size_x; |
| 2290 | + var max_size_x = this.options.max_size_x || this.cols; |
2278 | 2291 | var max_rows = 0;
|
2279 | 2292 | var max_cols = 0;
|
2280 | 2293 | var i;
|
|
0 commit comments