Skip to content

Commit 7c86d51

Browse files
authored
Merge pull request #1522 from adumesny/develop
support all options for new dragged in widgets
2 parents 392d411 + 8d13204 commit 7c86d51

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

demo/two.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,14 @@ <h1>Two grids demo</h1>
5050
<div class="row">
5151
<div class="col-md-3">
5252
<div class="sidebar">
53-
5453
<!-- will size to match content -->
5554
<div class="grid-stack-item">
5655
<div class="grid-stack-item-content">Drag me</div>
5756
</div>
5857
<!-- manually force a drop size of 2x1 -->
59-
<div class="grid-stack-item" gs-w="2" gs-h="1">
60-
<div class="grid-stack-item-content">Drag me 2x1</div>
58+
<div class="grid-stack-item" gs-w="2" gs-h="1" gs-max-w="3">
59+
<div class="grid-stack-item-content">2x1, max=3</div>
6160
</div>
62-
6361
</div>
6462
</div>
6563
<div class="col-md-9">

doc/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ Change log
4646
## 3.1.0-dev
4747

4848
- fix [1419](https://github.com/gridstack/gridstack.js/issues/1419) dragging into a fixed row grid works better (check if it will fit, else try to append, else won't insert)
49+
-- **possible BREAK** (unlikely you use engine directly)
50+
* engine constructor takes Options struct rather than spelling arguments (easier to extend/use)
51+
* `canBePlacedWithRespectToHeight()` -> `willItFit()` like grid method
52+
4953
- fix [1330](https://github.com/gridstack/gridstack.js/issues/1330) `maxW` does not work as intended with resizable handle `"w"`
54+
- fix [1472](https://github.com/gridstack/gridstack.js/issues/1472) support all options for new dragged in widgets (read all `gs-xyz` attributes)
5055

5156
## 3.1.0 (2020-12-4)
5257

src/gridstack-dd.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,15 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
130130
})
131131
.on(this.el, 'dropover', (event, el: GridItemHTMLElement) => {
132132
// ignore drop enter on ourself, and prevent parent from receiving event
133-
let node = el.gridstackNode || {};
134-
if (node.grid === this) {
133+
let node = el.gridstackNode;
134+
if (node && node.grid === this) {
135135
delete node._added; // reset this to track placeholder again in case we were over other grid #1484 (dropout doesn't always clear)
136136
return false;
137137
}
138138

139-
// see if we already have a node with widget/height and check for attributes
140-
if (el.getAttribute && (!node.w || !node.h)) {
141-
let w = parseInt(el.getAttribute('gs-w'));
142-
if (w > 0) { node.w = w; }
143-
let h = parseInt(el.getAttribute('gs-h'));
144-
if (h > 0) { node.h = h; }
139+
// load any element attributes if we don't have a node
140+
if (!node) {
141+
node = this._readAttr(el);
145142
}
146143

147144
// if the item came from another grid, let it know it was added here to removed duplicate shadow #393

src/gridstack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,8 @@ export class GridStack {
13071307
}
13081308

13091309
/** @internal call to read any default attributes from element */
1310-
private _readAttr(el: HTMLElement, node: GridStackNode = {}): GridStackWidget {
1310+
private _readAttr(el: HTMLElement): GridStackWidget {
1311+
let node: GridStackNode = {};
13111312
node.x = Utils.toNumber(el.getAttribute('gs-x'));
13121313
node.y = Utils.toNumber(el.getAttribute('gs-y'));
13131314
node.w = Utils.toNumber(el.getAttribute('gs-w'));

0 commit comments

Comments
 (0)