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

Skip to content

Commit d26c2d6

Browse files
committed
update gridstack.js
1 parent fcc4a60 commit d26c2d6

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

demo/knockout.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ <h1>knockout.js Demo</h1>
3939

4040
<div>
4141
<button data-bind="click: add_new_widget">Add new widget</button>
42+
<button data-bind="click: change_cell_height">Change Cell Height</button>
4243
</div>
4344

4445
<br>
@@ -103,6 +104,11 @@ <h1>knockout.js Demo</h1>
103104
this.delete_widget = function (item) {
104105
self.widgets.remove(item);
105106
};
107+
108+
this.change_cell_height = function (item) {
109+
var grid = $('.grid-stack').data('gridstack');
110+
grid.cell_height(50 + 100 * Math.random());
111+
}.bind(this);
106112
};
107113

108114
var widgets = [

gridstack.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
return _.sortBy(nodes, function (n) { return dir * (n.x + n.y * width); });
2626
},
2727

28-
create_stylesheet: function () {
28+
create_stylesheet: function (id) {
2929
var style = document.createElement("style");
3030
style.setAttribute("type", "text/css");
31+
style.setAttribute("data-gs-id", id);
3132
if (style.styleSheet) {
3233
style.styleSheet.cssText = "";
3334
}
@@ -387,9 +388,7 @@
387388
});
388389

389390
this.container.addClass(this.opts._class);
390-
this._styles = Utils.create_stylesheet();
391-
if (this._styles != null)
392-
this._styles._max = 0;
391+
this._init_styles();
393392

394393
this.grid = new GridStackEngine(this.opts.width, function (nodes) {
395394
var max_height = 0;
@@ -469,6 +468,16 @@
469468
on_resize_handler();
470469
};
471470

471+
GridStack.prototype._init_styles = function () {
472+
if (this._styles_id) {
473+
$('link[rel=stylesheet][data-gs-id=' + this._styles_id + ']').remove();
474+
}
475+
this._styles_id = 'gridstack-style-' + (Math.random() * 100000).toFixed();
476+
this._styles = Utils.create_stylesheet();
477+
if (this._styles != null)
478+
this._styles._max = 0;
479+
};
480+
472481
GridStack.prototype._update_styles = function (max_height) {
473482
if (this._styles == null) {
474483
return;
@@ -478,15 +487,7 @@
478487

479488
if (typeof max_height == 'undefined') {
480489
max_height = this._styles._max;
481-
this._styles._max = 0;
482-
var f = function () {};
483-
if (typeof this._styles.removeRule === 'function')
484-
f = this._styles.removeRule;
485-
else if (typeof this._styles.deleteRule === 'function')
486-
f = this._styles.deleteRule;
487-
while (this._styles.rules.length) {
488-
f.call(this._styles, 0);
489-
}
490+
this._init_styles();
490491
this._update_container_height();
491492
}
492493

0 commit comments

Comments
 (0)