-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
191 lines (155 loc) · 5.51 KB
/
script.js
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// $("header").load("./partials/header.html");
var mode = localStorage['mode'] || 'light';
localStorage['mode'] = mode;
if (mode == 'dark'){
$("body").addClass("dark");
$("#mode-toggler").html("Switch to light mode");
$('meta[name="theme-color"]').attr("content","#000");
$('meta[name="msapplication-navbutton-color"]').attr("content","#000");
$('meta[name="apple-mobile-web-app-status-bar-style"]').attr("content","#000");
}
$.ajax({
type: "GET",
url: "./partials/header.html",
success: function(data){
$('header').css("display", "none");
$('header').html(data);
hash_checker();
}
});
function show_loader(){
if ($(".loader").css("display") == "none")
$(".loader").css("display","block");
}
function hide_loader(){
$(".loader").css("display","none");
}
function hash_checker(){
var hash = window.location.hash;
var page_set = ['home','about','events','team','contact'];
var res = hash.split('/');
val = (page_set.indexOf(res[1]) > -1) ? res[1] : page_set[0];
page_switch(val);
}
function page_switch(val){
$('ul.navbar-nav>li').removeClass('active');
show_loader();
$.ajax({
type: "GET",
url: "./partials/"+val+".html",
cache: false, //(val == 'events'),
success: function(data){
$('main').fadeOut("fast",function(){
$("main").html("");
if (val == "home")
$('header').fadeOut("fast");
else
$('header').fadeIn("fast");
$("main").html(data);
$("title").html(val.charAt(0).toUpperCase() + val.slice(1)+" | Mathematics Society, IIT Delhi");
if ($("#mode-toggler-switch").length > 0){
if ($("body").hasClass("dark")){
$("#mode-toggler-switch>input").prop("checked",true);
$(".for-light-text").css("display","block");
$(".for-dark-text").css("display", "none");
$('meta[name="theme-color"]').attr("content","#000");
$('meta[name="msapplication-navbutton-color"]').attr("content","#000");
$('meta[name="apple-mobile-web-app-status-bar-style"]').attr("content","#000");
}
else{
$(".for-light-text").css("display","none");
$(".for-dark-text").css("display", "block");
$('meta[name="theme-color"]').attr("content","#fff");
$('meta[name="msapplication-navbutton-color"]').attr("content","#fff");
$('meta[name="apple-mobile-web-app-status-bar-style"]').attr("content","#fff");
}
}
$(window).scrollTop(0);
$('main').fadeIn();
//$('main>*').fadeOut();
history.replaceState(undefined, undefined, "#/"+val+'/');
hide_loader();
$('ul.navbar-nav>li#nav-'+val).addClass('active');
});
}
});
}
/*
$(".nav-link").click(function() {
res = $(this).attr("href").split('/')[1];
$('#'+res).fadeOut();
//alert(res);
//update hash
})
*/
$(window).on("scroll",function() {
var scroll = $(window).scrollTop();
if (scroll >= 10) {
$("header>div.navigation-wrap").removeClass('start-style').addClass("scroll-on");
} else {
$("header>div.navigation-wrap").removeClass("scroll-on").addClass('start-style');
}
});
//Menu On Hover
$('body').on('mouseenter mouseleave','.nav-item',function(e){
if ($(window).width() > 750) {
var _d=$(e.target).closest('.nav-item');_d.addClass('show');
setTimeout(function(){
_d[_d.is(':hover')?'addClass':'removeClass']('show');
},1);
}
});
// Close Nav in mobile after click
$('header').on('click','.nav-link',function(){
if ($('.navbar-toggler').css("display") != "none"){
$('.navbar-toggler').trigger('click');
}
})
$("body").on("click","#mode-toggler",function(){
if ($("#mode-toggler-switch").length > 0)
$("#mode-toggler-switch>input").trigger("change");
else{
if ($("body").hasClass("dark")) {
$("body").removeClass("dark");
$("#mode-toggler").html("Switch to dark mode");
localStorage['mode'] = 'light';
$('meta[name="theme-color"]').attr("content","#fff");
$('meta[name="msapplication-navbutton-color"]').attr("content","#fff");
$('meta[name="apple-mobile-web-app-status-bar-style"]').attr("content","#fff");
}
else {
$("body").addClass("dark");
$("#mode-toggler").html("Switch to light mode");
localStorage['mode'] = 'dark';
$('meta[name="theme-color"]').attr("content","#000");
$('meta[name="msapplication-navbutton-color"]').attr("content","#000");
$('meta[name="apple-mobile-web-app-status-bar-style"]').attr("content","#000");
}
}
});
$("body").on("change","#mode-toggler-switch>input",function(){
if ($("body").hasClass("dark")) {
$("body").removeClass("dark");
$("#mode-toggler-switch>input").prop("checked",false);
$("#mode-toggler").html("Switch to dark mode");
$(".for-light-text").fadeOut("fast",function(){
$(".for-dark-text").fadeIn();
});
localStorage['mode'] = 'light';
$('meta[name="theme-color"]').attr("content","#fff");
$('meta[name="msapplication-navbutton-color"]').attr("content","#fff");
$('meta[name="apple-mobile-web-app-status-bar-style"]').attr("content","#fff");
}
else {
$("body").addClass("dark");
$("#mode-toggler-switch>input").prop("checked",true);
$("#mode-toggler").html("Switch to light mode");
$(".for-dark-text").fadeOut("fast",function(){
$(".for-light-text").fadeIn();
});
localStorage['mode'] = 'dark';
$('meta[name="theme-color"]').attr("content","#000");
$('meta[name="msapplication-navbutton-color"]').attr("content","#000");
$('meta[name="apple-mobile-web-app-status-bar-style"]').attr("content","#000");
}
})