1/** 2 * We handle several device classes based on browser width. 3 * 4 * - desktop: > __tablet_width__ (as set in style.ini) 5 * - mobile: 6 * - tablet <= __tablet_width__ 7 * - phone <= __phone_width__ 8 */ 9var device_class = ''; // not yet known 10var device_classes = 'desktop mobile tablet phone'; 11 12function tpl_dokuwiki_mobile(){ 13 14 // the z-index in mobile.css is (mis-)used purely for detecting the screen mode here 15 var screen_mode = jQuery('#screen__mode').css('z-index') + ''; 16 17 // determine our device pattern 18 // TODO: consider moving into dokuwiki core 19 switch (screen_mode) { 20 case '1': 21 if (device_class.match(/tablet/)) return; 22 device_class = 'mobile tablet'; 23 break; 24 case '2': 25 if (device_class.match(/phone/)) return; 26 device_class = 'mobile phone'; 27 break; 28 default: 29 if (device_class == 'desktop') return; 30 device_class = 'desktop'; 31 } 32 33 jQuery('html').removeClass(device_classes).addClass(device_class); 34 35 // handle some layout changes based on change in device 36 var $handle = jQuery('#dokuwiki__aside h3.toggle'); 37 var $toc = jQuery('#dw__toc h3'); 38 39 if (device_class == 'desktop') { 40 // reset for desktop mode 41 if($handle.length) { 42 $handle[0].setState(1); 43 $handle.hide(); 44 } 45 if($toc.length) { 46 $toc[0].setState(1); 47 } 48 } 49 if (device_class.match(/mobile/)){ 50 // toc and sidebar hiding 51 if($handle.length) { 52 $handle.show(); 53 $handle[0].setState(-1); 54 } 55 if($toc.length) { 56 $toc[0].setState(-1); 57 } 58 } 59} 60 61jQuery(function(){ 62 var resizeTimer; 63 dw_page.makeToggle('#dokuwiki__aside h3.toggle','#dokuwiki__aside div.content'); 64 65 tpl_dokuwiki_mobile(); 66 jQuery(window).on('resize', 67 function(){ 68 if (resizeTimer) clearTimeout(resizeTimer); 69 resizeTimer = setTimeout(tpl_dokuwiki_mobile,200); 70 } 71 ); 72 73 // increase sidebar length to match content (desktop mode only) 74 var $sidebar = jQuery('.desktop #dokuwiki__aside'); 75 if($sidebar.length) { 76 var $content = jQuery('#dokuwiki__content div.page'); 77 $content.css('min-height', $sidebar.height()); 78 } 79}); 80 81/** 82 * Code for handling automatic scrolling if the mouse hovers over 83 * one of the scroll areas. 84 */ 85var scrolling = null; 86function scroll_up() { 87 var d = document.getElementById('dokuwiki__page'); 88 89 d.scrollTop = d.scrollTop - 5; 90 91 scrolling = window.setTimeout(function() { 92 scroll_up(); 93 }, 5); 94} 95 96function scroll_down() { 97 var d = document.getElementById('dokuwiki__page'); 98 99 d.scrollTop = d.scrollTop + 5; 100 101 scrolling = window.setTimeout(function() { 102 scroll_down(); 103 }, 5); 104} 105 106function stop_scroll() { 107 window.clearTimeout(scrolling); 108} 109