Skip to content

Commit

Permalink
Move some properties to dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWillCom committed Aug 27, 2024
1 parent 8945ad3 commit 63d82f6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-masks-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hexo-theme-cupertino': minor
---

Move the exported configurations in the global object called `ThemeCupertino` to the dataset of body.
8 changes: 1 addition & 7 deletions layout/_partial/head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,7 @@
<% if (page.type == 'categories') { %>
<%- css('css/categories') %>
<% } %>
<script>
ThemeCupertino = {}
</script>
<% if (theme.scroll_reveal) { %>
<script>
ThemeCupertino['scrollRevealDisappear'] = <%- JSON.stringify(theme.scroll_reveal_disappear) %>
ThemeCupertino['scrollRevealQuery'] = <%- JSON.stringify(theme.scroll_reveal_query) %>
</script>
<%- css('css/scroll-reveal') %>
<% } %>
<% if (theme.view_transition) { %>
Expand All @@ -147,5 +140,6 @@
<link rel="stylesheet" href="<%- getCdnUrl('@waline/client', 'v2', 'dist/waline.css') %>" />
<% } %>

<script>var ThemeCupertino = {}</script>
<%- theme.insertions.head.ending %>
</head>
4 changes: 4 additions & 0 deletions layout/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<% if (theme.search == true && page.type == 'search') { %>
data-search-path="<%= theme.search_path %>"
<% } %>
<% if (theme.scroll_reveal) { %>
data-scroll-reveal-disappear="<%= theme.scroll_reveal_disappear %>"
data-scroll-reveal-query="<%= theme.scroll_reveal_query %>"
<% } %>
>
<a href="#main-content" id="skip-to-content"><%- __('skip_to_content') %></a>
<%- partial('_partial/nav') %>
Expand Down
12 changes: 7 additions & 5 deletions source/js/scroll-reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ ThemeCupertino['ScrollReveal'] = new (class {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('scroll-reveal-show')
} else if (ThemeCupertino.scrollRevealDisappear) {
} else if (document.body.dataset.scrollRevealDisappear) {
entry.target.classList.remove('scroll-reveal-show')
}
})
})

document.querySelectorAll(ThemeCupertino.scrollRevealQuery).forEach(el => {
el.classList.add('scroll-reveal')
this.observer.observe(el)
})
document
.querySelectorAll(document.body.dataset.scrollRevealQuery)
.forEach(el => {
el.classList.add('scroll-reveal')
this.observer.observe(el)
})
}

/**
Expand Down

0 comments on commit 63d82f6

Please sign in to comment.