script.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. */
  9. var device_class = ''; // not yet known
  10. var device_classes = 'desktop mobile tablet phone';
  11. function tpl_dokuwiki_mobile(){
  12. // the z-index in mobile.css is (mis-)used purely for detecting the screen mode here
  13. var screen_mode = jQuery('#screen__mode').css('z-index') + '';
  14. // determine our device pattern
  15. // TODO: consider moving into dokuwiki core
  16. switch (screen_mode) {
  17. case '1':
  18. if (device_class.match(/tablet/)) return;
  19. device_class = 'mobile tablet';
  20. break;
  21. case '2':
  22. if (device_class.match(/phone/)) return;
  23. device_class = 'mobile phone';
  24. break;
  25. default:
  26. if (device_class == 'desktop') return;
  27. device_class = 'desktop';
  28. }
  29. jQuery('html').removeClass(device_classes).addClass(device_class);
  30. // handle some layout changes based on change in device
  31. var $handle = jQuery('#dokuwiki__aside h3.toggle');
  32. var $toc = jQuery('#dw__toc h3');
  33. if (device_class == 'desktop') {
  34. // reset for desktop mode
  35. if($handle.length) {
  36. $handle[0].setState(1);
  37. $handle.hide();
  38. }
  39. if($toc.length) {
  40. $toc[0].setState(1);
  41. }
  42. }
  43. if (device_class.match(/mobile/)){
  44. // toc and sidebar hiding
  45. if($handle.length) {
  46. $handle.show();
  47. $handle[0].setState(-1);
  48. }
  49. if($toc.length) {
  50. $toc[0].setState(-1);
  51. }
  52. }
  53. }
  54. jQuery(function(){
  55. var resizeTimer;
  56. dw_page.makeToggle('#dokuwiki__aside h3.toggle','#dokuwiki__aside div.content');
  57. tpl_dokuwiki_mobile();
  58. jQuery(window).on('resize',
  59. function(){
  60. if (resizeTimer) clearTimeout(resizeTimer);
  61. resizeTimer = setTimeout(tpl_dokuwiki_mobile,200);
  62. }
  63. );
  64. // increase sidebar length to match content (desktop mode only)
  65. var sidebar_height = jQuery('.desktop #dokuwiki__aside').height();
  66. var pagetool_height = jQuery('.desktop #dokuwiki__pagetools ul:first').height();
  67. // pagetools div has no height; ul has a height
  68. var content_min = Math.max(sidebar_height || 0, pagetool_height || 0);
  69. var content_height = jQuery('#dokuwiki__content div.page').height();
  70. if(content_min && content_min > content_height) {
  71. var $content = jQuery('#dokuwiki__content div.page');
  72. $content.css('min-height', content_min);
  73. }
  74. // blur when clicked
  75. jQuery('#dokuwiki__pagetools div.tools>ul>li>a').on('click', function(){
  76. this.blur();
  77. });
  78. });