Skip to content

Commit 4cd4fc1

Browse files
authored
Merge pull request #1316 from adumesny/typescript
TS: adding styleInHead option for #1313
2 parents 066eb35 + f1a51a2 commit 4cd4fc1

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

doc/CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Change log
66
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
77

88
- [2.0.0-dev (upcoming)](#200-dev-upcoming)
9+
- [1.2.0 (upcoming)](#120-upcoming)
910
- [1.1.2 (2020-05-17)](#112-2020-05-17)
1011
- [1.1.1 (2020-03-17)](#111-2020-03-17)
1112
- [1.1.0 (2020-02-29)](#110-2020-02-29)
@@ -44,6 +45,11 @@ Change log
4445
You can now have perfect square cells (default) [723](https://github.com/gridstack/gridstack.js/issues/723)
4546
- fix [1299](https://github.com/gridstack/gridstack.js/pull/1299) many columns round-off error
4647

48+
## 1.2.0 (upcoming)
49+
50+
- fix [1311](https://github.com/gridstack/gridstack.js/issues/1311) domAttr is not defined
51+
- adds `styleInHead` option to allow for selecting older behavior (adding STYLE element to HEAD element instead of parentNode)
52+
4753
## 1.1.2 (2020-05-17)
4854

4955
- fix [1229](https://github.com/gridstack/gridstack.js/issues/1229) `staticGrid` no longer disable oneColumnMode

doc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ gridstack.js API
113113
- `row` - fix grid number of rows. This is a shortcut of writing `minRow:N, maxRow:N`. (default `0` no constrain)
114114
- `rtl` - if `true` turns grid to RTL. Possible values are `true`, `false`, `'auto'` (default: `'auto'`) See [example](http://gridstackjs.com/demo/rtl.html)
115115
- `staticGrid` - removes drag&drop&resize (default `false`). If `true` widgets are not movable/resizable by the user, but code can still move and oneColumnMode will still work. You don't even need jQueryUI draggable/resizable. A CSS class `grid-stack-static` is also added to the container.
116+
- `styleInHead` - if `true` will add style element to `<head>` otherwise will add it to element's parent node (default `false`).
116117

117118
## Grid attributes
118119

spec/gridstack-spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,23 @@ describe('gridstack', function() {
11581158
});
11591159
});
11601160

1161+
describe('grid.opts.styleInHead', function() {
1162+
beforeEach(function() {
1163+
document.body.insertAdjacentHTML('afterbegin', gridstackHTML);
1164+
});
1165+
afterEach(function() {
1166+
document.body.removeChild(document.getElementById('gs-cont'));
1167+
});
1168+
it('should add STYLE to parent node as a default', function() {
1169+
var grid = GridStack.init();
1170+
expect((grid as any)._styles.ownerNode.parentNode.tagName).toBe('DIV');
1171+
});
1172+
it('should add STYLE to HEAD if styleInHead === true', function() {
1173+
var grid = GridStack.init({styleInHead: true});
1174+
expect((grid as any)._styles.ownerNode.parentNode.tagName).toBe('HEAD');
1175+
});
1176+
});
1177+
11611178
describe('grid.enableMove', function() {
11621179
beforeEach(function() {
11631180
document.body.insertAdjacentHTML('afterbegin', gridstackHTML);

src/gridstack.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export class GridStack {
170170
placeholderText: '',
171171
handle: '.grid-stack-item-content',
172172
handleClass: null,
173+
styleInHead: false,
173174
cellHeight: 'auto',
174175
margin: 10,
175176
auto: true,
@@ -1075,9 +1076,9 @@ export class GridStack {
10751076
Utils.removeStylesheet(this._stylesId);
10761077
}
10771078
this._stylesId = 'gridstack-style-' + (Math.random() * 100000).toFixed();
1078-
// insert style to parent (instead of 'head') to support WebComponent
1079-
let parent = this.el.parentNode as HTMLElement;
1080-
this._styles = Utils.createStylesheet(this._stylesId, parent);
1079+
// insert style to parent (instead of 'head' by default) to support WebComponent
1080+
let styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode as HTMLElement;
1081+
this._styles = Utils.createStylesheet(this._stylesId, styleLocation);
10811082
if (this._styles !== null) {
10821083
this._styles._max = 0;
10831084
}

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ export interface GridstackOptions {
162162
*/
163163
staticGrid?: boolean;
164164

165+
/** if `true` will add style element to `<head>` otherwise will add it to element's parent node (default `false`). */
166+
styleInHead?: boolean;
167+
165168
/** @internal */
166169
_isNested?: boolean;
167170
/** @internal */

0 commit comments

Comments
 (0)