mirror of
https://github.com/suk-ws/ph-Bookshelf.git
synced 2025-01-31 21:13:00 +08:00
后端大改 progress-2
This commit is contained in:
parent
25a208b273
commit
882362e31a
@ -282,7 +282,7 @@ body {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
#sidebar > #noscript-warn {
|
||||
#sidebar > .warnings {
|
||||
flex-shrink: 0;
|
||||
padding: 1rem;
|
||||
border-radius: 0.5rem;
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
40
src/Web/Html/Main/Heading.php
Normal file
40
src/Web/Html/Main/Heading.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web\Html\Main;
|
||||
|
||||
use DOMElement;
|
||||
use SukWs\Bookshelf\Web\HtmlPage;
|
||||
|
||||
class Heading {
|
||||
|
||||
public HtmlPage $root;
|
||||
public MainContainer $parent;
|
||||
|
||||
public DOMElement $__self;
|
||||
|
||||
public DOMElement $_page_tools;
|
||||
public DOMElement $_page_tools_sidebar_toggle;
|
||||
|
||||
public function __construct (MainContainer $parent) {
|
||||
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
43
src/Web/Html/Main/MainContainer.php
Normal file
43
src/Web/Html/Main/MainContainer.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web\Html\Main;
|
||||
|
||||
use DOMElement;
|
||||
use SukWs\Bookshelf\Web\Html\Body;
|
||||
use SukWs\Bookshelf\Web\HtmlPage;
|
||||
|
||||
class MainContainer {
|
||||
|
||||
public HtmlPage $root;
|
||||
public Body $parent;
|
||||
|
||||
public DOMElement $__main;
|
||||
|
||||
public DOMElement $_anchor_top;
|
||||
|
||||
public Heading $_heading;
|
||||
|
||||
// public DOMElement $_article;
|
||||
|
||||
public function __construct (Body $parent) {
|
||||
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
@ -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]<sidebar>: 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');
|
||||
|
28
src/Web/Html/Sidebar/WebError.php
Normal file
28
src/Web/Html/Sidebar/WebError.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace SukWs\Bookshelf\Web\Html\Sidebar;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
|
||||
class WebError {
|
||||
|
||||
/* @var string[] */ public array $errorMessages = array();
|
||||
|
||||
public function addErrorMessage(string $message): void {
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user