Skip to content

Commit 9894421

Browse files
authored
Add swiping on mobile to open the sidebar (#31)
2 parents 6148e6b + 3e912bb commit 9894421

File tree

6 files changed

+70
-32
lines changed

6 files changed

+70
-32
lines changed

README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
[![hugo github pages](https://github.com/MinecraftTAS/minecrafttas.com/actions/workflows/gh-pages.yaml/badge.svg)](https://test.minecrafttas.com)
21
The source code for https://minecrafttas.com
32

4-
Uses a completely custom theme that I would not recommend to copy...
3+
Uses a custom theme.
54
## Installation
6-
1. Download [Hugo Extended](https://github.com/gohugoio/hugo/releases) (hugo_extended_\<number\>_windows-amd64)
7-
2. Extract it and put it in the mctas.com folder
8-
3. Run `./hugo.exe server` or `./startserver.sh`
9-
5. Open `http://localhost:1313/`
5+
Download and install Hugo Extended, either via the [releases page](https://github.com/gohugoio/hugo/releases) or by using
6+
```
7+
winget install Hugo.Hugo.Extended
8+
```
9+
And that's it! No other dependencies needed! Hugo Extended comes with Sass support for css and we use *raw* JavaScript for our needs, which is kind of a cleansing experience...
1010

1111
## Contributing
1212
Want to add new pages and guides? Add a markdown file into the content folder and choose a subdirectory. The html will be automatically generated.
1313

1414
You may also use the command `hugo new <filename>.md` or `hugo new <directory>/<filename>.md` to let hugo initialize a new file with a template.
1515

16-
### HTML in markdown
17-
To add html to your markdown simply encase the tags with `{{<rawhtml>}}`
18-
```html
19-
{{<rawhtml>}}
20-
<p> Your html code here! <p>
21-
{{</rawhtml>}}
22-
```
16+
### Shortcodes
17+
Our custom template features a bunch of shortcodes
18+
A list is available on the [Wiki](https://github.com/MinecraftTAS/minecrafttas.com/wiki/Shortcodes)
2319

2420
## Generating
2521
Running `hugo` will generate the html files in the `public/` directory

assets/scss/styles.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ nav.mainNav {
151151
max-height: 60%;
152152
max-width: 30%;
153153
top: 10rem;
154+
left: -1000px;
154155

155156
@media screen and (max-width: 850px) {
156157
top: initial;
@@ -185,7 +186,7 @@ nav.mainNav {
185186
}
186187

187188
.buttonclose {
188-
background-color: $bg-color, 20%;
189+
background-color: $bg-color;
189190
background-image: url(/images/OpenCloseArrow.svg);
190191
background-repeat: no-repeat;
191192
background-size: cover;
@@ -305,6 +306,7 @@ section {
305306
background-color: #272822;
306307
border-radius: 10px;
307308
padding: 15px;
309+
overflow-x: auto;
308310

309311
code {
310312
background-color: initial;

content/downloads/playback/tasmod.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ prev: false
99
---
1010

1111
{{<rawhtml>}}
12-
<p align="center"><img src="https://minecrafttas.com/images/TASmodLogo.svg" alt="Logo" width="500"></p>
12+
<p align="center"><img class="screenshot" src="https://minecrafttas.com/images/TASmodLogo.svg" alt="Logo"></p>
1313
{{</rawhtml>}}
1414

1515
A [Tool-Assisted Speedrun](https://tasvideos.org/WelcomeToTASVideos) mod for Minecraft.

layouts/baseof.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
{{ end }}
3030
<meta property="og:description" content="{{.Description}}">
3131

32-
<script src="/js/link-headings.js" defer async></script>
32+
<script src="/js/link-headings.js" defer async="false"></script>
3333
{{ end }}
3434
<meta name="keywords" content="Minecraft, TAS, Tool-Assisted Speedrun, Modification, Playback, Non-Playback">
3535
<meta name="viewport" content="width=device-width, initial-scale=1">

startserver.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

static/js/sidebar-open.js

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,90 @@
11
let buttonelem = document.getElementsByClassName("buttonclose")[0]
2-
buttonelem.addEventListener("click", ()=>{
2+
buttonelem.addEventListener("click", () => {
33
addTransition(true)
44
toggle()
55
})
66

77
let wrapper = document.getElementsByClassName("toc--wrapper")[0]
88
let toc = document.getElementsByClassName("toc")[0]
9-
wrapper.style.left = -(toc.getBoundingClientRect().width+7)+"px"
9+
wrapper.style.left = -(toc.getBoundingClientRect().width + 7) + "px"
1010

1111
let isOpen = localStorage.getItem("sidebar") !== null ? true : false
1212
open(isOpen)
1313

1414
addEventListener('resize', (event) => {
15-
if(wrapper.classList.contains("opened")){
16-
wrapper.style.transform = "translate("+(toc.getBoundingClientRect().width+7)+"px)"
15+
if (wrapper.classList.contains("opened")) {
16+
wrapper.style.transform = "translate(" + (toc.getBoundingClientRect().width + 7) + "px)"
1717
}
18-
wrapper.style.left = -(toc.getBoundingClientRect().width+7)+"px"
18+
wrapper.style.left = -(toc.getBoundingClientRect().width + 7) + "px"
1919
});
2020

21-
function toggle(){
21+
function toggle() {
2222
let wrapper = document.getElementsByClassName("toc--wrapper")[0]
2323
open(!wrapper.classList.contains("opened"))
2424
}
2525

26-
function open(open){
26+
function open(open) {
2727
let wrapper = document.getElementsByClassName("toc--wrapper")[0]
28-
if(!open){
28+
if (!open) {
2929
wrapper.classList.remove("opened")
3030
wrapper.style.transform = "initial"
3131
localStorage.removeItem("sidebar")
32-
}else{
32+
} else {
3333
wrapper.classList.add("opened")
34-
wrapper.style.transform = "translate("+(toc.getBoundingClientRect().width+7)+"px)"
34+
wrapper.style.transform = "translate(" + (toc.getBoundingClientRect().width + 7) + "px)"
3535
localStorage.setItem("sidebar", "open")
3636
}
3737
}
3838

39-
function addTransition(add){
39+
function addTransition(add) {
4040
let wrapper = document.getElementsByClassName("toc--wrapper")[0]
41-
let button = document.getElementsByClassName("buttonclose")[0]
42-
if(add){
41+
let button = document.getElementsByClassName("buttonclose")[0]
42+
if (add && !wrapper.classList.contains("transitioner")) {
4343
wrapper.classList.add("transitioner")
4444
button.classList.add("transitioner")
45-
}else{
45+
} else if(!add && wrapper.classList.contains("transitioner")) {
4646
wrapper.classList.remove("transitioner")
4747
button.classList.remove("transitioner")
4848
}
49-
}
49+
}
50+
51+
document.addEventListener('touchstart', handleTouchStart, false);
52+
document.addEventListener('touchmove', handleTouchMove, false);
53+
54+
var xDown = null;
55+
var yDown = null;
56+
57+
function getTouches(evt) {
58+
return evt.touches || // browser API
59+
evt.originalEvent.touches; // jQuery
60+
}
61+
62+
function handleTouchStart(evt) {
63+
const firstTouch = getTouches(evt)[0];
64+
xDown = firstTouch.clientX;
65+
yDown = firstTouch.clientY;
66+
};
67+
68+
function handleTouchMove(evt) {
69+
if (!xDown || !yDown) {
70+
return;
71+
}
72+
73+
var xUp = evt.touches[0].clientX;
74+
var yUp = evt.touches[0].clientY;
75+
76+
var xDiff = xDown - xUp;
77+
var yDiff = yDown - yUp;
78+
79+
if (Math.abs(xDiff) > Math.abs(yDiff)) {/*most significant*/
80+
if (xDiff > 200) {
81+
/* right swipe */
82+
addTransition(true)
83+
open(false)
84+
} else if (xDiff < -100) {
85+
/* left swipe */
86+
addTransition(true)
87+
open(true)
88+
}
89+
}
90+
};

0 commit comments

Comments
 (0)