|
348 | 348 | max_height = Math.max(max_height, n.y + n.height); |
349 | 349 | } |
350 | 350 | }); |
351 | | - max_height += 10; |
352 | | - if (max_height > self._styles._max) { |
353 | | - for (var i = self._styles._max; i < max_height; ++i) { |
354 | | - var css; |
355 | | - css = '.' + self.opts._class + ' .' + self.opts.item_class + '[data-gs-height="' + (i + 1) + '"] { height: ' + (self.opts.cell_height * (i + 1) + self.opts.vertical_margin * i) + 'px; }'; |
356 | | - self._styles.insertRule(css, i); |
357 | | - css = '.' + self.opts._class + ' .' + self.opts.item_class + '[data-gs-y="' + (i) + '"] { top: ' + (self.opts.cell_height * i + self.opts.vertical_margin * i) + 'px; }'; |
358 | | - self._styles.insertRule(css, i); |
359 | | - } |
360 | | - self._styles._max = max_height; |
361 | | - } |
| 351 | + self._update_styles(max_height + 10); |
362 | 352 | }, this.opts.float, this.opts.height); |
363 | 353 |
|
364 | 354 | if (this.opts.auto) { |
|
410 | 400 | on_resize_handler(); |
411 | 401 | }; |
412 | 402 |
|
| 403 | + GridStack.prototype._update_styles = function (max_height) { |
| 404 | + if (typeof max_height == 'undefined') { |
| 405 | + max_height = this._styles._max; |
| 406 | + this._styles._max = 0; |
| 407 | + while (this._styles.rules.length) { |
| 408 | + this._styles.removeRule(0); |
| 409 | + } |
| 410 | + this._update_container_height(); |
| 411 | + } |
| 412 | + |
| 413 | + if (max_height > this._styles._max) { |
| 414 | + for (var i = this._styles._max; i < max_height; ++i) { |
| 415 | + var css; |
| 416 | + css = '.' + this.opts._class + ' .' + this.opts.item_class + '[data-gs-height="' + (i + 1) + '"] { height: ' + (this.opts.cell_height * (i + 1) + this.opts.vertical_margin * i) + 'px; }'; |
| 417 | + this._styles.insertRule(css, i); |
| 418 | + css = '.' + this.opts._class + ' .' + this.opts.item_class + '[data-gs-y="' + (i) + '"] { top: ' + (this.opts.cell_height * i + this.opts.vertical_margin * i) + 'px; }'; |
| 419 | + this._styles.insertRule(css, i); |
| 420 | + } |
| 421 | + this._styles._max = max_height; |
| 422 | + } |
| 423 | + }; |
| 424 | + |
413 | 425 | GridStack.prototype._update_container_height = function () { |
414 | 426 | this.container.height(this.grid.get_grid_height() * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin); |
415 | 427 | }; |
|
441 | 453 | }); |
442 | 454 | el.data('_gridstack_node', node); |
443 | 455 |
|
444 | | - var cell_width, cell_height = this.opts.cell_height + this.opts.vertical_margin; |
| 456 | + var cell_width, cell_height; |
445 | 457 |
|
446 | 458 | var on_start_moving = function (event, ui) { |
447 | 459 | var o = $(this); |
448 | 460 | self.grid.clean_nodes(); |
449 | 461 | self.grid.begin_update(node); |
450 | 462 | cell_width = Math.ceil(o.outerWidth() / o.attr('data-gs-width')); |
| 463 | + cell_height = self.opts.cell_height + self.opts.vertical_margin; |
451 | 464 | self.placeholder |
452 | 465 | .attr('data-gs-x', o.attr('data-gs-x')) |
453 | 466 | .attr('data-gs-y', o.attr('data-gs-y')) |
|
668 | 681 | }); |
669 | 682 | }; |
670 | 683 |
|
| 684 | + GridStack.prototype.cell_height = function (val) { |
| 685 | + if (typeof val == 'undefined') { |
| 686 | + return this.opts.cell_height; |
| 687 | + } |
| 688 | + val = parseInt(val); |
| 689 | + if (val == this.opts.cell_height) |
| 690 | + return; |
| 691 | + this.opts.cell_height = val || this.opts.cell_height; |
| 692 | + this._update_styles(); |
| 693 | + }; |
| 694 | + |
| 695 | + GridStack.prototype.cell_width = function () { |
| 696 | + var o = this.container.find('.' + this.opts.item_class).first(); |
| 697 | + return Math.ceil(o.outerWidth() / o.attr('data-gs-width')); |
| 698 | + }; |
| 699 | + |
671 | 700 | scope.GridStackUI = GridStack; |
672 | 701 |
|
673 | 702 | scope.GridStackUI.Utils = Utils; |
|
0 commit comments