diff --git a/bin/Controls/Independent/Items/Custom.js b/bin/Controls/Independent/Items/Custom.js index efbcbc6bdb0ab9d95b9c1ed38068cd49930039ad..37970253fb7c6aac832f8c88e4d276101c616999 100644 --- a/bin/Controls/Independent/Items/Custom.js +++ b/bin/Controls/Independent/Items/Custom.js @@ -111,6 +111,10 @@ define('package/quiqqer/menu/bin/Controls/Independent/Items/Custom', [ data.name = ''; } + if (typeof data.target !== 'undefined') { + this.getElm().getElement('[name="target"]').set('value', data.target); + } + if (typeof data.status === 'undefined' || data.status) { this.getElm().getElement('[name="status"]').set('checked', true); } diff --git a/bin/Controls/Independent/Items/Site.js b/bin/Controls/Independent/Items/Site.js index 90fff588a4755d1d35082a22ef44fa1860261987..7fb34a7459ad3761cf273549558f0be25e7467c9 100644 --- a/bin/Controls/Independent/Items/Site.js +++ b/bin/Controls/Independent/Items/Site.js @@ -93,6 +93,10 @@ define('package/quiqqer/menu/bin/Controls/Independent/Items/Site', [ this.getElm().getElement('[name="site"]').set('value', data.site); } + if (typeof data.target !== 'undefined') { + this.getElm().getElement('[name="target"]').set('value', data.target); + } + if (typeof data.rel !== 'undefined') { this.getElm().getElement('[name="rel"]').set('value', data.rel); } diff --git a/bin/Controls/Independent/Items/Url.js b/bin/Controls/Independent/Items/Url.js index fd267dd5bcbf380106ed8e9e9141355cf62532ef..e6d0fa3d7edbf022560f9b08d988aad3576f5e37 100644 --- a/bin/Controls/Independent/Items/Url.js +++ b/bin/Controls/Independent/Items/Url.js @@ -107,6 +107,10 @@ define('package/quiqqer/menu/bin/Controls/Independent/Items/Url', [ data.name = ''; } + if (typeof data.target !== 'undefined') { + this.getElm().getElement('[name="target"]').set('value', data.target); + } + if (typeof data.status === 'undefined' || data.status) { this.getElm().getElement('[name="status"]').set('checked', true); } diff --git a/bin/Controls/NavTabs.js b/bin/Controls/NavTabs.js index 3502529432118090c9ded0ac5a16c68bd0b77f1d..78261b445adf8e4f82afd589113bc2719e68d644 100644 --- a/bin/Controls/NavTabs.js +++ b/bin/Controls/NavTabs.js @@ -26,11 +26,16 @@ define('package/quiqqer/menu/bin/Controls/NavTabs', [ Binds: [ '$onImport', - 'toggle' + '$resize', + 'toggle', + '$mouseMoveHandler', + '$mouseDownHandler', + '$mouseUpHandler' ], options: { - animation: 'slide' + animation : 'slide', + enabledragtoscroll: false // if enabled allows users to drag to scroll nav elements }, initialize: function (options) { @@ -45,9 +50,15 @@ define('package/quiqqer/menu/bin/Controls/NavTabs', [ this.clicked = false; this.animation = 'slide'; + // drag to scroll + this.enableDragToScroll = false; + this.navPos = {left: 0, x: 0}; + this.addEvents({ onImport: this.$onImport }); + + QUI.addEvent('resize', this.$resize); }, $onImport: function () { @@ -63,6 +74,12 @@ define('package/quiqqer/menu/bin/Controls/NavTabs', [ return; } + this.enableDragToScroll = parseInt(this.getAttribute('enabledragtoscroll')); + + if (this.enableDragToScroll === 1) { + this.$initDragToScroll(); + } + // animation effect if (this.getAttribute('animation')) { switch (this.getAttribute('animation')) { @@ -126,9 +143,22 @@ define('package/quiqqer/menu/bin/Controls/NavTabs', [ const newUrl = url.split('#')[0] + '#open_' + target; history.pushState(null, null, newUrl); - } + }; this.navTabsItems.addEvent('click', clickEvent); + this.$resize(); + }, + + $resize: function () { + if (this.enableDragToScroll !== 1) { + return; + } + + if (this.navTab.scrollWidth > this.navTab.clientWidth) { + this.navTab.addEventListener('mousedown', this.$mouseDownHandler); + } else { + this.navTab.removeEventListener('mousedown', this.$mouseDownHandler); + } }, /** @@ -262,7 +292,7 @@ define('package/quiqqer/menu/bin/Controls/NavTabs', [ */ $slideFadeOut: function (Item) { return this.$animate(Item, { - opacity : 0, + opacity : 0, translateX: -5, }); @@ -282,7 +312,7 @@ define('package/quiqqer/menu/bin/Controls/NavTabs', [ return this.$animate(Item, { translateX: 0, - opacity : 1 + opacity : 1 }); }, @@ -331,6 +361,69 @@ define('package/quiqqer/menu/bin/Controls/NavTabs', [ animejs(options); }); + }, + + // region drag to scroll + + /** + * Init drag to scroll + */ + $initDragToScroll: function () { + if (this.navTab.scrollWidth <= this.navTab.clientWidth) { + return; + } + + this.navTab.addEventListener('mousedown', this.$mouseDownHandler); + }, + + /** + * Move handler + * + * @param e + */ + $mouseMoveHandler: function (e) { + // How far the mouse has been moved + const dx = e.clientX - this.navPos.x; + + if (this.navPos.x !== dx) { + this.clicked = true; + } + + // Scroll the element + this.navTab.scrollLeft = this.navPos.left - dx; + }, + + /** + * Mouse down handler + * + * @param e + */ + $mouseDownHandler: function (e) { + this.navTab.style.userSelect = 'none'; + + this.navPos = { + left: this.navTab.scrollLeft, // The current scroll + x : e.clientX, // Get the current mouse position + }; + + document.addEventListener('mousemove', this.$mouseMoveHandler); + document.addEventListener('mouseup', this.$mouseUpHandler); + }, + + /** + * Mouse up handler + */ + $mouseUpHandler: function () { + document.removeEventListener('mousemove', this.$mouseMoveHandler); + document.removeEventListener('mouseup', this.$mouseUpHandler); + + this.navTab.style.removeProperty('user-select'); + + setTimeout(() => { + this.clicked = false; + }, 50); } + + // end region }); }); \ No newline at end of file diff --git a/bricks.xml b/bricks.xml index b3b92bd2878d99e6fcd82f390f6a66fde480046f..bdff38d2d02f2f1b472b649addd095d5a95ad9cf 100644 --- a/bricks.xml +++ b/bricks.xml @@ -82,6 +82,72 @@ </settings> </brick> + <!-- Url list --> + <brick control="\QUI\Menu\UrlList"> + <title> + <locale group="quiqqer/menu" + var="menu.control.urlList.title"/> + </title> + <description> + <locale group="quiqqer/menu" + var="menu.control.urlList.description"/> + </description> + + <settings> + <setting name="display" type="select"> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.display"/> + + <option value="default"> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.display.default"/> + </option> + </setting> + + <setting name="headerText"> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.headerText"/> + </setting> + + <setting name="menuId" data-qui="package/quiqqer/menu/bin/Controls/Independent/Input" type="text"> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.menuId"/> + <description> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.menuId.desc"/> + </description> + </setting> + + <setting name="startId" class="project-site"> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.startId"/> + <description> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.startId.desc"/> + </description> + </setting> + + <setting name="icon" type="text" class="media-image" data-qui-options-cssclasses="1"> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.icon"/> + <description> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.icon.desc"/> + </description> + </setting> + + <setting name="resetLinkColor" type="checkbox"> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.resetLinkColor"/> + <description> + <locale group="quiqqer/menu" + var="menu.control.urlList.setting.resetLinkColor.desc"/> + </description> + </setting> + + </settings> + </brick> + <!-- one page nav --> <brick control="\QUI\Menu\OnePageNav"> <title> diff --git a/locale.xml b/locale.xml index 3ef0108677cb7c963cc90ada95030479d87a45ec..8edef0fe64f7f45ff7c460f4f8d888c7df6dacdd 100644 --- a/locale.xml +++ b/locale.xml @@ -192,6 +192,60 @@ <en><![CDATA[Also show pages that do not have the property Show in navigation.]]></en> </locale> + <!-- url list --> + <locale name="menu.control.urlList.title"> + <de><![CDATA[Menu: Url Liste]]></de> + <en><![CDATA[Menu: Url list]]></en> + </locale> + <locale name="menu.control.urlList.description"> + <de><![CDATA[Einfache Seitenliste, die man perfekt im Footer verwenden kann. Der Baustein wird nur die erste Ebene der Unterseiten aufbauen.]]></de> + <en><![CDATA[Simple page list that you can use perfectly in the footer. This control will build only the first level of the subpages.]]></en> + </locale> + <locale name="menu.control.urlList.setting.display"> + <de><![CDATA[Layout]]></de> + <en><![CDATA[Layout]]></en> + </locale> + <locale name="menu.control.urlList.setting.display.default"> + <de><![CDATA[Standard]]></de> + <en><![CDATA[Default]]></en> + </locale> + <locale name="menu.control.urlList.setting.headerText"> + <de><![CDATA[Titel über der Seitenliste]]></de> + <en><![CDATA[Titel above the url list]]></en> + </locale> + <locale name="menu.control.urlList.setting.menuId"> + <de><![CDATA[Menu ID]]></de> + <en><![CDATA[Menu ID]]></en> + </locale> + <locale name="menu.control.urlList.setting.menuId.desc"> + <de><![CDATA[Menu ID auswählen.]]></de> + <en><![CDATA[Select your menu]]></en> + </locale> + <locale name="menu.control.urlList.setting.startId"> + <de><![CDATA[Elternseite]]></de> + <en><![CDATA[Parent site]]></en> + </locale> + <locale name="menu.control.urlList.setting.startId.desc"> + <de><![CDATA[Bitte die Elternseite auswählen. <strong>Achtung!</strong> Wenn "Menu ID" ausgewählt ist, hat diese Option keine Auswirkung.]]></de> + <en><![CDATA[Select the parent site. <strong>Notice:</strong> if "Menu ID" is selected, this option has no effect.]]></en> + </locale> + <locale name="menu.control.urlList.setting.icon"> + <de><![CDATA[Icon]]></de> + <en><![CDATA[Icon]]></en> + </locale> + <locale name="menu.control.urlList.setting.icon.desc"> + <de><![CDATA[Wenn ein Icon ausgewählt ist, wird sie vor dem Link eingeblendet. Es werden nur FontAwesome Icons unterstützt. <strong>Tipp!</strong> Im Auswahl-Fenster kann man nach <code>right</code> filtern, falls man ein Icon in Pfeil-Stil benutzen möchte.]]></de> + <en><![CDATA[When an icon is selected, it is displayed in front of the link. Only FontAwesome icons are supported. In the selection window you can filter by <code>right</code> if you want to use an arrow-style icon.]]></en> + </locale> + <locale name="menu.control.urlList.setting.resetLinkColor"> + <de><![CDATA[Link Farbe zurücksetzen]]></de> + <en><![CDATA[Reset link color]]></en> + </locale> + <locale name="menu.control.urlList.setting.resetLinkColor.desc"> + <de><![CDATA[Wenn die Option aktiv ist, ist der Link in der gleichen Farbe, wie Seiteninhalt. Die Option beeinflusst den Mouse-Over effekt nicht. <strong>Achtung!</strong> Das benutzte Template kann die Einstellung überschreiben.]]></de> + <en><![CDATA[If the option is active, the link has the same color as the page content. This option does not affect the mouse-over effect. <strong>Caution!</strong> The template, you are using, can overwrite this setting.]]></en> + </locale> + <!-- one page nav --> <locale name="menu.control.OnePageNav.title"> <de><![CDATA[Menu: One Page Menü (für Landingpage)]]></de> diff --git a/src/QUI/Menu/Controls/Tabs.css b/src/QUI/Menu/Controls/Tabs.css index 9b29a1f489b67d98f4287cc8080e2ac0c381d365..43585b83d845ca3dc7a241be9bf6bc128e05e0e6 100644 --- a/src/QUI/Menu/Controls/Tabs.css +++ b/src/QUI/Menu/Controls/Tabs.css @@ -37,11 +37,14 @@ flex: 1; } -@media screen and (min-width: 768px) { - .quiqqer-tabsAdvanced-nav-inner.navTab__center { +/*@media screen and (min-width: 768px) {*/ + .quiqqer-tabsAdvanced-nav { + display: flex; + } + .quiqqer-tabsAdvanced-nav.navTab__center { justify-content: center; } -} +/*}*/ .quiqqer-tabsAdvanced-nav-link { padding: 1rem; @@ -119,7 +122,7 @@ /* content */ /***********/ .quiqqer-tabsAdvanced-content { - margin-top: var(--qui-spacing-xl, 2rem); + margin-top: var(--qui-spacing-2xl, 3rem); } .quiqqer-tabsAdvanced-content-item { diff --git a/src/QUI/Menu/Controls/Tabs.html b/src/QUI/Menu/Controls/Tabs.html index e5dbea4152fd8afd00902b679eaab8ccf9a38074..2ff2d9c8aa8756ac8d353c1e0cc899f6dea41c5a 100644 --- a/src/QUI/Menu/Controls/Tabs.html +++ b/src/QUI/Menu/Controls/Tabs.html @@ -16,15 +16,15 @@ {if $contentImgMaxWidth}--quiqqer-tabsAdvanced-contentImgMaxWidth: {$contentImgMaxWidth}px;{/if} {if $contentImgMinWidth}--quiqqer-tabsAdvanced-contentImgMinWidth: {$contentImgMinWidth}px;{/if} "> - <div class="quiqqer-tabsAdvanced-nav"> - <ul class="quiqqer-tabsAdvanced-nav-inner {$navAlignment} quiqqer-tab-nav"> + <div class="quiqqer-tabsAdvanced-nav {$navAlignment}"> + <ul class="quiqqer-tabsAdvanced-nav-inner quiqqer-tab-nav"> {foreach from=$entries item=entry key=key} <li class="quiqqer-tabsAdvanced-nav-item {$navTabStyleCss} {$navFillSpace} quiqqer-tab-nav-item {if $key == $active - 1}active{/if}" data-entry-nav-pos="{$key}"> <a href="#{QUI\Utils\Security\Orthos::urlEncodeString($entry.tabTitle)}" data-qui-disableTemplateScroll="1" - class="quiqqer-tabsAdvanced-nav-link {$navTabStyleCss}"> + class="quiqqer-tabsAdvanced-nav-link {$navTabStyleCss}" draggable="false"> {if isset($entry.tabIcon) && $entry.tabIcon} {image src=$entry.tabIcon width="80" height="80"} {/if} diff --git a/src/QUI/Menu/Controls/Tabs.php b/src/QUI/Menu/Controls/Tabs.php index a1bd84def8aad14c909d0bdb3314efbc9af471e7..8843b747abcd33e62759d3b9c36e220bdaddd58f 100644 --- a/src/QUI/Menu/Controls/Tabs.php +++ b/src/QUI/Menu/Controls/Tabs.php @@ -34,9 +34,10 @@ public function __construct($attributes = []) // tabs nav 'navImgHeight' => 20, // number 'navStyle' => 'imgLeft', // imgLeft, imgTop, onlyImg - 'navWrapText' => 'wrap', // wrap / noWrap; allow breaking text on space. 'noWrap' set "white-space: nowrap;" CSS property on nav text + 'navWrapText' => 'wrap', // wrap / noWrap; allow breaking text on space. 'noWrap' set "white-space: nowrap;" CSS property on nav text 'navFillSpace' => false, // it feels the available space 'navCenter' => false, + 'enableDragToScroll' => true, // tabs content 'contentImgMinWidth' => 200, // number; do not use large values, recommended is between 100 and 600 @@ -74,6 +75,8 @@ public function getBody() $active = 1; + $this->setJavaScriptControlOption('enabledragtoscroll', $this->getAttribute('enableDragToScroll')); + if ($this->getAttribute('activeEntry') && $this->getAttribute('activeEntry') > 0) { $active = $this->getAttribute('activeEntry'); } @@ -83,7 +86,7 @@ public function getBody() /* nav */ $showNavText = true; - $navWrapText = 'navText__wrap'; + $navWrapText = 'navText__wrap'; $navTabStyleCss = 'navTabStyle__imgLeft'; $navAlignment = ''; $navFillSpace = ''; @@ -116,7 +119,7 @@ public function getBody() 'active' => $active, 'navImgHeight' => $this->getAttribute('navImgHeight'), 'navStyle' => $this->getAttribute('navStyle'), - 'navWrapText' => $navWrapText, + 'navWrapText' => $navWrapText, 'navTabStyleCss' => $navTabStyleCss, 'showNavText' => $showNavText, 'navAlignment' => $navAlignment, diff --git a/src/QUI/Menu/Independent/Items/Site.php b/src/QUI/Menu/Independent/Items/Site.php index f8605f53feb335b9c97ad90962001e1a28a4afbc..9c509e3594da4c4e7d5d1376cba11a909f44a687 100644 --- a/src/QUI/Menu/Independent/Items/Site.php +++ b/src/QUI/Menu/Independent/Items/Site.php @@ -60,6 +60,7 @@ public function getSite(): ?QUI\Projects\Site $Project = $Site->getProject(); $langId = $Site->getId($current); $LangProject = QUI::getProject($Project->getName(), $current); + return $LangProject->get($langId); } catch (QUI\Exception $exception) { return null; @@ -115,9 +116,15 @@ public function getTitle(QUI\Locale $Locale = null): string } try { - $data = $this->getCustomData(); + $data = $this->getCustomData(); + + if (!$data || !isset($data['site'])) { + return ''; + } + $siteUrl = $data['site']; $Site = QUI\Projects\Site\Utils::getSiteByLink($siteUrl); + return $Site->getAttribute('title'); } catch (QUI\Exception $Exception) { } diff --git a/src/QUI/Menu/SidebarDropDownMenu.Independent.Simple.html b/src/QUI/Menu/SidebarDropDownMenu.Independent.Simple.html index bdf462007790918cefcb0dead8d6cb205294ea6b..7fec10d670c577c54d3863f11ba079f71a7566f7 100644 --- a/src/QUI/Menu/SidebarDropDownMenu.Independent.Simple.html +++ b/src/QUI/Menu/SidebarDropDownMenu.Independent.Simple.html @@ -86,6 +86,7 @@ {if $level == 1} <script> + (function() { let QuiIndependentMenu = document.getElement('.quiqqer-sidebar-dropdown-navigation'); let quiIndependentUrls = QuiIndependentMenu.getElements('.quiqqer-navigation-link'); const setPath = function (Elm) { @@ -124,5 +125,6 @@ setPath(LiElm); } }); + })(); </script> {/if} \ No newline at end of file diff --git a/src/QUI/Menu/UrlList.Default.css b/src/QUI/Menu/UrlList.Default.css new file mode 100644 index 0000000000000000000000000000000000000000..a839faa276017fc1f1cb1dfebc7d82a8531240b1 --- /dev/null +++ b/src/QUI/Menu/UrlList.Default.css @@ -0,0 +1,25 @@ +.quiqqer-urlList-entries { + padding-left: 0; + margin: 0 0 1em 0; +} + +.quiqqer-urlList-entry { + padding-left: 0; + margin: 0 0 0.5em 0; +} + +.quiqqer-urlList-entry-link__resetLinkColor { + display: inline-flex; +} + +/* icon */ +.quiqqer-urlList-entry-link-icon { + margin-right: 0.5em; + flex-shrink: 0; + line-height: inherit; +} + +/* reset link */ +.quiqqer-urlList-entry-link__resetLinkColor:not(:hover, :focus) { + color: inherit; +} \ No newline at end of file diff --git a/src/QUI/Menu/UrlList.Default.html b/src/QUI/Menu/UrlList.Default.html new file mode 100644 index 0000000000000000000000000000000000000000..4e3947a15a0454f3fab3b26053394a6f52b5d49d --- /dev/null +++ b/src/QUI/Menu/UrlList.Default.html @@ -0,0 +1,33 @@ +{if $this->getAttribute('showTitle') && $this->getAttribute('frontendTitle')} + <header class="control-header"> + <h2>{$this->getAttribute('frontendTitle')}</h2> + </header> +{/if} + +{if $this->getAttribute('content') != ""} + <div class="control-content"> + {$this->getAttribute('content')} + </div> +{/if} + +{if $headerText} + <h5 class="quiqqer-urlList-title"> + {$headerText} + </h5> +{/if} +{strip} + {if count($children)} + <ul class="quiqqer-urlList-entries list-unstyled"> + {foreach from=$children item=Child} + <li class="quiqqer-urlList-entry"> + <a href="{url site=$Child}" class="quiqqer-urlList-entry-link {$restLinkColorCss}"> + {if $icon} + <span class="{$icon} fa-fw quiqqer-urlList-entry-link-icon"></span> + {/if} + <span class="quiqqer-urlList-entry-link-text">{$Child->getAttribute('title')}</span> + </a> + </li> + {/foreach} + </ul> + {/if} +{/strip} diff --git a/src/QUI/Menu/UrlList.Independent.Default.html b/src/QUI/Menu/UrlList.Independent.Default.html new file mode 100644 index 0000000000000000000000000000000000000000..0e091f7506b622e0336e388231151ad9ab2b8123 --- /dev/null +++ b/src/QUI/Menu/UrlList.Independent.Default.html @@ -0,0 +1,45 @@ +{if $this->getAttribute('showTitle') && $this->getAttribute('frontendTitle')} + <header class="control-header"> + <h2>{$this->getAttribute('frontendTitle')}</h2> + </header> +{/if} + +{if $this->getAttribute('content') != ""} + <div class="control-content"> + {$this->getAttribute('content')} + </div> +{/if} + +{if $headerText} + <h5 class="quiqqer-urlList-title"> + {$headerText} + </h5> +{/if} +{strip} + {if count( $children )} + <ul class="quiqqer-urlList-entries list-unstyled"> + {foreach from=$children item=Child} + <li class="quiqqer-urlList-entry"> + {if $Child->getUrl()} + <a href="{$Child->getUrl()}" class="quiqqer-urlList-entry-link {$restLinkColorCss}" + title="{$Child->getTitleAttribute()|escape:'html'}" + {if $Child->getTarget()}target="{$Child->getTarget()}"{/if}> + {if $icon} + <span class="{$icon} fa-fw quiqqer-urlList-entry-link-icon"></span> + {/if} + <span class="quiqqer-urlList-entry-link-text">{$Child->getTitle()}</span> + </a> + {else} + <span class="quiqqer-urlList-entry-link" + title="{$Child->getTitleAttribute()|escape:'html'}"> + {if $icon} + <span class="{$icon} fa-fw quiqqer-urlList-entry-link-icon"></span> + {/if} + <span class="quiqqer-urlList-entry-link-text">{$Child->getTitle()}</span> + </span> + {/if} + </li> + {/foreach} + </ul> + {/if} +{/strip} \ No newline at end of file diff --git a/src/QUI/Menu/UrlList.php b/src/QUI/Menu/UrlList.php new file mode 100644 index 0000000000000000000000000000000000000000..3bf2e55b908461068524fd739edeacdaab6a328f --- /dev/null +++ b/src/QUI/Menu/UrlList.php @@ -0,0 +1,155 @@ +<?php + +/** + * This file contains \QUI\Menu\UrlList + */ + +namespace QUI\Menu; + +use QUI; +use QUI\Projects\Site\Utils; + +/** + * Class UrlList + * + * Simple url list. + * + * It creates a list of sites. + * This control is supposed to work with QUI Independent Menu, but you can use it with QUI Site. + * You have to pass a menu ID or a parent page. + * + * Only one level of sub sites will be displayed started from given page (or menu id). + * This control DO NOT support nested navigation structure. + * + * @package QUI\Menu + * @author www.pcsg.de (Michael Danielczok) + */ +class UrlList extends QUI\Control +{ + /** + * @param array $attributes + */ + public function __construct($attributes = []) + { + // defaults values + $this->setAttributes([ + 'class' => 'quiqqer-urlList', + 'headerText' => '', // title above the url list + 'startId' => false, // id or site link + 'menuId' => false, // id of an (independent) menu + 'display' => 'default', + 'icon' => '', // only fontawesome icons are supported + 'resetLinkColor' => false // if true, the link inherit color from parent + ]); + + parent::__construct($attributes); + + $this->setAttribute('cacheable', false); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + if ($this->getAttribute('menuId')) { + // independent menu + $children = $this->getChildrenForIndependentMenu(); + $template = dirname(__FILE__).'/UrlList.Independent.Default.html'; + } elseif ($this->getAttribute('startId')) { + // qui site + $children = $this->getChildrenForQUISite(); + $template = dirname(__FILE__).'/UrlList.Default.html'; + } else { + return ''; + } + + $Engine = QUI::getTemplateManager()->getEngine(); + $icon = ''; + $restLinkColorCss = ''; + + if ($this->getAttribute('icon') && strpos($this->getAttribute('icon'), 'fa ') === 0) { + $icon = $this->getAttribute('icon'); + } + + if ($this->getAttribute('resetLinkColor')) { + $restLinkColorCss = 'quiqqer-urlList-entry-link__resetLinkColor'; + } + + switch ($this->getAttribute('display')) { + default: + case 'default': + $this->addCSSClass('quiqqer-urlList__default'); + break; + } + + $Engine->assign([ + 'this' => $this, + 'headerText' => $this->getAttribute('headerText'), + 'children' => $children, + 'icon' => $icon, + 'restLinkColorCss' => $restLinkColorCss + ]); + + $this->addCSSFile(dirname(__FILE__).'/UrlList.Default.css'); + + return $Engine->fetch($template); + } + + /** + * Get sites for independent menu + * + * @return array + * @throws QUI\Exception + */ + public function getChildrenForIndependentMenu() + { + $IndependentMenu = Independent\Handler::getMenu($this->getAttribute('menuId')); + + return $IndependentMenu->getChildren(); + } + + /** + * Get sites for QUI site + * + * @return array + * @throws QUI\Exception + */ + public function getChildrenForQUISite() + { + $Project = $this->getProject(); + + // start + try { + $startId = $this->getAttribute('startId'); + + if (Utils::isSiteLink($startId)) { + $Site = Utils::getSiteByLink($startId); + } else { + $Site = $Project->get((int)$startId); + } + } catch (QUI\Exception $Exception) { + QUI\System\Log::addWarning($Exception->getMessage()); + + return []; + } + + return $this->getChildren($Site); + } + + /** + * @param QUI\Projects\Site $Site + * @return array|int + * @throws QUI\Exception + */ + public function getChildren(QUI\Projects\Site $Site) + { + if (!$this->getAttribute('showAllChildren')) { + return $Site->getNavigation(); + } + + return $Site->getChildren(); + } +}