-
Notifications
You must be signed in to change notification settings - Fork 2
/
Index.html
186 lines (172 loc) · 5.29 KB
/
Index.html
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
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">
<title>YANA Home</title>
</head>
<style>
div.pcon{
width:100%;
background-color:#f2f2f2;
}
div.ptit{
width:100%;
display:block;
}
.pdiv {
border: 2px solid black;
border-radius: 10px;
width:70%;
padding:10px;
margin-left:20px;
}
</style>
<script type="text/javascript">
var xhr = new XMLHttpRequest();
var xhr1 = new XMLHttpRequest();
var id = 0;var data = [];
//document.body.onscroll = fetch;
//var scr1;
count=0;
scrollamt=200;
function getContent(){
console.log(document.body.scrollTop);
if(document.body.scrollTop>scrollamt || document.documentElement.scrollTop>scrollamt)
{
posts();
scrollamt+=200;
}
}
window.onscroll=getContent;
function posts(){
id = id+10;
xhr1.onreadystatechange = print_posts;
xhr1.open("GET","fetch_posts.php?id="+id,true);
xhr1.send()
}
function init(){
xhr.onreadystatechange = set_usr;
xhr.open("GET","login_check.php",true);console.log("checking...");
xhr.send();
posts()
}
function print_posts(){
if(xhr1.readyState == 4 && xhr1.status == 200){
//console.log(xhr1.responseText);
var res = JSON.parse(xhr1.responseText);
var new_dat_len = res.length;
var old_dat_len = data.length;
//data.push(res:res);
for(var j = 0;j<new_dat_len;j++)
data.push(res[j]);
console.log(data);
for(var i=old_dat_len; i< old_dat_len+new_dat_len;i++){
//data.push(res[i]);
var pdiv = document.createElement("div");
var pusr = document.createElement("div");
var ptit = document.createElement("div");
var pcon = document.createElement("div");
pdiv.setAttribute("class","pdiv");
pusr.setAttribute("class","pusr");
ptit.setAttribute("class","ptit");
pcon.setAttribute("class","pcon");
pdiv.setAttribute("id","p_"+data[i].id);
pcon.setAttribute("id","c_"+data[i].id);
pusr.innerHTML = "<h4><b><u>@"+data[i].username+"</u></b></h4>";
ptit.innerHTML = "<b><i>"+data[i].title+"</i></b>";
pdiv.setAttribute("onclick","expand_post("+data[i].id+")");
var p = document.getElementById("post_container");
pdiv.appendChild(pusr);
pdiv.appendChild(ptit);
pdiv.appendChild(pcon);
p.appendChild(pdiv);
p.appendChild(document.createElement("br"));
// console.log(data[i]);
}
}
}
function expand_post(pid){
ps = document.getElementById("p_"+pid);
for(i = 0;i<data.length;i++){
if(data[i].id == pid){
con = data[i].content;
//console.log(con);
p = document.getElementById("c_"+pid)
p.appendChild(document.createElement("br"));
p.innerHTML = con;
}
}
}
function set_usr(){
if(xhr.readyState == 4 && xhr.status == 200){
if(xhr.responseText != "-1"){
document.getElementById("d_1").innerHTML = xhr.responseText;
document.getElementById("d_2").innerHTML = "Logout";
document.getElementById("d_2").setAttribute("onclick","logout()");
document.getElementById("d_2").setAttribute("href","Index.html");
console.log("changed!");
}
else {
document.getElementById("d_1").innerHTML = "Login";
document.getElementById("d_2").innerHTML = "About";
document.getElementById("d_1").setAttribute("href","Login.html");
document.getElementById("d_2").setAttribute("href","about.html");
}
}
}
function logout(){
xhr.open("GET","logout.php",true);console.log("logging out...");
xhr.send();
}
</script>
<body onload="init()">
<nav class="navbar navbar-inverse navbar-fixed-top" id="navv">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapsemenu">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.html" class="navbar-brand">YANA</a>
</div>
<div class="collapse navbar-collapse" id="collapsemenu">
<ul class="nav navbar-nav navbar-right ">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="">Profile</a></li>
<li><a href="">Catagories</a></li>
<li><a href="new_post.html">Post</a></li>
<li>
<a class="dropdown-toggle" data-toggle="dropdown" role="button" href="">More<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a id="d_1">Login</a></li>
<li><a id="d_2">Sign Up</a></li>
</ul>
</li>
<!-- <button type="button" class="btn btn-default navbar-btn navbar-right">Sign out</button>
--> </ul>
</div>
</div>
</nav>
<div id="post_container">
</div>
<div class="jumbotron center" id="jumbo1">
<h1>Yet Another News Aggrigator</h1>
</div>
<div id="jumb0">
<div class="container center">
<h2>Desinged By Team NPN</h2>
</div>
</div>
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script >
$(document).scroll(function() {
$("#navv").css("background-color","rgba(0,0,0,1)");
});
</script>
</body>
</html>