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

Skip to content

Commit 78199e2

Browse files
committed
fix boolean attributes
1 parent 67fb4e2 commit 78199e2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/gridstack.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
document.head.appendChild(style);
2424

2525
return style.sheet;
26+
},
27+
28+
toBool: function (v) {
29+
if (typeof v == 'boolean')
30+
return v;
31+
if (typeof v == 'string') {
32+
v = v.toLowerCase();
33+
return !(v == '' || v == 'no' || v == 'false' || v == '0');
34+
}
35+
return Boolean(v);
2636
}
2737
};
2838

@@ -423,10 +433,10 @@
423433
min_width: el.attr('data-gs-min-width'),
424434
max_height: el.attr('data-gs-max-height') || 100,
425435
min_height: el.attr('data-gs-min-height'),
426-
auto_position: el.attr('data-gs-auto-position'),
427-
no_resize: el.attr('data-gs-no-resize'),
428-
no_move: el.attr('data-gs-no-move'),
429-
locked: el.attr('data-gs-locked'),
436+
auto_position: Utils.toBool(el.attr('data-gs-auto-position')),
437+
no_resize: Utils.toBool(el.attr('data-gs-no-resize')),
438+
no_move: Utils.toBool(el.attr('data-gs-no-move')),
439+
locked: Utils.toBool(el.attr('data-gs-locked')),
430440
el: el
431441
});
432442
el.data('_gridstack_node', node);
@@ -532,7 +542,7 @@
532542
if (typeof y != 'undefined') el.attr('data-gs-y', y);
533543
if (typeof width != 'undefined') el.attr('data-gs-width', width);
534544
if (typeof height != 'undefined') el.attr('data-gs-height', height);
535-
if (typeof auto_position != 'undefined') el.attr('data-gs-auto-position', auto_position);
545+
if (typeof auto_position != 'undefined') el.attr('data-gs-auto-position', auto_position ? 'yes' : null);
536546
this.container.append(el);
537547
this._prepare_element(el);
538548
this._update_container_height();

0 commit comments

Comments
 (0)