-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
62 lines (55 loc) · 2.09 KB
/
scripts.js
File metadata and controls
62 lines (55 loc) · 2.09 KB
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
function change_page(which, page) {
//get rid of the recipe / project thats there for aesthetic reasons
if (which == 'body') {
clear_page('#recipes');
clear_page('#projects');
}
//get current page info
const $cur_page = $(which + " .visible");
const cur_id = $cur_page.attr("id");
//same page, cya later
if(cur_id == page) return;
//get new page to be displayed
let $new_page = $("#" + page);
//disables all buttons (no breaking my animations >:()
$("select").attr("disabled", "disabled");
$("#buttons li").attr("onclick", null);
//different page animation durations
let timeout = 500;
//if home page (since its 2 elements)
if(cur_id == "home") {
timeout = 1000;
$(document.getElementById("joshmage")).removeClass("img_visible").addClass("img_invisible");
}
$cur_page.removeClass("visible").addClass("invisible");
//delay so the fade out animation can play
setTimeout(function () {
//page gone for good now
$cur_page.css("display", "none");
//home page stuff again
if(page == "home"){
//change link
window.history.pushState("", "", "/");
$(document.getElementById("joshmage")).removeClass("img_invisible").addClass("img_visible");
}else if(which == 'body'){
window.history.pushState("", "", "/#" + page);
}
//new page can be displayed now + animation
$new_page.css("display", "block");
$new_page.removeClass("invisible").addClass("visible");
//renable all buttons :)
$("select").removeAttr("disabled");
$("#buttons li").each(function () {
const text = $(this).text().toLowerCase().trim();
$(this).attr("onclick","change_page('body', '" + text +"')");
});
}, timeout);
}
function clear_page(which){
//this recipe must leave in a timely order
setTimeout(function () {
const $cur_page = $(which + " .visible");
$cur_page.removeClass("visible").addClass("invisible");
$("select").val("none");
}, 500);
}