mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00: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();
|
public $remaining = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DocumentationPage
|
||||||
|
*/
|
||||||
|
public $currentLevelOnePage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var String Same as the routing pattern set through Director::addRules().
|
* @var String Same as the routing pattern set through Director::addRules().
|
||||||
*/
|
*/
|
||||||
@ -62,6 +67,24 @@ class DocumentationViewer extends Controller {
|
|||||||
*/
|
*/
|
||||||
private static $edit_links = array();
|
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() {
|
function init() {
|
||||||
parent::init();
|
parent::init();
|
||||||
|
|
||||||
@ -468,7 +491,7 @@ class DocumentationViewer extends Controller {
|
|||||||
*/
|
*/
|
||||||
function getEntityPages() {
|
function getEntityPages() {
|
||||||
if($entity = $this->getEntity()) {
|
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) {
|
if($pages) {
|
||||||
foreach($pages as $page) {
|
foreach($pages as $page) {
|
||||||
@ -480,6 +503,10 @@ class DocumentationViewer extends Controller {
|
|||||||
|
|
||||||
$page->LinkingMode = 'link';
|
$page->LinkingMode = 'link';
|
||||||
$page->Children = $this->_getEntityPagesNested($page, $entity);
|
$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(
|
$children = DocumentationService::get_pages_from_folder(
|
||||||
$entity,
|
$entity,
|
||||||
$page->getRelativePath(),
|
$page->getRelativePath(),
|
||||||
false,
|
self::$recursive_submenu,
|
||||||
$this->getVersion(),
|
$this->getVersion(),
|
||||||
$this->getLang()
|
$this->getLang()
|
||||||
);
|
);
|
||||||
@ -552,6 +579,31 @@ class DocumentationViewer extends Controller {
|
|||||||
return false;
|
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
|
* Return the content for the page. If its an actual documentation page then
|
||||||
* display the content from the page, otherwise display the contents from
|
* 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
|
* HEADING ANCHOR LINKS
|
||||||
*
|
*
|
||||||
|
@ -5,24 +5,24 @@
|
|||||||
<% control EntityPages %>
|
<% control EntityPages %>
|
||||||
<li>
|
<li>
|
||||||
<a href="$Link" class="$LinkingMode">$Title</a>
|
<a href="$Link" class="$LinkingMode">$Title</a>
|
||||||
|
<% if Top.Submenu = nested %>
|
||||||
<% if Children %>
|
<% if Children %>
|
||||||
<ul id="submenu">
|
<% include DocSubmenu %>
|
||||||
<% control Children %>
|
<% end_if %>
|
||||||
<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>
|
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
</li>
|
</li>
|
||||||
<% end_control %>
|
<% end_control %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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…
x
Reference in New Issue
Block a user