1
2
3  /* day/night toggle  */
4  function tpl_toggleLight() {
5     if (DokuCookie.getValue('dark')==1)
6     {
7          DokuCookie.setValue('dark','0');
8        jQuery('body').toggleClass('dark');
9        return false;
10     }
11     else
12     {
13        DokuCookie.setValue('dark','1');
14        jQuery('body').toggleClass('dark');
15        return false;
16      }
17   }
18
19
20(function($) {
21    var fadeOption = {duration: 1};
22    var device_class = ''; // not yet known
23    var device_classes = 'mobile wide desktop tablet phone';
24    var resizeTimer;
25    function toggleLeft() {
26        $('#nav_bg').show('fade', fadeOption);
27        $('#dokuwiki__nav').show();
28    }
29
30    function toggleRight() {
31        $('#sidebar_bg').show('fade', fadeOption);
32        $('#dokuwiki__aside').show();
33    }
34
35    function preventParentWheel(e) {
36        var curScrollPos = $(this).scrollTop();
37        var scrollableDist = $(this).prop('scrollHeight') - $(this).outerHeight();
38        var wheelEvent = e.originalEvent;
39        var dY = wheelEvent.deltaY;
40
41        if (dY < 0 && curScrollPos <= 0) {
42            return false;
43        }
44        if (dY > 0 && curScrollPos >= scrollableDist) {
45            return false;
46        }
47    }
48
49    function checkWidth() {
50        // the z-index in mobile.css is (mis-)used purely for detecting the screen mode here
51    var screen_mode = jQuery('#screen__mode').css('z-index') + '';
52
53    // determine our device pattern
54    // TODO: consider moving into dokuwiki core
55    switch (screen_mode) {
56        case '1':
57            if (device_class.match(/phone/)) return;
58            device_class = 'mobile phone';
59			$('#dokuwiki__aside').hide();
60            break;
61        case '2':
62            if (device_class.match(/tablet/)) return;
63            device_class = 'mobile tablet';
64			$('#dokuwiki__aside').hide();
65            break;
66        case '3':
67            if (device_class.match(/desktop/)) return;
68            device_class = 'desktop';
69			$('#dokuwiki__aside').show();
70            break;
71        default:
72            if (device_class.match(/wide/)) return;
73			$('#dokuwiki__aside').show();
74            device_class = 'wide';
75    }
76
77    jQuery('html').removeClass(device_classes).addClass(device_class);
78    }
79
80
81    function bindEvents() {
82        $('.sidebar').on('wheel scroll', preventParentWheel);
83        $('.btn_left').click(function() {
84            toggleLeft();
85        });
86        $('.btn_right').click(function() {
87            toggleRight();
88        });
89        $('#sidebar_bg').click(function() {
90            $(this).hide('fade', fadeOption);
91            if (device_class.match(/mobile/))
92            $('#dokuwiki__aside').hide();
93        });
94        $('#nav_bg').click(function() {
95            $(this).hide('fade', fadeOption);
96            $('#dokuwiki__nav').hide();
97			jQuery('.btn_left i').removeClass('fa-spin');
98        });
99        $('.btn_search').click(function() {
100            $('div.search').toggle();
101            $('div.search').find('input.edit').focus();
102        });
103        jQuery(window).bind('resize',
104        function(){
105            if (resizeTimer) clearTimeout(resizeTimer);
106            resizeTimer = setTimeout(checkWidth,200);
107        });
108    }
109
110    function initUI() {
111        // Move TOC
112        if ($('#dokuwiki__content h2').length > 0) {
113            $('#dw__toc').insertBefore($('#dokuwiki__content h2:first'));
114        } else {
115            $('#dw__toc').insertAfter($('#dokuwiki__content h1:first').next('.level1'));
116        }
117        // Anchor link should be shifted by header pixel
118        $(window).on("hashchange", function () {
119            window.scrollTo(window.scrollX, window.scrollY - 48);
120        });
121    }
122
123    $(function() {
124        initUI();
125         checkWidth();
126        bindEvents();
127    });
128})(jQuery);
129
130
131