Skip to content

Commit

Permalink
simplepicker: Fix logic of the constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
priyank-p committed Aug 26, 2020
1 parent 131c215 commit 8cde1bf
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,25 @@ class SimplePicker {
private $ok: HTMLElement;
private $displayDateElements: HTMLElement[];

constructor(elOrOpts?: SimplePickerOpts | string | HTMLElement, opts?: SimplePickerOpts) {
let el: HTMLElement | string | undefined;
if (typeof elOrOpts === 'object') {
opts = elOrOpts as SimplePickerOpts;
el = undefined;
}

el = (elOrOpts as HTMLElement | string) || 'body';
if (typeof el === 'string') {
el = document.querySelector(el) as HTMLElement;
constructor(arg1?: HTMLElement | string | SimplePickerOpts, arg2?: SimplePickerOpts) {
let el: HTMLElement | undefined = undefined;
let opts: SimplePickerOpts | undefined = arg2;

if (typeof arg1 === 'string') {
const element = <HTMLElement> document.querySelector(arg1);
if (element !== null) {
el = element;
} else {
throw new Error('Invalid selector passed to SimplePicker!');
}
} else if (arg1 instanceof HTMLElement) {
el = arg1;
} else if (typeof arg1 === 'object') {
opts = arg1 as SimplePickerOpts;
}

if (!el) {
throw new Error('SimplePicker: Valid selector or element must be passed!');
el = <HTMLElement> document.querySelector('body');
}

if (!opts) {
Expand Down

0 comments on commit 8cde1bf

Please sign in to comment.