xref: /template/kiwiki/script.js (revision c17c23bd1b4ad0417bc7fdb3f7a48d1ac4897578)
1(function ($) {
2  "use strict";
3  function _kiwikiChangeAdminLabels(label, level, title) {
4    $(label)
5      .parent()
6      .parent()
7      .html(
8        '<td colspan="2" class="kiwiki-styles"><' +
9          level +
10          ">" +
11          title +
12          "</" +
13          level +
14          "></td>"
15      );
16  }
17
18  var colorscheme = "lightmode";
19  if($.cookie("theme")=="system-color"){
20    if (
21      window.matchMedia &&
22      window.matchMedia("(prefers-color-scheme: dark)").matches
23    ) {
24      colorscheme = "darkmode";
25      document.cookie = "theme=darkmode;path=/;";
26      $("body").removeClass("lightmode");
27      $("body").addClass("darkmode");
28    }else{
29      document.cookie = "theme=lightmode;path=/;";
30      $("body").removeClass("darkmode");
31      $("body").addClass("lightmode");
32    }
33  }
34
35  /*close the toc on mobile*/
36  function updateTocClass() {
37    if ($(window).width() < 950) {
38      var $toc = $('#dw__toc h3');
39      console.log($toc);
40      $toc[0].setState(-1);
41
42    }
43  }
44
45  $(window).on("resize", updateTocClass);
46  $(document).ready(updateTocClass);
47
48  $(document).on("click", function (event) {
49    var trigger = $("nav.tools>div,div#dokuwiki__pagetools");
50    var search = $("div#open-search");
51    var thememode = $("div#theme-mode");
52    var fullscreen = $("div#full-screen");
53    var openmenu = $("#kiwiki-main-menu__open");
54    var closemenu = $("#kiwiki-main-menu__close, .kiwiki-main-menu-overlay");
55    var menu = $(
56      "#kiwiki #dokuwiki__site #dokuwiki__content__wrapper #dokuwiki__aside .kiwiki-main-menu h3"
57    );
58
59    if ($(event.target).is(trigger)) {
60      if (!$(event.target).hasClass("active")) {
61        $(trigger).removeClass("active");
62        $(event.target).addClass("active");
63      }
64    } else {
65      $(trigger).removeClass("active");
66    }
67
68    if ($(event.target).is(search)) {
69      $(
70        "#dokuwiki__header > .dokuwiki__header__wrapper #dw__search"
71      ).toggleClass("open");
72    }
73    if ($(event.target).is(fullscreen)) {
74      $("body").toggleClass("fullscreen");
75    }
76    if ($(event.target).is(menu)) {
77      $(menu).parent().toggleClass("open");
78    }
79    if ($(event.target).is(openmenu)) {
80      $(".kiwiki-main-menu__wrapper").addClass("open");
81    }
82    if ($(event.target).is(closemenu)) {
83      $(".kiwiki-main-menu__wrapper").removeClass("open");
84    }
85
86    if ($(event.target).is(thememode)) {
87      if (!!$.cookie("theme")) {
88        if (!$("body").hasClass("darkmode")) {
89          $("body").removeClass("lightmode");
90          $("body").addClass("darkmode");
91          document.cookie = "theme=darkmode;path=/;";
92        } else {
93          $("body").removeClass("darkmode");
94          $("body").addClass("lightmode");
95          document.cookie = "theme=lightmode;path=/;";
96        }
97      } else {
98        if (colorscheme == "darkmode") {
99          $("body").addClass("lightmode");
100          document.cookie = "theme=lightmode;path=/;";
101        } else {
102          $("body").addClass("darkmode");
103          document.cookie = "theme=darkmode;path=/;";
104        }
105      }
106
107      /**/
108    }
109  });
110
111
112  _kiwikiChangeAdminLabels(
113    'label[for="tpl____kiwiki_color__"]',
114    "h3",
115    "Kiwiki"
116  );
117  _kiwikiChangeAdminLabels(
118    'label[for="tpl____kiwiki_light_colors__"]',
119    "h4",
120    "Light mode colors"
121  );
122  _kiwikiChangeAdminLabels(
123    'label[for="tpl____kiwiki_dark_colors__"]',
124    "h4",
125    "Dark mode colors"
126  );
127})(jQuery);
128