fix TabContainer bugs and improve CheckBox

This commit is contained in:
Michael Becker 2024-02-07 23:31:12 -05:00
parent dc8ba8fe3c
commit 74e3c0908b
4 changed files with 66 additions and 25 deletions

View File

@ -19,8 +19,12 @@ function CheckBox(parentElement)
}
if (!changed) return;
if (!this.__inhibit_update)
{
System.RaiseEvent(this.ParentElement, "change", null);
}
}
this.GetChecked = function()
{
return this.mvarChecked;
@ -35,9 +39,8 @@ function CheckBox(parentElement)
child.NativeObject = this;
child.addEventListener("click", function(e)
{
child.NativeObject.ToggleChecked();
this.NativeObject.ToggleChecked();
});
var fa = document.createElement("i");
fa.className = "fa fa-check";
child.appendChild(fa);
@ -46,10 +49,26 @@ function CheckBox(parentElement)
parentElement.parentNode.insertBefore(child, parentElement);
this.NewParentElement = child;
parentElement.NativeObject = this;
parentElement.NativeObject.__inhibit_update = false;
parentElement.addEventListener("change", function(e)
{
parentElement.NativeObject.SetChecked(parentElement.checked);
if (!this.NativeObject.__inhibit_update)
{
this.NativeObject.__inhibit_update = true;
this.NativeObject.SetChecked(this.checked);
this.NativeObject.__inhibit_update = false;
}
/*
if (this.hasAttribute("checked"))
{
System.ClassList.Add(this.NativeObject.ParentElement, "uwt-checked");
}
else
{
System.ClassList.Remove(this.NativeObject.ParentElement, "uwt-checked");
}
*/
});
this.SetChecked(parentElement.checked);
}

View File

@ -18,26 +18,26 @@ function TabContainer(parentElement)
var selectedIndex = -1;
for (var i = 0; i < tabs.childNodes.length; i++)
{
if (System.ClassList.Contains(tabs.childNodes[i], "Selected"))
if (System.ClassList.Contains(tabs.childNodes[i], "uwt-selected"))
{
System.ClassList.Remove(tabs.childNodes[i], "Selected");
System.ClassList.Remove(tabs.childNodes[i], "uwt-selected");
}
if (tabs.childNodes[i] === tab)
{
selectedIndex = i;
System.ClassList.Add(tabs.childNodes[i], "Selected");
System.ClassList.Add(tabs.childNodes[i], "uwt-selected");
}
}
for (var i = 0; i < tabPages.childNodes.length; i++)
{
if (selectedIndex > -1 && selectedIndex < tabPages.childNodes.length && i == selectedIndex)
{
System.ClassList.Add(tabPages.childNodes[i], "Selected");
System.ClassList.Add(tabPages.childNodes[i], "uwt-selected");
}
else
{
System.ClassList.Remove(tabPages.childNodes[i], "Selected");
System.ClassList.Remove(tabPages.childNodes[i], "uwt-selected");
}
}
@ -76,7 +76,7 @@ function TabContainer(parentElement)
}
window.addEventListener("load", function(e)
{
var tbss = document.getElementsByClassName("TabContainer");
var tbss = document.getElementsByClassName("uwt-tabcontainer");
for (var i = 0; i < tbss.length; i++)
{
tbss[i].ObjectReference = new TabContainer(tbss[i]);

View File

@ -572,7 +572,7 @@
$this->BeginContent();
if (is_callable($this->Content))
{
call_user_func($this->Content, $this, $this->ExtraData);
call_user_func_array($this->Content, array($this, $this->ExtraData));
}
else if (is_string($this->Content))
{

View File

@ -43,6 +43,7 @@
public $Title;
public $Controls;
public $Content;
public $Visible;
@ -66,6 +67,8 @@
{
$this->ID = $id;
$this->Title = $title;
$this->Content = null;
$this->Controls = array();
$this->ImageURL = $imageURL;
$this->TargetURL = $targetURL;
$this->TargetScript = $targetScript;
@ -117,7 +120,7 @@
{
$this->Attributes[] = new WebControlAttribute("data-onclienttabchanged", $this->OnClientTabChanged);
}
$this->ClassList[] = "TabContainer";
$this->ClassList[] = "uwt-tabcontainer";
if (is_string($this->TabPosition))
{
@ -175,19 +178,20 @@
$this->Controls = array();
$ulTabs = new HTMLControl("ul");
$ulTabs->ClassList[] = "Tabs";
$ulTabs->ClassList[] = "uwt-tabcontainer-tabs";
$j = 0;
foreach ($this->TabPages as $tabPage)
{
$liTab = new HTMLControl("li");
$liTab->ClassList[] = "uwt-tabcontainer-tab";
if ((is_bool($tabPage->Visible) && $tabPage->Visible) || (is_string($tabPage->Visible) && $tabPage->Visible != "false"))
{
$liTab->ClassList[] = "Visible";
$liTab->ClassList[] = "uwt-visible";
}
if (($this->SelectedTabID != null && $tabPage->ID == $this->SelectedTabID) || ($this->SelectedTab != null && ($tabPage->ID == $this->SelectedTab->ID)))
if (($this->SelectedTab == $tabPage) || (($this->SelectedTabID != null && $tabPage->ID == $this->SelectedTabID) || ($this->SelectedTab != null && ($tabPage->ID != null && $tabPage->ID == $this->SelectedTab->ID))))
{
$liTab->ClassList[] = "Selected";
$liTab->ClassList[] = "uwt-selected";
}
$aTab = new Anchor();
@ -202,24 +206,42 @@
$this->Controls[] = $ulTabs;
$divTabPages = new HTMLControl("div");
$divTabPages->ClassList[] = "TabPages";
$divTabPages->ClassList[] = "uwt-tabcontainer-tabpages";
foreach ($this->TabPages as $tabPage)
{
$divTabPage = new HTMLControl("div");
$divTabPage->ClassList[] = "TabPage";
if (($this->SelectedTabID != null && $tabPage->ID == $this->SelectedTabID) || ($this->SelectedTab != null && ($tabPage->ID == $this->SelectedTab->ID)))
$divTabPage->ClassList[] = "uwt-tabpage";
if (($this->SelectedTab == $tabPage) || (($this->SelectedTabID != null && $tabPage->ID == $this->SelectedTabID) || ($this->SelectedTab != null && ($tabPage->ID != null && $tabPage->ID == $this->SelectedTab->ID))))
{
$divTabPage->ClassList[] = "Selected";
$divTabPage->ClassList[] = "uwt-selected";
}
if (isset($tabPage->Content))
if ($tabPage->Content !== null)
{
if (is_callable($tabPage->Content))
{
$divTabPage->ExtraData = $tabPage;
$divTabPage->Content = function($sender, $extraData)
{
$tabPage2 = $extraData;
if (is_callable($tabPage2->Content))
{
call_user_func_array($tabPage2->Content, array($tabPage2, $tabPage2->ExtraData));
}
};
}
else
{
$divTabPage->Content = $tabPage->Content;
}
}
else
{
foreach ($tabPage->Controls as $ctl)
{
$divTabPage->Controls[] = $ctl;
}
}
$divTabPages->Controls[] = $divTabPage;
}
$this->Controls[] = $divTabPages;