|
|
@@ -8,6 +8,8 @@
|
|
|
import React from 'react';
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
|
|
+import { debounce } from 'throttle-debounce';
|
|
|
+
|
|
|
import GrowiRenderer from '../util/GrowiRenderer';
|
|
|
import Page from '../components/Page';
|
|
|
|
|
|
@@ -165,6 +167,60 @@ Crowi.handleKeyCtrlSlashHandler = (event) => {
|
|
|
event.preventDefault();
|
|
|
};
|
|
|
|
|
|
+Crowi.initSlimScrollForRevisionToc = () => {
|
|
|
+ const revisionTocElem = document.querySelector('.growi .revision-toc');
|
|
|
+ const tocContentElem = document.querySelector('.growi .revision-toc .markdownIt-TOC');
|
|
|
+
|
|
|
+ // growi layout only
|
|
|
+ if (revisionTocElem == null || tocContentElem == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getCurrentRevisionTocTop() {
|
|
|
+ // calculate absolute top of '#revision-toc' element
|
|
|
+ return revisionTocElem.getBoundingClientRect().top;
|
|
|
+ }
|
|
|
+
|
|
|
+ function resetScrollbar(revisionTocTop) {
|
|
|
+ // window height - revisionTocTop - .system-version height
|
|
|
+ let h = window.innerHeight - revisionTocTop - 20;
|
|
|
+
|
|
|
+ const tocContentHeight = tocContentElem.getBoundingClientRect().height + 15; // add margin
|
|
|
+
|
|
|
+ h = Math.min(h, tocContentHeight);
|
|
|
+
|
|
|
+ $('#revision-toc-content').slimScroll({
|
|
|
+ railVisible: true,
|
|
|
+ position: 'right',
|
|
|
+ height: h,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const resetScrollbarDebounced = debounce(100, resetScrollbar);
|
|
|
+
|
|
|
+ // initialize
|
|
|
+ const revisionTocTop = getCurrentRevisionTocTop();
|
|
|
+ resetScrollbar(revisionTocTop);
|
|
|
+
|
|
|
+ /*
|
|
|
+ * set event listener
|
|
|
+ */
|
|
|
+ // resize
|
|
|
+ window.addEventListener('resize', (event) => {
|
|
|
+ resetScrollbarDebounced(getCurrentRevisionTocTop());
|
|
|
+ });
|
|
|
+ // affix on
|
|
|
+ $('#revision-toc').on('affixed.bs.affix', function() {
|
|
|
+ resetScrollbar(getCurrentRevisionTocTop());
|
|
|
+ });
|
|
|
+ // affix off
|
|
|
+ $('#revision-toc').on('affixed-top.bs.affix', function() {
|
|
|
+ // calculate sum of height (.navbar-header + .bg-title) + margin-top of .main
|
|
|
+ const sum = 138;
|
|
|
+ resetScrollbar(sum);
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
$(function() {
|
|
|
var config = JSON.parse(document.getElementById('crowi-context-hydrate').textContent || '{}');
|
|
|
|
|
|
@@ -430,7 +486,7 @@ $(function() {
|
|
|
var revisionPath = '#' + id + ' .revision-path';
|
|
|
/* eslint-enable */
|
|
|
var pagePath = document.getElementById(id).getAttribute('data-page-path');
|
|
|
- var markdown = $(contentId).html();
|
|
|
+ var markdown = entities.decodeHTML($(contentId).html());
|
|
|
|
|
|
ReactDOM.render(<Page crowi={crowi} crowiRenderer={growiRendererForTimeline} markdown={markdown} pagePath={pagePath} />, revisionBodyElem);
|
|
|
});
|
|
|
@@ -529,6 +585,20 @@ $(function() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // (function () {
|
|
|
+ // var timer = 0;
|
|
|
+
|
|
|
+ // window.onresize = function () {
|
|
|
+ // if (timer > 0) {
|
|
|
+ // clearTimeout(timer);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // timer = setTimeout(function () {
|
|
|
+ // DrawScrollbar();
|
|
|
+ // }, 200);
|
|
|
+ // };
|
|
|
+ // }());
|
|
|
+
|
|
|
/*
|
|
|
* transplanted to React components -- 2017.06.02 Yuki Takei
|
|
|
*
|
|
|
@@ -890,6 +960,7 @@ window.addEventListener('load', function(e) {
|
|
|
Crowi.highlightSelectedSection(location.hash);
|
|
|
Crowi.modifyScrollTop();
|
|
|
Crowi.setCaretLineAndFocusToEditor();
|
|
|
+ Crowi.initSlimScrollForRevisionToc();
|
|
|
});
|
|
|
|
|
|
window.addEventListener('hashchange', function(e) {
|