mirror of
https://github.com/esiur/iui.git
synced 2025-05-06 06:42:58 +00:00
dropdown
This commit is contained in:
parent
0709891cf0
commit
19917791df
@ -24,6 +24,10 @@ export default IUI.module(class Layout extends HTMLElement// IUIElement
|
|||||||
// this.style.display = "none";
|
// this.style.display = "none";
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
async create() {
|
||||||
|
await super.create();
|
||||||
|
}
|
||||||
|
|
||||||
static getHTML(el, removeSelf = false) {
|
static getHTML(el, removeSelf = false) {
|
||||||
for (var i = 0; i < el.children.length; i++)
|
for (var i = 0; i < el.children.length; i++)
|
||||||
if (el.children[i] instanceof Layout) {
|
if (el.children[i] instanceof Layout) {
|
||||||
|
@ -1,26 +1,53 @@
|
|||||||
import IUIElement from "../Core/IUIElement.js";
|
import IUIElement from "../Core/IUIElement.js";
|
||||||
import { IUI } from "../Core/IUI.js";
|
import { IUI } from "../Core/IUI.js";
|
||||||
|
import Layout from "../Data/Layout.js";
|
||||||
|
import Menu from "./Menu.js";
|
||||||
export default IUI.module(class DropDown extends IUIElement {
|
export default IUI.module(class DropDown extends IUIElement {
|
||||||
|
|
||||||
|
visible = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({"direction": "down" });
|
super({"direction": "down" });
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
this._register("visible");
|
this._register("visible");
|
||||||
|
|
||||||
this.visible = false;
|
|
||||||
|
|
||||||
// this.classList.add(this.cssClass + "-" + this.direction);
|
}
|
||||||
|
|
||||||
this.menu = this.getElementsByClassName(this.cssClass + "-menu")[0];
|
|
||||||
|
|
||||||
|
|
||||||
//this.arrow = document.createElement("div");
|
|
||||||
//this.arrow.className = this.customClass + "-arrow";
|
|
||||||
|
|
||||||
|
async create()
|
||||||
|
{
|
||||||
|
await super.create();
|
||||||
|
|
||||||
//this.el.appendChild(this.arrow);
|
this.menu = new Menu({ cssClass: this.cssClass + "-menu", "target-class": "" });
|
||||||
|
|
||||||
|
let layout = Layout.get(this, "div", true, true);
|
||||||
|
|
||||||
|
if (layout != null && layout.label != undefined && layout.menu != undefined) {
|
||||||
|
this.label = layout.label.node;
|
||||||
|
this.menu.appendChild(layout.menu.node);
|
||||||
|
}
|
||||||
|
else if (layout != null && layout.null != null)
|
||||||
|
{
|
||||||
|
this.label = layout.null.node;
|
||||||
|
this.menu.appendChild(layout.null.node.cloneNode(true));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.label = document.createElement("div");
|
||||||
|
this.label.innerHTML = this.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.label.className = this.cssClass + "-label";
|
||||||
|
|
||||||
|
this.appendChild(this.label);
|
||||||
|
|
||||||
|
let self = this;
|
||||||
|
|
||||||
|
this.label.addEventListener("click", function (e) {
|
||||||
|
self.show();
|
||||||
|
});
|
||||||
|
|
||||||
if (this.getAttribute("fixed"))
|
if (this.getAttribute("fixed"))
|
||||||
{
|
{
|
||||||
@ -28,8 +55,6 @@ export default IUI.module(class DropDown extends IUIElement {
|
|||||||
document.body.appendChild(this.menu);
|
document.body.appendChild(this.menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
//this.el.appendChild(this.menu);
|
|
||||||
|
|
||||||
this.addEventListener("click", function (e) {
|
this.addEventListener("click", function (e) {
|
||||||
var t = e.target
|
var t = e.target
|
||||||
do {
|
do {
|
||||||
@ -40,25 +65,19 @@ export default IUI.module(class DropDown extends IUIElement {
|
|||||||
self.setVisible(!self.visible);
|
self.setVisible(!self.visible);
|
||||||
});
|
});
|
||||||
|
|
||||||
IUI._menus.push(this);
|
|
||||||
|
|
||||||
/*
|
app.appendChild(this.menu);
|
||||||
document.body.addEventListener("click", function(e)
|
|
||||||
{
|
if (app.loaded)
|
||||||
if (!self.visible)
|
{
|
||||||
return;
|
await IUI.create(this.menu);
|
||||||
|
|
||||||
var x = e.target;
|
IUI.bind(this.menu, false, "menu", this.__i_bindings?.scope, false);
|
||||||
do {
|
// update referencing
|
||||||
if (x == self.menu || x == self.el)
|
this.__i_bindings?.scope?.refs?._build();
|
||||||
return;
|
|
||||||
} while (x = x.parentNode)
|
await IUI.created(this.menu);
|
||||||
|
}
|
||||||
if (e.target.id == "iui_app_background")
|
|
||||||
return;
|
|
||||||
|
|
||||||
self.setVisible(false);
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set fixed(value) {
|
set fixed(value) {
|
||||||
@ -79,6 +98,18 @@ export default IUI.module(class DropDown extends IUIElement {
|
|||||||
return this.setVisible(true);
|
return this.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
disconnectedCallback() {
|
||||||
|
if (this.menu)
|
||||||
|
app.removeChild(this.menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
connectedCallback(){
|
||||||
|
super.connectedCallback();
|
||||||
|
if (this.menu)
|
||||||
|
app.appendChild(this.menu);
|
||||||
|
}
|
||||||
|
|
||||||
getOffset() {
|
getOffset() {
|
||||||
var el = this;
|
var el = this;
|
||||||
var _x = 0;
|
var _x = 0;
|
||||||
@ -94,12 +125,46 @@ export default IUI.module(class DropDown extends IUIElement {
|
|||||||
return { top: _y, left: _x, width: this.clientWidth, height: this.clientHeight };
|
return { top: _y, left: _x, width: this.clientWidth, height: this.clientHeight };
|
||||||
}
|
}
|
||||||
|
|
||||||
set data(value) {
|
|
||||||
// console.log("DD", value);
|
|
||||||
super.data = value;
|
|
||||||
// console.log("VV", this._uiBindings, this._dataBindings);
|
|
||||||
}
|
|
||||||
setVisible(visible) {
|
setVisible(visible) {
|
||||||
|
|
||||||
|
if (visible == this.visible)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (visible) {
|
||||||
|
// show menu
|
||||||
|
var rect = this.getBoundingClientRect();
|
||||||
|
this.menu.style.width = (this.clientWidth - this._computeMenuOuterWidth()) + "px";
|
||||||
|
this.menu.style.paddingTop = rect.height + "px";
|
||||||
|
this.menu.setVisible(true, rect.left, rect.top);//, this.menu);
|
||||||
|
this.visible = true;
|
||||||
|
|
||||||
|
this.classList.add(this.cssClass + "-visible");
|
||||||
|
|
||||||
|
if (this._autocomplete)
|
||||||
|
setTimeout(() => {
|
||||||
|
this.textbox.focus();
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.visible = false;
|
||||||
|
this.classList.remove(this.cssClass + "-visible");
|
||||||
|
|
||||||
|
this.menu.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
//this.textbox.focus();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_computeMenuOuterWidth() {
|
||||||
|
return this.menu.offsetWidth - this.menu.clientWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
setVisibleOld(visible) {
|
||||||
this.visible = visible;
|
this.visible = visible;
|
||||||
|
|
||||||
if (!this.fixed) {
|
if (!this.fixed) {
|
||||||
|
@ -35,6 +35,7 @@ export default IUI.module(class Select extends IUIElement {
|
|||||||
if (!this.searchlist && this.menu)
|
if (!this.searchlist && this.menu)
|
||||||
app.appendChild(this.menu);
|
app.appendChild(this.menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
get autocomplete() {
|
get autocomplete() {
|
||||||
return this._autocomplete;
|
return this._autocomplete;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user