From 9dce749fe0369a0d8c5b440a7fdb098f5d2641c8 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 19 Nov 2024 22:50:50 -0500 Subject: [PATCH] add ListBox.js --- lib/phast/client/scripts/controls/ListBox.js | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/phast/client/scripts/controls/ListBox.js diff --git a/lib/phast/client/scripts/controls/ListBox.js b/lib/phast/client/scripts/controls/ListBox.js new file mode 100644 index 0000000..14f7fa4 --- /dev/null +++ b/lib/phast/client/scripts/controls/ListBox.js @@ -0,0 +1,36 @@ +function ListBox(parentElement) +{ + this.ParentElement = parentElement; + this.SetSelectedItem = function(li) + { + for (var i = 0; i < this.ParentElement.children.length; i++) + { + if (this.ParentElement.children[i] == li) + { + System.ClassList.Add(this.ParentElement.children[i], "uwt-selected"); + } + else + { + System.ClassList.Remove(this.ParentElement.children[i], "uwt-selected"); + } + } + }; + + for (var i = 0; i < this.ParentElement.children.length; i++) + { + this.ParentElement.children[i].NativeObject = this; + this.ParentElement.children[i].addEventListener("click", function() + { + this.NativeObject.SetSelectedItem(this); + }); + } +} + +window.addEventListener("load", function() +{ + var items = document.getElementsByClassName("uwt-listbox"); + for (var i = 0; i < items.length; i++) + { + items[i].NativeObject = new ListBox(items[i]); + } +});