Skip to content

Commit c8bb696

Browse files
authored
Merge pull request #1365 from adumesny/develop
fixed init() to give better error msg
2 parents cf48f8d + 7e5d4ef commit c8bb696

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

spec/gridstack-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('gridstack', function() {
5252
});
5353
it('use selector no dot', function() {
5454
let grid = GridStack.init(null, 'grid-stack');
55-
expect(grid).not.toBe(null);
55+
expect(grid).toEqual(null);
5656
});
5757
it('use wrong selector', function() {
5858
let grid = GridStack.init(null, 'FOO');
@@ -64,7 +64,7 @@ describe('gridstack', function() {
6464
});
6565
it('initAll use selector no dot', function() {
6666
let grids = GridStack.initAll(undefined, 'grid-stack');
67-
expect(grids.length).toBe(1);
67+
expect(grids.length).toBe(0);
6868
});
6969
it('initAll use wrong selector', function() {
7070
let grids = GridStack.initAll(undefined, 'FOO');

src/gridstack.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ export class GridStack {
7575
let el = GridStack.getGridElement(elOrString);
7676
if (!el) {
7777
if (typeof elOrString === 'string') {
78-
console.log('gridstack.js: init() no grid was found. Did you forget class ' + elOrString + ' on your element ?' +
79-
'\n".grid-stack" is required for proper CSS styling and drag/drop.');
78+
console.error('GridStack.initAll() no grid was found with selector "' + elOrString + '" - element missing or wrong selector ?' +
79+
'\nNote: ".grid-stack" is required for proper CSS styling and drag/drop, and is the default selector.');
8080
} else {
81-
console.log('gridstack.js: init() no grid element was passed.');
81+
console.error('GridStack.init() no grid element was passed.');
8282
}
8383
return null;
8484
}
@@ -106,8 +106,8 @@ export class GridStack {
106106
grids.push(el.gridstack);
107107
});
108108
if (grids.length === 0) {
109-
console.log('gridstack.js: initAll() no grid was found. Did you forget class ' + selector + ' on your element ?' +
110-
'\n".grid-stack" is required for proper CSS styling and drag/drop.');
109+
console.error('GridStack.initAll() no grid was found with selector "' + selector + '" - element missing or wrong selector ?' +
110+
'\nNote: ".grid-stack" is required for proper CSS styling and drag/drop, and is the default selector.');
111111
}
112112
return grids;
113113
}
@@ -1704,18 +1704,11 @@ export class GridStack {
17041704
}
17051705
/** @internal */
17061706
private static getGridElement(els: string | HTMLElement = '.grid-stack'): GridHTMLElement {
1707-
return (typeof els === 'string' ?
1708-
(document.querySelector(els) || document.querySelector('#' + els) || document.querySelector('.' + els)) : els);
1707+
return (typeof els === 'string' ? document.querySelector(els) : els);
17091708
}
17101709
/** @internal */
17111710
private static getGridElements(els: string | HTMLElement = '.grid-stack'): GridHTMLElement[] {
1712-
if (typeof els === 'string') {
1713-
let list = document.querySelectorAll(els);
1714-
if (!list.length) { list = document.querySelectorAll('.' + els) }
1715-
if (!list.length) { list = document.querySelectorAll('#' + els) }
1716-
return Array.from(list) as GridHTMLElement[];
1717-
}
1718-
return [els];
1711+
return (typeof els === 'string') ? Array.from(document.querySelectorAll(els)) : [els];
17191712
}
17201713

17211714
/** @internal initialize margin top/bottom/left/right and units */

0 commit comments

Comments
 (0)