|
25 | 25 | return _.sortBy(nodes, function (n) { return dir * (n.x + n.y * width); });
|
26 | 26 | },
|
27 | 27 |
|
28 |
| - create_stylesheet: function () { |
| 28 | + create_stylesheet: function (id) { |
29 | 29 | var style = document.createElement("style");
|
30 | 30 | style.setAttribute("type", "text/css");
|
| 31 | + style.setAttribute("data-gs-id", id); |
31 | 32 | if (style.styleSheet) {
|
32 | 33 | style.styleSheet.cssText = "";
|
33 | 34 | }
|
|
387 | 388 | });
|
388 | 389 |
|
389 | 390 | 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(); |
393 | 392 |
|
394 | 393 | this.grid = new GridStackEngine(this.opts.width, function (nodes) {
|
395 | 394 | var max_height = 0;
|
|
469 | 468 | on_resize_handler();
|
470 | 469 | };
|
471 | 470 |
|
| 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 | + |
472 | 481 | GridStack.prototype._update_styles = function (max_height) {
|
473 | 482 | if (this._styles == null) {
|
474 | 483 | return;
|
|
478 | 487 |
|
479 | 488 | if (typeof max_height == 'undefined') {
|
480 | 489 | 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(); |
490 | 491 | this._update_container_height();
|
491 | 492 | }
|
492 | 493 |
|
|
0 commit comments