From 882362e31ae969cd789b639bae1626c2093baf17 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Sat, 4 Mar 2023 17:03:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E5=A4=A7=E6=94=B9=20progress?= =?UTF-8?q?-2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/web/main.css | 2 +- src/Web/Html/Body.php | 21 +++----------- src/Web/Html/Main/Heading.php | 40 +++++++++++++++++++++++++++ src/Web/Html/Main/MainContainer.php | 43 +++++++++++++++++++++++++++++ src/Web/Html/Sidebar/Sidebar.php | 31 ++++++++++++++++++--- src/Web/Html/Sidebar/WebError.php | 28 +++++++++++++++++++ 6 files changed, 143 insertions(+), 22 deletions(-) create mode 100644 src/Web/Html/Main/Heading.php create mode 100644 src/Web/Html/Main/MainContainer.php create mode 100644 src/Web/Html/Sidebar/WebError.php diff --git a/assets/web/main.css b/assets/web/main.css index f59bc00..710b4ca 100644 --- a/assets/web/main.css +++ b/assets/web/main.css @@ -282,7 +282,7 @@ body { margin-bottom: 1rem; } -#sidebar > #noscript-warn { +#sidebar > .warnings { flex-shrink: 0; padding: 1rem; border-radius: 0.5rem; diff --git a/src/Web/Html/Body.php b/src/Web/Html/Body.php index 1211723..5babe0e 100644 --- a/src/Web/Html/Body.php +++ b/src/Web/Html/Body.php @@ -4,6 +4,7 @@ namespace SukWs\Bookshelf\Web\Html; use DOMDocument; use DOMElement; +use SukWs\Bookshelf\Web\Html\Main\MainContainer; use SukWs\Bookshelf\Web\Html\Sidebar\Sidebar; use SukWs\Bookshelf\Web\HtmlPage; use SukWs\Bookshelf\Web\WebWarn; @@ -15,6 +16,7 @@ class Body { public DOMElement $__self; public Sidebar $_sidebar; + public MainContainer $_main; public function __construct (HtmlPage $root) { @@ -22,12 +24,14 @@ class Body { $this->__self = $root->document->createElement("body"); $this->_sidebar = new Sidebar($this); + $this->_main = new MainContainer($this); } public function build (): DOMElement { $this->__self->appendChild($this->_sidebar->build()); + $this->__self->appendChild($this->_main->build()); foreach ($this->root->res_manager->getJavascriptLazyloadsDOM($this->root->document) as $script) $this->__self->appendChild($script); @@ -39,21 +43,4 @@ class Body { } - private static function getMain (DOMDocument $root): DOMElement { - - /* @var */ $main = $root->createElement("main"); - $main->setAttribute("id", "main"); - - /* @var */ $main_heading = $main->appendChild($root->createElement("div")); - $main_heading->setAttribute("id", "main-heading"); - - /* @var */ $page_tools = $main_heading->appendChild($root->createElement("div")); - $page_tools->setAttribute("id", "page-tools"); - /* @var */ $tool_sidebar_show = $page_tools->appendChild($root->createElement("button", "☰")); - $tool_sidebar_show->setAttribute("id", "sidebar-show"); - - return $main; - - } - } diff --git a/src/Web/Html/Main/Heading.php b/src/Web/Html/Main/Heading.php new file mode 100644 index 0000000..f560ab8 --- /dev/null +++ b/src/Web/Html/Main/Heading.php @@ -0,0 +1,40 @@ +parent = $parent; + $this->root = $parent->root; + + $this->__self = $this->root->document->createElement('div'); + $this->__self->setAttribute('id', 'main-heading'); + + $this->_page_tools = $this->root->document->createElement('div'); + $this->_page_tools->setAttribute('id', 'page-tools'); + + $this->_page_tools_sidebar_toggle = $this->root->document->createElement('button', "☰"); + $this->_page_tools_sidebar_toggle->setAttribute('id', 'sidebar-show'); + + } + + public function build (): DOMElement { + $this->_page_tools->appendChild($this->_page_tools_sidebar_toggle); + $this->__self->appendChild($this->_page_tools); + return $this->__self; + } + +} \ No newline at end of file diff --git a/src/Web/Html/Main/MainContainer.php b/src/Web/Html/Main/MainContainer.php new file mode 100644 index 0000000..e40da42 --- /dev/null +++ b/src/Web/Html/Main/MainContainer.php @@ -0,0 +1,43 @@ +parent = $parent; + $this->root = $parent->root; + + $this->__main = $this->root->document->createElement('main'); + $this->__main->setAttribute('id', 'main'); + + $this->_anchor_top = $this->root->document->createElement('a'); + $this->_anchor_top->setAttribute('id', 'top'); + + $this->_heading = new Heading($this); + + } + + public function build (): DOMElement { + $this->__main->appendChild($this->_anchor_top); + $this->__main->appendChild($this->_heading->build()); + return $this->__main; + } + +} \ No newline at end of file diff --git a/src/Web/Html/Sidebar/Sidebar.php b/src/Web/Html/Sidebar/Sidebar.php index 216e783..2c34434 100644 --- a/src/Web/Html/Sidebar/Sidebar.php +++ b/src/Web/Html/Sidebar/Sidebar.php @@ -5,20 +5,25 @@ namespace SukWs\Bookshelf\Web\Html\Sidebar; use DOMElement; use SukWs\Bookshelf\Web\Html\Body; use SukWs\Bookshelf\Web\HtmlPage; -use SukWs\Bookshelf\Web\WebWarn; class Sidebar { + const WARNING_NOSCRIPT = "For now, javascript must be enabled to view this site!!"; + public HtmlPage $root; public Body $parent; + public WebError $web_error; + public DOMElement $_sidebar_container; public DOMElement $_sidebar; public DOMElement $_sidebar_site_title_node; public ?string $_sidebar_site_title_value; + public DOMElement $_warning_noscript; + public bool $show_sidebar; public function __construct (Body $parent) { @@ -26,12 +31,18 @@ class Sidebar { $this->parent = $parent; $this->root = $parent->root; + $this->web_error = new WebError(); + $this->_sidebar_container = $this->root->document->createElement('div'); $this->_sidebar_container->setAttribute('id', 'nav-container'); $this->_sidebar = $this->root->document->createElement('nav'); $this->_sidebar->setAttribute('id', 'sidebar'); - $this->show_sidebar = false; + $this->show_sidebar = true; + + $this->_warning_noscript = $this->root->document->createElement('noscript'); + $this->_warning_noscript->setAttribute('class', 'warnings'); + $this->_warning_noscript->appendChild($this->root->document->createTextNode(self::WARNING_NOSCRIPT)); $this->_sidebar_site_title_node = $this->root->document->createElement('a'); $this->_sidebar_site_title_node->setAttribute('id','site-title'); @@ -52,14 +63,26 @@ class Sidebar { public function build (): DOMElement { + // === prebuild if ($this->_sidebar_site_title_value == null) { - $this->_sidebar_site_title_value = "...not set"; - WebWarn::output("[Web]: Site Title not set yet."); + $this->_sidebar_site_title_value = "..."; + $this->web_error->addErrorMessage("Site Title not set."); } + + // === build + + // -- warning: overall + foreach ($this->web_error->getErrorsAsSidebarWarning($this->root->document) as $error_dom) { + $this->_sidebar->appendChild($error_dom); + } + // -- warning: noscript + $this->_sidebar->appendChild($this->_warning_noscript); + // -- site title $this->_sidebar_site_title_node->appendChild( $this->root->document->createTextNode($this->_sidebar_site_title_value)); $this->_sidebar->appendChild($this->_sidebar_site_title_node); + // == sidebar body $this->_sidebar_container->appendChild($this->_sidebar); if ($this->show_sidebar) $this->_sidebar_container->setAttribute('class', 'show-sidebar'); diff --git a/src/Web/Html/Sidebar/WebError.php b/src/Web/Html/Sidebar/WebError.php new file mode 100644 index 0000000..617ab13 --- /dev/null +++ b/src/Web/Html/Sidebar/WebError.php @@ -0,0 +1,28 @@ +errorMessages[] = $message; + } + + /** @return DOMElement[] */ + public function getErrorsAsSidebarWarning(DOMDocument $root): array { + $domList = array(); + foreach ($this->errorMessages as $error) { + $dom = $root->createElement('div'); + $dom->setAttribute('class', 'warnings'); + $dom->appendChild($root->createTextNode($error)); + $domList[] = $dom; + } + return $domList; + } + +} \ No newline at end of file