about summary refs log tree commit diff stats
path: root/wiki/lib/tpl/dokuwiki/script.js
diff options
context:
space:
mode:
authorahriman <ahriman@falte.red>2018-12-03 19:22:25 -0500
committerahriman <ahriman@falte.red>2018-12-03 19:22:25 -0500
commit0ae8cbf5c0b1a198b963490985b7738392ebcb97 (patch)
treeb2c77ae72c6b717e2b97492065196ac5ffb2d9e2 /wiki/lib/tpl/dokuwiki/script.js
parentf57f6cc5a2d159f90168d292437dc4bd8cd7f934 (diff)
downloadsite-0ae8cbf5c0b1a198b963490985b7738392ebcb97.tar.gz
installed dokuwiki, added to navbar, updated news
Diffstat (limited to 'wiki/lib/tpl/dokuwiki/script.js')
-rw-r--r--wiki/lib/tpl/dokuwiki/script.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/wiki/lib/tpl/dokuwiki/script.js b/wiki/lib/tpl/dokuwiki/script.js
new file mode 100644
index 0000000..b4e6ced
--- /dev/null
+++ b/wiki/lib/tpl/dokuwiki/script.js
@@ -0,0 +1,79 @@
+/**
+ *  We handle several device classes based on browser width.
+ *
+ *  - desktop:   > __tablet_width__ (as set in style.ini)
+ *  - mobile:
+ *    - tablet   <= __tablet_width__
+ *    - phone    <= __phone_width__
+ */
+var device_class = ''; // not yet known
+var device_classes = 'desktop mobile tablet phone';
+
+function tpl_dokuwiki_mobile(){
+
+    // the z-index in mobile.css is (mis-)used purely for detecting the screen mode here
+    var screen_mode = jQuery('#screen__mode').css('z-index') + '';
+
+    // determine our device pattern
+    // TODO: consider moving into dokuwiki core
+    switch (screen_mode) {
+        case '1':
+            if (device_class.match(/tablet/)) return;
+            device_class = 'mobile tablet';
+            break;
+        case '2':
+            if (device_class.match(/phone/)) return;
+            device_class = 'mobile phone';
+            break;
+        default:
+            if (device_class == 'desktop') return;
+            device_class = 'desktop';
+    }
+
+    jQuery('html').removeClass(device_classes).addClass(device_class);
+
+    // handle some layout changes based on change in device
+    var $handle = jQuery('#dokuwiki__aside h3.toggle');
+    var $toc = jQuery('#dw__toc h3');
+
+    if (device_class == 'desktop') {
+        // reset for desktop mode
+        if($handle.length) {
+            $handle[0].setState(1);
+            $handle.hide();
+        }
+        if($toc.length) {
+            $toc[0].setState(1);
+        }
+    }
+    if (device_class.match(/mobile/)){
+        // toc and sidebar hiding
+        if($handle.length) {
+            $handle.show();
+            $handle[0].setState(-1);
+        }
+        if($toc.length) {
+            $toc[0].setState(-1);
+        }
+    }
+}
+
+jQuery(function(){
+    var resizeTimer;
+    dw_page.makeToggle('#dokuwiki__aside h3.toggle','#dokuwiki__aside div.content');
+
+    tpl_dokuwiki_mobile();
+    jQuery(window).on('resize',
+        function(){
+            if (resizeTimer) clearTimeout(resizeTimer);
+            resizeTimer = setTimeout(tpl_dokuwiki_mobile,200);
+        }
+    );
+
+    // increase sidebar length to match content (desktop mode only)
+    var $sidebar = jQuery('.desktop #dokuwiki__aside');
+    if($sidebar.length) {
+        var $content = jQuery('#dokuwiki__content div.page');
+        $content.css('min-height', $sidebar.height());
+    }
+});