WikiPages controls
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user