Verified Commit c19e66f5 authored by Camil Staps's avatar Camil Staps 🚀

Documentation browser with correct links

parent c797bcd6
......@@ -89,13 +89,12 @@ Element.prototype.browser = function(opts) {
return {
state: state,
triggerChange: triggerChange,
setPath: function(path) {
openPath: function(path) {
var old = root.getElementsByClassName('active');
for (var i = 0; i < old.length; i++)
old[i].classList.remove('active');
var e = root;
console.log(path);
for (var i = 0; i < path.length && 'childNodes' in e; i++) {
var children = e.childNodes;
for (var k = 0; k < children.length; k++) {
......@@ -111,6 +110,15 @@ Element.prototype.browser = function(opts) {
}
}
},
openTo: function(elem) {
var path = [];
elem.classList.add('active');
while (elem != root && elem != null) {
if (elem.classList.contains('toggle-container'))
toggle(elem, true);
elem = elem.parentNode;
}
},
open: function() {
opts.newHash(decodeURIComponent(window.location.hash.substring(1)));
}
......
......@@ -63,9 +63,9 @@ class Toc {
echo '<div class="browser togglee">';
foreach ($this->children as $child) {
if ($child->isLeaf()) {
echo '<div class="browser-item module" onclick="loadModule(this)" ' .
'data-module="' . $child->link . '">' . $child->title . '</span>' .
'</div>';
echo '<div class="browser-item module" id="' . $child->link .
'" data-name="' . $child->link . '">' .
$child->title . '</span></div>';
} else {
echo '<div class="browser-item directory toggle-container">' .
'<span class="toggler" onclick="toggle(this)">' .
......
window.onload = function() {
var viewer = document.getElementById('viewer');
var browser = document.getElementsByClassName('browser')[0].browser({
newPath: function (path) {
path = path[0].split(';');
this.state.loc = path[0];
this.state.jump = null;
for (var i = 1; i < path.length; i++)
if (path[i].substring(0,5) == 'jump=')
this.state.jump = path[i].substring(5);
this.newState();
},
newHash: function (hash) {
var hashelems = hash.split(';');
this.state.loc = hashelems[0];
this.state.jump = null;
for (var i = 1; i < hashelems.length; i++)
if (hashelems[i].substring(0,5) == 'jump=')
this.state.jump = hashelems[i].substring(5);
this.newState();
browser.openTo(document.getElementById(hash));
},
newState: function () {
var hash = this.state.loc;
if (this.state.jump != null)
hash += ';jump=' + this.state.jump;
document.location.hash = '#' + hash;
},
getUrl: function () {
return 'src.php?loc=' + encodeURIComponent(this.state.loc);
},
viewer: viewer,
onLoad: function(state) {
if (state.jump != null) {
var l = document.getElementsByName(state.jump)[0].documentOffsetTop();
viewer.scrollTo(0, l - window.innerHeight/4);
}
},
state: {
jump: false
}
});
browser.open();
browser.triggerChange();
var sidebar = document.getElementById('sidebar');
var viewer = document.getElementById('viewer');
if (window.innerWidth > 800) {
var height = window.innerHeight;
sidebar.style.height = (height - 20) + 'px';
viewer.style.height = height + 'px';
}
}
......@@ -7,10 +7,15 @@
<meta name="description" content="Cloogle is the unofficial Clean language search engine"/>
<meta name="keywords" content="Clean,Clean language,Concurrent Clean,search,functions,search engine,programming language,clean platform,iTasks,cloogle,hoogle"/>
<script src="../common.js" type="text/javascript" defer="defer"></script>
<script src="../src/view.js" type="text/javascript" defer="defer"></script>
<script src="../browser.js" type="text/javascript" defer="defer"></script>
<script src="doc.js" type="text/javascript" defer="defer"></script>
<link rel="stylesheet" href="../common.css" type="text/css"/>
<link rel="stylesheet" href="../src/view.css" type="text/css"/>
<style type="text/css">
#viewer {
padding: 1em;
}
.Heading1Chapter img, .Newchapter img {
display: none;
}
......
<?php
define('CLEANHOME', '/opt/clean');
$loc = isset($_REQUEST['mod']) ? $_REQUEST['mod'] : 'CleanRep.2.2_1.htm;jump=_Toc311797959';
$loc = $_REQUEST['loc'] ?: 'CleanRep.2.2_1.htm;jump=_Toc311797959';
$loc = preg_replace('/\.\.+/', '.', $loc);
$loc = preg_replace('/[^\w\d.;=]+/', '', $loc);
......
......@@ -74,7 +74,7 @@ window.onload = function() {
this.state.line = hashelems[i].substring(5);
}
browser.setPath(this.state.mod.split('.'));
browser.openPath(this.state.mod.split('.'));
},
newState: function () {
var hash = this.state.mod;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment