Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3565ee5

Browse files
committed
add cell_width/cell_height
1 parent bb3f8b6 commit 3565ee5

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

src/gridstack.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,7 @@
348348
max_height = Math.max(max_height, n.y + n.height);
349349
}
350350
});
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);
362352
}, this.opts.float, this.opts.height);
363353

364354
if (this.opts.auto) {
@@ -410,6 +400,28 @@
410400
on_resize_handler();
411401
};
412402

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+
413425
GridStack.prototype._update_container_height = function () {
414426
this.container.height(this.grid.get_grid_height() * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin);
415427
};
@@ -441,13 +453,14 @@
441453
});
442454
el.data('_gridstack_node', node);
443455

444-
var cell_width, cell_height = this.opts.cell_height + this.opts.vertical_margin;
456+
var cell_width, cell_height;
445457

446458
var on_start_moving = function (event, ui) {
447459
var o = $(this);
448460
self.grid.clean_nodes();
449461
self.grid.begin_update(node);
450462
cell_width = Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
463+
cell_height = self.opts.cell_height + self.opts.vertical_margin;
451464
self.placeholder
452465
.attr('data-gs-x', o.attr('data-gs-x'))
453466
.attr('data-gs-y', o.attr('data-gs-y'))
@@ -668,6 +681,22 @@
668681
});
669682
};
670683

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+
671700
scope.GridStackUI = GridStack;
672701

673702
scope.GridStackUI.Utils = Utils;

0 commit comments

Comments
 (0)