@@ -681,7 +681,7 @@ export class GridStack {
681681 * @param val if true widget will be locked.
682682 */
683683 public locked ( els : GridStackElement , val : boolean ) : GridStack {
684- this . getElements ( els ) . forEach ( el => {
684+ GridStack . getElements ( els ) . forEach ( el => {
685685 let node = el . gridstackNode ;
686686 if ( ! node ) return ;
687687 node . locked = ( val || false ) ;
@@ -703,10 +703,10 @@ export class GridStack {
703703 * @example
704704 * let grid = GridStack.init();
705705 * grid.el.appendChild('<div id="gsi-1" data-gs-width="3"></div>');
706- * grid.makeWidget('gsi-1');
706+ * grid.makeWidget('# gsi-1');
707707 */
708708 public makeWidget ( els : GridStackElement ) : GridItemHTMLElement {
709- let el = this . getElement ( els ) ;
709+ let el = GridStack . getElement ( els ) ;
710710 this . _prepareElement ( el , true ) ;
711711 this . _updateContainerHeight ( ) ;
712712 this . _triggerAddEvent ( ) ;
@@ -756,7 +756,7 @@ export class GridStack {
756756 * @param val if true widget will be draggable.
757757 */
758758 public movable ( els : GridStackElement , val : boolean ) : GridStack {
759- this . getElements ( els ) . forEach ( el => {
759+ GridStack . getElements ( els ) . forEach ( el => {
760760 let node = el . gridstackNode ;
761761 if ( ! node ) { return }
762762 node . noMove = ! ( val || false ) ;
@@ -861,7 +861,7 @@ export class GridStack {
861861 * @param triggerEvent if `false` (quiet mode) element will not be added to removed list and no 'removed' callbacks will be called (Default? true).
862862 */
863863 public removeWidget ( els : GridStackElement , removeDOM = true , triggerEvent = true ) : GridStack {
864- this . getElements ( els ) . forEach ( el => {
864+ GridStack . getElements ( els ) . forEach ( el => {
865865 if ( el . parentElement !== this . el ) return ; // not our child!
866866 let node = el . gridstackNode ;
867867 // For Meteor support: https://github.com/gridstack/gridstack.js/pull/272
@@ -924,7 +924,7 @@ export class GridStack {
924924 * @param val if true widget will be resizable.
925925 */
926926 public resizable ( els : GridStackElement , val : boolean ) : GridStack {
927- this . getElements ( els ) . forEach ( el => {
927+ GridStack . getElements ( els ) . forEach ( el => {
928928 let node = el . gridstackNode ;
929929 if ( ! node ) { return ; }
930930 node . noResize = ! ( val || false ) ;
@@ -1450,7 +1450,7 @@ export class GridStack {
14501450
14511451 /** @internal */
14521452 private _updateElement ( els : GridStackElement , callback : ( el : GridItemHTMLElement , node : GridStackNode ) => void ) : GridStack {
1453- let el = this . getElement ( els ) ;
1453+ let el = GridStack . getElement ( els ) ;
14541454 if ( ! el ) { return this ; }
14551455 let node = el . gridstackNode ;
14561456 if ( ! node ) { return this ; }
@@ -1687,28 +1687,38 @@ export class GridStack {
16871687 return this ;
16881688 }
16891689
1690- /** @internal */
1691- private getElement ( els : GridStackElement = '.grid-stack-item' ) : GridItemHTMLElement {
1692- return ( typeof els === 'string' ?
1693- ( document . querySelector ( els ) || document . querySelector ( '#' + els ) || document . querySelector ( '.' + els ) ) : els ) ;
1690+ /** @internal convert a potential selector into actual element */
1691+ private static getElement ( els : GridStackElement = '.grid-stack-item' ) : GridItemHTMLElement {
1692+ if ( typeof els === 'string' ) {
1693+ let el = document . querySelector ( els ) ;
1694+ if ( ! el && els [ 0 ] !== '.' && els [ 0 ] !== '#' ) {
1695+ el = document . querySelector ( '#' + els ) ;
1696+ if ( ! el ) { el = document . querySelector ( '.' + els ) }
1697+ }
1698+ return el as GridItemHTMLElement ;
1699+ }
1700+ return els ;
16941701 }
1695- /** @internal */
1696- private getElements ( els : GridStackElement = '.grid-stack-item' ) : GridItemHTMLElement [ ] {
1702+
1703+ /** @internal convert a potential selector into actual list of elements */
1704+ private static getElements ( els : GridStackElement = '.grid-stack-item' ) : GridItemHTMLElement [ ] {
16971705 if ( typeof els === 'string' ) {
16981706 let list = document . querySelectorAll ( els ) ;
1699- if ( ! list . length ) { list = document . querySelectorAll ( '.' + els ) }
1700- if ( ! list . length ) { list = document . querySelectorAll ( '#' + els ) }
1707+ if ( ! list . length && els [ 0 ] !== '.' && els [ 0 ] !== '#' ) {
1708+ list = document . querySelectorAll ( '.' + els ) ;
1709+ if ( ! list . length ) { list = document . querySelectorAll ( '#' + els ) }
1710+ }
17011711 return Array . from ( list ) as GridItemHTMLElement [ ] ;
17021712 }
17031713 return [ els ] ;
17041714 }
17051715 /** @internal */
17061716 private static getGridElement ( els : string | HTMLElement = '.grid-stack' ) : GridHTMLElement {
1707- return ( typeof els === 'string' ? document . querySelector ( els ) : els ) ;
1717+ return GridStack . getElement ( els ) as GridHTMLElement ;
17081718 }
17091719 /** @internal */
17101720 private static getGridElements ( els : string | HTMLElement = '.grid-stack' ) : GridHTMLElement [ ] {
1711- return ( typeof els === 'string' ) ? Array . from ( document . querySelectorAll ( els ) ) : [ els ] ;
1721+ return GridStack . getElements ( els ) as GridHTMLElement [ ] ;
17121722 }
17131723
17141724 /** @internal initialize margin top/bottom/left/right and units */
@@ -1755,7 +1765,7 @@ export class GridStack {
17551765
17561766 /** @internal called to update an element(s) attributes and node values */
17571767 private _updateAttr ( els : GridStackElement , val : number , attr : string , field : string ) : GridStack {
1758- this . getElements ( els ) . forEach ( el => {
1768+ GridStack . getElements ( els ) . forEach ( el => {
17591769 if ( val ) {
17601770 el . setAttribute ( attr , String ( val ) ) ;
17611771 } else {
0 commit comments