WikiPages controls

This commit is contained in:
2022-04-13 22:54:23 +00:00
parent 7365248bf3
commit dc745e91da
9 changed files with 99 additions and 81 deletions

View File

@ -2,6 +2,7 @@
class WikiDropdownHelper {
constructor(element, onChange) {
this.onSelectWiki = onChange;
this.dd = element;
this.dd.addEventListener('change', e=>onChange(+e.target.value||0));
}
@ -12,17 +13,22 @@ class WikiDropdownHelper {
return this;
}
add(text, value, set=false) {
var option = document.createElement("option");
option.text = text;
option.value = value;
this.dd.appendChild(option);
if (this.find(value)<=0) {
var option = document.createElement("option");
option.text = text;
option.value = value;
this.dd.appendChild(option);
}
if ( set ) {
this.set(value);
}
return this;
}
find(value) {
return Array.from(this.dd.options).findIndex(option=>option.value==value);
}
delete(value) {
let index = Array.from(this.dd.options).findIndex(option=>option.value==value);
let index = this.find(value);
if (index>0) {
this.dd.remove(index);
}
@ -39,8 +45,8 @@ class WikiDropdownHelper {
};
}
set(value) {
this.dd.parentElement.value=value;
// this.onSelectWiki(value);
this.dd.value=value;
this.onSelectWiki(value);
return this;
}
}