dual-listbox
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "dual-listbox", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Dual listbox for multi-select elements", | ||
@@ -5,0 +5,0 @@ "main": "dist/dual-listbox.js", |
@@ -22,7 +22,11 @@ const MAIN_BLOCK = 'dual-listbox'; | ||
this.setDefaults(); | ||
this.select = document.querySelector(selector); | ||
this.selected = []; | ||
this.available = []; | ||
if (this.isDomElement(selector)) { | ||
this.select = selector; | ||
} else { | ||
this.select = document.querySelector(selector); | ||
} | ||
this._initOptions(options); | ||
@@ -443,2 +447,13 @@ this._initReusableElements(); | ||
} | ||
/** | ||
* @Private | ||
* Returns true if argument is a DOM element | ||
*/ | ||
isDomElement(o) { | ||
return ( | ||
typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2 | ||
o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName === "string" | ||
); | ||
} | ||
} | ||
@@ -445,0 +460,0 @@ |
@@ -292,2 +292,11 @@ import DualListbox, { DualListbox as DualListbox2 } from '../src/dual-listbox.js'; | ||
}); | ||
it('should be able to create object from DOM element', () => { | ||
let domParent = document.createElement("div"); | ||
domParent.innerHTML = FIXTURE_FILLED_SELECT; | ||
let dlb = new DualListbox(domParent.getElementsByTagName('select')[0]); | ||
expect(dlb.available.length).toBe(10); | ||
expect(dlb.selected.length).toBe(0); | ||
}); | ||
}); |
71384
870