Skip to content

Commit df96fc4

Browse files
fixed a bug deleting adoptedStyleSheets at -1 index (#3)
1 parent 7cdd3df commit df96fc4

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

dist/gridstack.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125

126126
createStylesheet: function(id) {
127127
var stylesheet = new CSSStyleSheet();
128-
128+
stylesheet._id = id;
129129
if (!document.adoptedStyleSheets || document.adoptedStyleSheets.length === 0) {
130130
document.adoptedStyleSheets = [stylesheet];
131131
} else {
@@ -139,12 +139,18 @@
139139
return stylesheet;
140140
},
141141

142-
removeStylesheet: function(stylesheet) {
142+
removeStylesheet: function(stylesId) {
143143
var styles = [];
144144
document.adoptedStyleSheets.forEach(function(style) {
145145
styles.push(style);
146146
});
147-
styles.splice(styles.indexOf(stylesheet),1);
147+
var indexToRemove = styles.findIndex(function(style) {
148+
return style._id === stylesId;
149+
});
150+
if (indexToRemove < 0) {
151+
return;
152+
}
153+
styles.splice(indexToRemove, 1);
148154
document.adoptedStyleSheets = styles;
149155
},
150156

@@ -1435,6 +1441,7 @@
14351441
}
14361442
if (Utils.isConstructableStyleSheetSupported()) {
14371443
Utils.removeStylesheet(this._stylesId);
1444+
this.styles = null;
14381445
}
14391446
if (this.grid) {
14401447
this.grid = null;

0 commit comments

Comments
 (0)