Welcome to mirror list, hosted at ThFree Co, Russian Federation.

toggleTheme.html « partials « layouts - github.com/darshanbaral/aafu.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 457921e58ab47b2a3aafeadc9f108c632918bf03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{{ if .Site.Params.theme.allowToggle }}
<div class="toggleSwitchContainer" style="width: 45px; height: 45px;">
  <i
    class="fas fa-toggle-on zoomlink"
    id="toggle"
    title="Toggle Theme"
    onclick="toggleTheme(this)"
  ></i>
</div>

<script>
  let mainTheme =
    "{{ print `/css/aafu_` .Site.Params.theme.mainTheme `.css` | absURL }}";
  let altTheme =
    "{{ print `/css/aafu_` .Site.Params.theme.altTheme `.css` | absURL }}";
  let toggleTheme = function(elem) {
    elem.classList.toggle("fa-toggle-off");
    elem.classList.toggle("fa-toggle-on");
    let currentCSS = document.querySelector("#color-CSS");
    if (currentCSS.href.includes(mainTheme)) {
      currentCSS.href = altTheme;
    } else {
      currentCSS.href = mainTheme;
    }
  };

  let changeThemeColor = function() {    
    themeColor.content = getComputedStyle(document.body)["background-color"];
  };
  let thisBody = document.body;
  thisBody.addEventListener("webkitTransitionEnd", changeThemeColor);
  thisBody.addEventListener("transitionend", changeThemeColor);
</script>
{{ end }}