2
0
Эх сурвалжийг харах

move scripts to crowi.js from layout.html

Yuki Takei 7 жил өмнө
parent
commit
53949e8a79

+ 0 - 37
lib/views/layout-growi/base/layout.html

@@ -26,43 +26,6 @@
 
 </div><!-- /.container-fluid -->
 
-
-<!-- Side Scroll Bar-->
-
-
-   * Disabled temporally -- 2018.06.06 Yuki Takei
-   * see https://weseek.myjetbrains.com/youtrack/issue/GC-278
-   *
-<script>
-  function DrawScrollbar() {
-    var h = window.innerHeight - 50 ;
-    $('#revision-toc-content').slimScroll({
-      railVisible: true,
-      position: 'right',
-      height: h,
-    });
-  }
-
-  $(function(){
-    DrawScrollbar();
-  });
-
-  (function () {
-    var timer = 0;
-
-    window.onresize = function () {
-      if (timer > 0) {
-        clearTimeout(timer);
-      }
-
-      timer = setTimeout(function () {
-        DrawScrollbar();
-      }, 200);
-    };
-  }());
-
-  </script>
-
 <footer class="footer">
   {% include '../../widget/system-version.html' %}
 </footer>

+ 39 - 0
resource/js/legacy/crowi.js

@@ -165,6 +165,30 @@ Crowi.handleKeyCtrlSlashHandler = (event) => {
   event.preventDefault();
 };
 
+Crowi.initSlimScrollForRevisionToc = () => {
+  // slimScroll for revision-toc
+  const revisionTocElem = document.getElementById('revision-toc');
+  function drawScrollbar() {
+    // calculate absolute top of '#revision-toc' element
+    const revisionTocTop = revisionTocElem.getBoundingClientRect().top;
+    // inner height - revisionTocTop
+    const h = window.innerHeight - revisionTocTop;
+
+    $('#revision-toc-content').slimScroll({
+      railVisible: true,
+      position: 'right',
+      height: h,
+    });
+  }
+
+  drawScrollbar();
+
+  // set event listener
+  // revisionTocElem.addEventListener('affix.bs.affix', () => {
+  //   console.log('hoge');
+  // });
+};
+
 $(function() {
   var config = JSON.parse(document.getElementById('crowi-context-hydrate').textContent || '{}');
 
@@ -529,6 +553,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 +928,7 @@ window.addEventListener('load', function(e) {
   Crowi.highlightSelectedSection(location.hash);
   Crowi.modifyScrollTop();
   Crowi.setCaretLineAndFocusToEditor();
+  Crowi.initSlimScrollForRevisionToc();
 });
 
 window.addEventListener('hashchange', function(e) {