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

theme.js « js « src - github.com/g1eny0ung/hugo-theme-dream.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1a308f1bf50b22e8fc991ed74a4093f343e81c33 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const dark = 'inverted'
const localStore = window.localStorage
let isDark = localStore.getItem('hugo-theme-dream-is-dark')
isDark = isDark ? isDark : window.defaultDark ? 'y' : isDark

const darkBackground = () => {
  if (window.backgroundDark || window.backgroundImageDark) {
    $('body').toggleClass('default').toggleClass('dark')
  }
}

const dark404 = () => {
  if (window.backgroundDark || window.backgroundImageDark) {
    const dream404 = $('.dream-404-container')

    if (dream404.length) {
      $('.dream-404-container h1').toggleClass(dark)

      const button = $('.dream-404-container button')
      button.toggleClass(dark)
      button.toggleClass('secondary')
    }
  }
}

const darkNavMenu = () => {
  if (window.backgroundDark || window.backgroundImageDark) {
    $('.dream-nav').toggleClass(dark)
  }

  const osInstance = window.overlayScrollbarsInstance
  if (window.fixedNav && osInstance && osInstance.scroll().position.y > 0) {
    $('.dream-nav').css('background', window.isDark === 'y' ? window.backgroundDark : window.background)
  }
}

const darkHeaderElements = () => {
  const header = $('.dream-header')

  if (header.length) {
    const title = $('.dream-header .ui.header')
    const iconList = $('.dream-header .ui.list')

    title.toggleClass(dark)
    iconList.toggleClass(dark)
  }
}

const darkCards = () => {
  $('.dream-card').toggleClass(dark)
}

const darkSingle = () => {
  const segments = $('.dream-single .ui.segment')

  if (segments.length) {
    segments.toggleClass(dark)

    const title = $('.dream-single h1.ui.header')
    title.toggleClass(dark)

    setThemeForUtterances()
    if (typeof setHighlightTheme === 'function') {
      setHighlightTheme()
    }

    $('.toc').toggleClass(dark)
    $('.actions').toggleClass(dark)
  }

  $('.dream-scroll-to-top').toggleClass(dark)
}

const darkTables = () => {
  $('.dream-single table').map(function () {
    if (this.style.color) {
      this.style.color = ''
    } else {
      this.style.color = 'black'
    }
  })
}

const darkPostsSection = () => {
  $('.ui.segment.dream-posts-section').toggleClass(dark)
}

const darkCategoriesSection = () => {
  $('.ui.segment.dream-categories-section').toggleClass(dark)
}

const darkTagsSection = () => {
  $('.ui.segment.dream-tags-section').toggleClass(dark)
}

const darkBack = () => {
  $('.dream-back .ui.segment').toggleClass(dark)
}

const darkFooter = () => {
  $('footer.ui.segment').toggleClass(dark)
}

const darkSearch = () => {
  $('#dream-search').toggleClass(dark)
}

function toggleDark() {
  darkBackground()
  dark404()
  darkNavMenu()
  darkHeaderElements()
  darkCards()
  darkSingle()
  darkTables()
  darkPostsSection()
  darkCategoriesSection()
  darkTagsSection()
  darkBack()
  darkFooter()
  darkSearch()

  if (Array.isArray(window.darkFunctions)) {
    darkFunctions.forEach((d) => d())
  }
}

const setThemeForUtterances = () => {
  const utterances = document.querySelector('iframe.utterances-frame')

  if (utterances) {
    utterances.contentWindow.postMessage(
      {
        type: 'set-theme',
        theme: isDark === 'y' ? 'github-dark' : 'github-light',
      },
      'https://utteranc.es'
    )
  }
}

window.addEventListener('message', (e) => {
  if (e.origin !== 'https://utteranc.es') {
    return
  }

  setThemeForUtterances()
})

const iconSwitchs = $('.theme-switch')

// Apply theme when first entering
if (isDark === 'y') {
  iconSwitchs.addClass('moon')
  toggleDark()
} else {
  iconSwitchs.addClass('sun')
}

function themeSwitch() {
  if (isDark === 'y') {
    iconSwitchs.removeClass('moon')
    iconSwitchs.addClass('sun')
    localStore.setItem('hugo-theme-dream-is-dark', 'n')
    isDark = 'n'
  } else {
    iconSwitchs.removeClass('sun')
    iconSwitchs.addClass('moon')
    localStore.setItem('hugo-theme-dream-is-dark', 'y')
    isDark = 'y'
  }

  toggleDark()
}