aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Widget/Helpindex.php12
-rw-r--r--doc/toc.html62
-rw-r--r--include/help.php39
-rw-r--r--view/js/mod_help.js74
-rw-r--r--view/tpl/help.tpl18
5 files changed, 113 insertions, 92 deletions
diff --git a/Zotlabs/Widget/Helpindex.php b/Zotlabs/Widget/Helpindex.php
index f23e73e75..8299cf16a 100644
--- a/Zotlabs/Widget/Helpindex.php
+++ b/Zotlabs/Widget/Helpindex.php
@@ -9,14 +9,22 @@ class Helpindex {
$o .= '<div class="widget">';
$level_0 = get_help_content('sitetoc');
- if(! $level_0)
- $level_0 = get_help_content('toc');
+ if(! $level_0) {
+ $path = 'toc';
+ $x = determine_help_language();
+ $lang = $x['language'];
+ if($lang !== 'en') {
+ $path = $lang . '/toc';
+ }
+ $level_0 = get_help_content($path);
+ }
$level_0 = preg_replace('/\<ul(.*?)\>/','<ul class="nav nav-pills flex-column">',$level_0);
$levels = array();
+ // TODO: Implement support for translations in hierarchical table of content files
if(argc() > 2) {
$path = '';
for($x = 1; $x < argc(); $x ++) {
diff --git a/doc/toc.html b/doc/toc.html
index 4da01d55d..1b7de3cb3 100644
--- a/doc/toc.html
+++ b/doc/toc.html
@@ -71,65 +71,3 @@
</div>
</div>
</div>
-<script>
- toc = {};
- // Generate the table of contents in the side nav menu (see view/tpl/help.tpl)
- $(document).ready(function () {
- $(".doco-section").find('a').each(function(){
- var url = document.createElement('a');
- url.href = window.location;
- var pageName = url.href.split('/').pop().split('#').shift().split('?').shift();
- var linkName = $(this).attr('href').split('/').pop();
- if(pageName === linkName) {
- var tocUl = $(this).closest('a').append('<ul>').find('ul');
- tocUl.removeClass(); // Classes are automatically added to <ul> elements by something else
- tocUl.toc({content: "#doco-content", headings: "h3"});
- tocUl.addClass('toc-content');
- tocUl.addClass('list-unstyled');
- tocUl.attr('id', 'doco-side-toc');
-
- }
- });
-
- $(document.body).trigger("sticky_kit:recalc");
-
- toc.contentTop = [];
- toc.edgeMargin = 20; // margin above the top or margin from the end of the page
- toc.topRange = 200; // measure from the top of the viewport to X pixels down
- // Set up content an array of locations
- $('#doco-side-toc').find('a').each(function(){
- toc.contentTop.push( $( '#'+$(this).attr('href').split('#').pop() ).offset().top );
- });
-
-
- // adjust side menu
- $(window).scroll(function(){
- var winTop = $(window).scrollTop(),
- bodyHt = $(document).height(),
- vpHt = $(window).height() + toc.edgeMargin; // viewport height + margin
- $.each( toc.contentTop, function(i,loc){
- if ( ( loc > winTop - toc.edgeMargin && ( loc < winTop + toc.topRange || ( winTop + vpHt ) >= bodyHt ) ) ){
- $('#doco-side-toc li')
- .removeClass('selected-doco-nav')
- .eq(i).addClass('selected-doco-nav');
- if (typeof($('#doco-side-toc li').eq(i).find('a').attr('href').split('#')[1]) !== 'undefined') {
- window.history.pushState({}, '', location.href.split('#')[0] + '#' + $('#doco-side-toc li').eq(i).find('a').attr('href').split('#')[1]);
- }
- }
- });
- });
-
- // When the page loads, it does not scroll to the section specified in the URL because it
- // has not been constructed yet by the script. This will reload the URL
- if (typeof(location.href.split('#')[1]) !== 'undefined') {
- var p = document.createElement('a');
- p.href = location.href;
- var portstr = '';
- if(p.port !== '') {
- portstr = ':'+ p.port;
- }
- var newref = p.protocol + '//'+ p.hostname + portstr + p.pathname + p.hash.split('?').shift();
- location.replace(newref)
- }
- });
-</script>
diff --git a/include/help.php b/include/help.php
index 4f9251b1b..cbadd02d9 100644
--- a/include/help.php
+++ b/include/help.php
@@ -107,20 +107,39 @@ function preg_callback_help_include($matches) {
}
-
+function determine_help_language() {
+ require_once('Text/LanguageDetect.php');
+ $lang_detect = new Text_LanguageDetect();
+ $lang_detect->setNameMode(2);
+ if($lang_detect->languageExists(argv(1))) {
+ $lang = argv(1);
+ $from_url = true;
+ } else {
+ $lang = \App::$language;
+ if(! isset($lang))
+ $lang = 'en';
+ $from_url = false;
+ }
+ return array('language' => $lang, 'from_url' => $from_url);
+}
function load_doc_file($s) {
- $lang = \App::$language;
- if(! isset($lang))
- $lang = 'en';
+ $path = 'doc';
+ $x = determine_help_language();
+ $lang = $x['language'];
+ $url_idx = ($x['from_url'] ? 1 : 0);
+ if($x['from_url'] && $lang !== 'en') {
+ $path .= '/' . $lang;
+ }
+
$b = basename($s);
- $d = dirname($s);
-
- if($dirname !== '-') {
- $c = find_doc_file("$d/$lang/$b");
- if($c)
- return $c;
+
+ for($i=1+$url_idx; $i<argc()-1; $i++) {
+ $path .= '/' . argv($i);
}
+ $c = find_doc_file($path . '/' . $b);
+ if($c)
+ return $c;
$c = find_doc_file($s);
if($c)
return $c;
diff --git a/view/js/mod_help.js b/view/js/mod_help.js
new file mode 100644
index 000000000..0f85af462
--- /dev/null
+++ b/view/js/mod_help.js
@@ -0,0 +1,74 @@
+function docoTocToggle() {
+ if ($('#doco-top-toc').is(':visible')) {
+ $('#doco-toc-toggle').removeClass('fa-cog').addClass('fa-caret-right');
+ } else {
+ $('#doco-toc-toggle').removeClass('fa-caret-right').addClass('fa-caret-down');
+ }
+ $('#doco-top-toc').toggle();
+
+ return false;
+}
+
+toc = {};
+// Generate the table of contents in the side nav menu (see view/tpl/help.tpl)
+$(document).ready(function () {
+ // Generate the table of contents in the side nav menu (see view/tpl/help.tpl)
+ $('#doco-top-toc').toc({content: "#doco-content", headings: "h3,h4,h5,h6"});
+
+ $(".doco-section").find('a').each(function () {
+ var url = document.createElement('a');
+ url.href = window.location;
+ var pageName = url.href.split('/').pop().split('#').shift().split('?').shift();
+ var linkName = $(this).attr('href').split('/').pop();
+ if (pageName === linkName) {
+ var tocUl = $(this).closest('a').append('<ul>').find('ul');
+ tocUl.removeClass(); // Classes are automatically added to <ul> elements by something else
+ tocUl.toc({content: "#doco-content", headings: "h3"});
+ tocUl.addClass('toc-content');
+ tocUl.addClass('list-unstyled');
+ tocUl.attr('id', 'doco-side-toc');
+
+ }
+ });
+
+ $(document.body).trigger("sticky_kit:recalc");
+
+ toc.contentTop = [];
+ toc.edgeMargin = 20; // margin above the top or margin from the end of the page
+ toc.topRange = 200; // measure from the top of the viewport to X pixels down
+ // Set up content an array of locations
+ $('#doco-side-toc').find('a').each(function () {
+ toc.contentTop.push($('#' + $(this).attr('href').split('#').pop()).offset().top);
+ });
+
+
+ // adjust side menu
+ $(window).scroll(function () {
+ var winTop = $(window).scrollTop(),
+ bodyHt = $(document).height(),
+ vpHt = $(window).height() + toc.edgeMargin; // viewport height + margin
+ $.each(toc.contentTop, function (i, loc) {
+ if ((loc > winTop - toc.edgeMargin && (loc < winTop + toc.topRange || (winTop + vpHt) >= bodyHt))) {
+ $('#doco-side-toc li')
+ .removeClass('selected-doco-nav')
+ .eq(i).addClass('selected-doco-nav');
+ if (typeof ($('#doco-side-toc li').eq(i).find('a').attr('href').split('#')[1]) !== 'undefined') {
+ window.history.pushState({}, '', location.href.split('#')[0] + '#' + $('#doco-side-toc li').eq(i).find('a').attr('href').split('#')[1]);
+ }
+ }
+ });
+ });
+
+ // When the page loads, it does not scroll to the section specified in the URL because it
+ // has not been constructed yet by the script. This will reload the URL
+ if (typeof (location.href.split('#')[1]) !== 'undefined') {
+ var p = document.createElement('a');
+ p.href = location.href;
+ var portstr = '';
+ if (p.port !== '') {
+ portstr = ':' + p.port;
+ }
+ var newref = p.protocol + '//' + p.hostname + portstr + p.pathname + p.hash.split('?').shift();
+ location.replace(newref)
+ }
+});
diff --git a/view/tpl/help.tpl b/view/tpl/help.tpl
index 43b061dcc..31e5b9794 100644
--- a/view/tpl/help.tpl
+++ b/view/tpl/help.tpl
@@ -13,21 +13,3 @@
{{$content}}
</div>
</div>
-
-<script>
- // Generate the table of contents in the side nav menu (see view/tpl/help.tpl)
- $(document).ready(function () {
- $('#doco-top-toc').toc({content: "#doco-content", headings: "h3,h4,h5,h6"});
- });
-
- function docoTocToggle() {
- if($('#doco-top-toc').is(':visible')) {
- $('#doco-toc-toggle').removeClass('fa-cog').addClass('fa-caret-right');
- } else {
- $('#doco-toc-toggle').removeClass('fa-caret-right').addClass('fa-caret-down');
- }
- $('#doco-top-toc').toggle();
-
- return false;
- }
-</script>