Skip to content

Commit c43b89f

Browse files
authored
Merge pull request #2164 from adumesny/master
custom itemClass fix
2 parents 37acc2e + 9298e61 commit c43b89f

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

demo/two.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
1010
<link rel="stylesheet" href="demo.css"/>
1111
<link rel="stylesheet" href="../dist/gridstack-extra.css"/>
12+
<style type="text/css">
13+
.with-lines { border: 1px dotted #777}
14+
</style>
1215

1316
<script src="../dist/gridstack-all.js"></script>
1417
</head>
@@ -59,7 +62,8 @@ <h1>Two grids demo</h1>
5962
// dragIn: '.sidebar .grid-stack-item', // add draggable to class
6063
// dragInOptions: { appendTo: 'body', helper: 'clone' }, // clone
6164
removable: '.trash', // true or drag-out delete class
62-
acceptWidgets: function(el) { return true; } // function example, but can also be: true | false | '.someClass' value
65+
// itemClass: 'with-lines', // test a custom additional class #2110
66+
acceptWidgets: function(el) { return true } // function example, but can also be: true | false | '.someClass' value
6367
};
6468
let grids = GridStack.initAll(options);
6569
grids[1].float(false);

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Change log
8080
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
8181
## 7.2.0-dev (TBD)
8282
* fix [#2162](https://github.com/gridstack/gridstack.js/pull/2162) removing item from a grid (into another) will now call `change` if anything was also modified during the remove
83+
* fix [#2110](https://github.com/gridstack/gridstack.js/issues/2110) custom `GridStackOptions.itemClass` now works when dragging from outside
8384

8485
## 7.2.0 (2023-01-07)
8586
* fix [#1936](https://github.com/gridstack/gridstack.js/issues/1936) some styles left behind after a drag

src/gridstack.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ export class GridStack {
19401940
}
19411941
dd.off(el, 'drag');
19421942
// if we made a copy ('helper' which is temp) of the original node then insert a copy, else we move the original node (#1102)
1943-
// as the helper will be nuked by jquery-ui otherwise
1943+
// as the helper will be nuked by jquery-ui otherwise. TODO: update old code path
19441944
if (helper !== el) {
19451945
helper.remove();
19461946
el.gridstackNode = origNode; // original item (left behind) is re-stored to pre dragging as the node now has drop info
@@ -1959,6 +1959,8 @@ export class GridStack {
19591959
Utils.copyPos(node, this._readAttr(this.placeholder)); // placeholder values as moving VERY fast can throw things off #1578
19601960
Utils.removePositioningStyles(el);// @ts-ignore
19611961
this._writeAttr(el, node);
1962+
el.className = '';
1963+
el.classList.add(gridDefaults.itemClass, this.opts.itemClass);
19621964
this.el.appendChild(el);// @ts-ignore // TODO: now would be ideal time to _removeHelperStyle() overriding floating styles (native only)
19631965
if (subGrid) {
19641966
subGrid.parentGridItem = node;
@@ -1976,7 +1978,7 @@ export class GridStack {
19761978

19771979
// wait till we return out of the drag callback to set the new drag&resize handler or they may get messed up
19781980
window.setTimeout(() => {
1979-
// IFF we are still there (some application will use as placeholder and insert their real widget instead and better call makeWidget())
1981+
// IFF we are still there (some application will use as placeholder and insert their real widget instead and better call makeWidget())
19801982
if (node.el && node.el.parentElement) {
19811983
this._prepareDragDropByNode(node);
19821984
} else {

0 commit comments

Comments
 (0)