@wernfried/daterangepicker 5.4.1 → 5.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ class DateRangePicker {
5
5
  constructor(element, options, cb) {
6
6
  if (typeof element === "string" && document.querySelectorAll(element).length > 1)
7
7
  throw new RangeError(`Option 'element' must match to one element only`);
8
- this.parentEl = "body";
8
+ this.parentEl = document.querySelector("body");
9
9
  this.element = element instanceof HTMLElement ? element : document.querySelector(element);
10
10
  this.isInputText = this.element instanceof HTMLInputElement && this.element.type === "text";
11
11
  this.button = null;
@@ -160,7 +160,11 @@ class DateRangePicker {
160
160
  options.template = template.join("");
161
161
  this.container = createElementFromHTML(options.template);
162
162
  }
163
- this.parentEl = document.querySelector(typeof options.parentEl === "string" ? options.parentEl : this.parentEl);
163
+ if (options.parentEl instanceof HTMLElement) {
164
+ this.parentEl = options.parentEl;
165
+ } else if (typeof options.parentEl === "string") {
166
+ this.parentEl = document.querySelector(options.parentEl) ?? this.parentEl;
167
+ }
164
168
  this.parentEl.appendChild(this.container);
165
169
  if (typeof options.timePicker === "boolean")
166
170
  this.timePicker = options.timePicker;
@@ -2364,21 +2368,34 @@ function outerHeight(el, withMargin = false) {
2364
2368
  const style = getComputedStyle(el);
2365
2369
  return el.offsetHeight + parseFloat(style.marginTop) + parseFloat(style.marginBottom);
2366
2370
  }
2367
- function daterangepicker(elements, options, callback) {
2368
- if (typeof elements === "string")
2369
- return daterangepicker(document.querySelectorAll(elements), options, callback);
2370
- if (elements instanceof HTMLElement)
2371
- elements = [elements];
2372
- if (elements instanceof NodeList || elements instanceof HTMLCollection)
2373
- elements = Array.from(elements);
2374
- if (elements == null)
2375
- return new DateRangePicker(null, options || {}, callback);
2376
- elements.forEach((el) => {
2377
- if (el._daterangepicker && typeof el._daterangepicker.remove === "function")
2378
- el._daterangepicker.remove();
2379
- el._daterangepicker = new DateRangePicker(el, options || {}, callback);
2380
- });
2381
- return elements.length === 1 ? elements[0] : elements;
2371
+ function daterangepicker(element, options, callback) {
2372
+ if (element instanceof HTMLElement) {
2373
+ return new DateRangePicker(element, options || {}, callback);
2374
+ } else if (elements instanceof NodeList || element instanceof HTMLCollection) {
2375
+ const ret = [];
2376
+ for (const el of Array.from(element)) {
2377
+ if (el._daterangepicker && typeof el._daterangepicker.remove === "function")
2378
+ el._daterangepicker.remove();
2379
+ ret.push(new DateRangePicker(el, options || {}, callback));
2380
+ }
2381
+ return ret;
2382
+ } else if (typeof element === "string") {
2383
+ if (document.querySelectorAll(element).length > 1) {
2384
+ const ret = [];
2385
+ for (const el of Array.from(document.querySelectorAll(element))) {
2386
+ if (el._daterangepicker && typeof el._daterangepicker.remove === "function")
2387
+ el._daterangepicker.remove();
2388
+ ret.push(new DateRangePicker(el, options || {}, callback));
2389
+ }
2390
+ return ret;
2391
+ } else if (document.querySelectorAll(element).length === 1) {
2392
+ return new DateRangePicker(element, options || {}, callback);
2393
+ } else {
2394
+ return null;
2395
+ }
2396
+ } else {
2397
+ return null;
2398
+ }
2382
2399
  }
2383
2400
  function getDateRangePicker(target) {
2384
2401
  if (typeof target === "string")