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

Skip to content

Commit 5defb90

Browse files
authored
Merge pull request #1152 from adumesny/develop
WebComponent support
2 parents 1b5b277 + 33b4e32 commit 5defb90

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ $(function () {
143143

144144
// you can now call on any grid this...
145145
$('.grid-stack').data('gridstack').printCount();
146-
});
146+
});
147147
```
148148

149149
## Touch devices support

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Change log
3131

3232
## v0.6.3-dev (upcoming changes)
3333

34+
- fix [#540](https://github.com/gridstack/gridstack.js/issues/540) WebComponent support: CSS file now insert before grid instead of 'head'
3435
- fix [#1143](https://github.com/gridstack/gridstack.js/issues/1143) nested grids with different `acceptWidgets` class
3536
- fix [#1142](https://github.com/gridstack/gridstack.js/issues/1142) add/remove widget will also trigger change events when it should.
3637
- optimized `change` callback to save original x,y,w,h values and only call those that changed [1148](https://github.com/gridstack/gridstack.js/pull/1148)

src/gridstack.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
return Utils.sortBy(nodes, function(n) { return (n.x + n.y * column); });
7676
},
7777

78-
createStylesheet: function(id) {
78+
createStylesheet: function(id, parent) {
7979
var style = document.createElement('style');
8080
style.setAttribute('type', 'text/css');
8181
style.setAttribute('data-gs-style-id', id);
@@ -84,7 +84,8 @@
8484
} else {
8585
style.appendChild(document.createTextNode(''));
8686
}
87-
document.getElementsByTagName('head')[0].appendChild(style);
87+
if (!parent) { parent = document.getElementsByTagName('head')[0]; } // default to head
88+
parent.insertBefore(style, parent.firstChild);
8889
return style.sheet;
8990
},
9091

@@ -1068,7 +1069,8 @@
10681069
Utils.removeStylesheet(this._stylesId);
10691070
}
10701071
this._stylesId = 'gridstack-style-' + (Math.random() * 100000).toFixed();
1071-
this._styles = Utils.createStylesheet(this._stylesId);
1072+
// insert style to parent (instead of 'head') to support WebComponent
1073+
this._styles = Utils.createStylesheet(this._stylesId, this.container.get(0).parentNode);
10721074
if (this._styles !== null) {
10731075
this._styles._max = 0;
10741076
}

0 commit comments

Comments
 (0)