mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
Allow for either nested or separate submenu form template. Include recursive option
Default setting: separate submenu, no recursion. Setting recursion fetches all children, to allow for JavaScript-powered submenus (script not included). If recursion is enabled, separate menus are disabled.
This commit is contained in:
parent
67ff61a756
commit
0df804f86c
@ -46,6 +46,11 @@ class DocumentationViewer extends Controller {
|
||||
*/
|
||||
public $remaining = array();
|
||||
|
||||
/**
|
||||
* @var DocumentationPage
|
||||
*/
|
||||
public $currentLevelOnePage;
|
||||
|
||||
/**
|
||||
* @var String Same as the routing pattern set through Director::addRules().
|
||||
*/
|
||||
@ -62,6 +67,24 @@ class DocumentationViewer extends Controller {
|
||||
*/
|
||||
private static $edit_links = array();
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
protected static $separate_submenu = true;
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
protected static $recursive_submenu = false;
|
||||
|
||||
public static function set_separate_submenu($separate_submenu = true) {
|
||||
self::$separate_submenu = $separate_submenu;
|
||||
}
|
||||
|
||||
public static function set_recursive_submenu($recursive_submenu = false) {
|
||||
self::$recursive_submenu = $nested_submenu;
|
||||
}
|
||||
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
@ -468,7 +491,7 @@ class DocumentationViewer extends Controller {
|
||||
*/
|
||||
function getEntityPages() {
|
||||
if($entity = $this->getEntity()) {
|
||||
$pages = DocumentationService::get_pages_from_folder($entity, null, false, $this->getVersion(), $this->getLang());
|
||||
$pages = DocumentationService::get_pages_from_folder($entity, null, self::$recursive_submenu, $this->getVersion(), $this->getLang());
|
||||
|
||||
if($pages) {
|
||||
foreach($pages as $page) {
|
||||
@ -480,6 +503,10 @@ class DocumentationViewer extends Controller {
|
||||
|
||||
$page->LinkingMode = 'link';
|
||||
$page->Children = $this->_getEntityPagesNested($page, $entity);
|
||||
|
||||
if (!empty($page->Children)) {
|
||||
$this->currentLevelOnePage = $page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -523,7 +550,7 @@ class DocumentationViewer extends Controller {
|
||||
$children = DocumentationService::get_pages_from_folder(
|
||||
$entity,
|
||||
$page->getRelativePath(),
|
||||
false,
|
||||
self::$recursive_submenu,
|
||||
$this->getVersion(),
|
||||
$this->getLang()
|
||||
);
|
||||
@ -552,6 +579,31 @@ class DocumentationViewer extends Controller {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DocumentationPage
|
||||
*/
|
||||
public function getCurrentLevelOnePage() {
|
||||
return $this->currentLevelOnePage;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns 'separate' if the submenu should be displayed in a separate
|
||||
* block, 'nested' otherwise. If no currentDocPage is defined, there is
|
||||
* no submenu, so an empty string is returned.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubmenu() {
|
||||
if ($this->currentLevelOnePage) {
|
||||
if (self::$separate_submenu && !self::$recursive_submenu) {
|
||||
return 'separate';
|
||||
} else {
|
||||
return 'nested';
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the content for the page. If its an actual documentation page then
|
||||
* display the content from the page, otherwise display the contents from
|
||||
|
@ -51,20 +51,6 @@
|
||||
|
||||
}
|
||||
|
||||
/** -----------------------------------------------
|
||||
* SUBMENU
|
||||
*
|
||||
* move to separate menu block
|
||||
*/
|
||||
if ($("#submenu").length > 0) {
|
||||
var submenuTitle = $("#sibling-pages").find('a.current, a.section').eq(0).text();
|
||||
var submenu = '<div class = "sidebar-box"><h4>' + submenuTitle + '</h4><ul>';
|
||||
submenu += $("#submenu").html();
|
||||
submenu += '</ul></div>';
|
||||
$("#sidebar-column").append(submenu);
|
||||
$("#submenu").remove();
|
||||
}
|
||||
|
||||
/** ---------------------------------------------
|
||||
* HEADING ANCHOR LINKS
|
||||
*
|
||||
|
@ -5,24 +5,24 @@
|
||||
<% control EntityPages %>
|
||||
<li>
|
||||
<a href="$Link" class="$LinkingMode">$Title</a>
|
||||
<% if Children %>
|
||||
<ul id="submenu">
|
||||
<% control Children %>
|
||||
<li><a href="$Link" class="$LinkingMode">
|
||||
$Title <% if IsFolder %><span class="is-folder">►</span><% end_if %>
|
||||
</a>
|
||||
<% if Children %>
|
||||
<ul>
|
||||
<% control Children %>
|
||||
<li><a href="$Link" class="$LinkingMode">$Title</a></li>
|
||||
<% end_control %>
|
||||
</ul><% end_if %>
|
||||
</li>
|
||||
<% end_control %>
|
||||
</ul>
|
||||
<% if Top.Submenu = nested %>
|
||||
<% if Children %>
|
||||
<% include DocSubmenu %>
|
||||
<% end_if %>
|
||||
<% end_if %>
|
||||
</li>
|
||||
<% end_control %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end_if %>
|
||||
<% end_if %>
|
||||
|
||||
<% if Submenu = separate %>
|
||||
<% control CurrentLevelOnePage %>
|
||||
<% if Children %>
|
||||
<div class = "sidebar-box">
|
||||
<h4>$title</h4>
|
||||
<% include DocSubmenu %>
|
||||
</div>
|
||||
<% end_if %>
|
||||
<% end_control %>
|
||||
<% end_if %>
|
||||
|
14
templates/Includes/DocSubmenu.ss
Normal file
14
templates/Includes/DocSubmenu.ss
Normal file
@ -0,0 +1,14 @@
|
||||
<ul id="submenu">
|
||||
<% control Children %>
|
||||
<li><a href="$Link" class="$LinkingMode">
|
||||
$Title <% if IsFolder %><span class="is-folder">►</span><% end_if %>
|
||||
</a>
|
||||
<% if Children %>
|
||||
<ul>
|
||||
<% control Children %>
|
||||
<li><a href="$Link" class="$LinkingMode">$Title</a></li>
|
||||
<% end_control %>
|
||||
</ul><% end_if %>
|
||||
</li>
|
||||
<% end_control %>
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user