-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
192 lines (165 loc) · 5.41 KB
/
common.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
190
191
192
function likeIt(heart){
//alert(heart.nextSibling.innerHTML);
var id=heart.parentNode.elements['hiddenPostId'].value;
var request = new XMLHttpRequest();
var param="postId="+id;
var number=heart.parentNode.getElementsByClassName('number')
request.open('POST','like.php',true);
request.onreadystatechange=function(){
console.log(request.responseText);
if(request.readyState == 4 && request.status == 200){
//if a person is not friend and likes on post are 0 then 0 is being returned but there is no alert because of the condition fix it later
if(request.responseText > 0 && request.responseText != 'fault'){
if(request.responseText.slice(0,1)=="n"){
heart.className='material-icons md-24 unchkd';
alert("You're not freinds with the person send a request to get connected ;)");
}
else
heart.className='material-icons md-24 chkd';
number[0].innerHTML=request.responseText+" likes";
}else{
heart.className='material-icons md-24 unchkd';
var rspns=request.responseText;
rspns=rspns.slice(1,rspns.length);
console.log(rspns);
number[0].innerHTML=rspns+" likes";
}
}
};
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//necessary header for post requests
request.send(param);
}
function deletePost(bin){
var id=bin.parentNode.elements['hiddenPostId'].value;
var request = new XMLHttpRequest();
request.open("POST","delete.php",true);
request.onreadystatechange= function(){
if(request.readyState==4 && request.status==200){
if(request.responseText=='d'){
console.log(request.responseText);
bin.parentNode.parentNode.style.display="none";
}
else{
console.log(request.responseText);
}
}
};
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("postId="+id);
}
function deleteComment(bin){
var id=bin.parentNode.elements['hiddenCommentId'].value;
var pid=bin.parentNode.elements['hiddenPostId'].value;
var request = new XMLHttpRequest();
request.open("POST","deleteComment.php",true);
request.onreadystatechange= function(){
if(request.readyState==4 && request.status==200){
if(request.responseText.slice(0,1)=='d'){
console.log(request.responseText);
bin.parentNode.parentNode.parentNode.style.display="none";
document.getElementById('comNumber1').innerHTML=request.responseText.slice(1,request.responseText.length)+" comments";
}
else{
console.log(request.responseText);
}
}
};
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("commentId="+id+"&postId="+pid);
}
function logout(a){
a.parentNode.submit();
}
function home(){
window.location="home.php";
}
function messages(){
window.location="messages.php";
}
function profile(){
window.location="profile.php?personId="+document.getElementById('idd').value;
}
function goToComments(pen){
var id=pen.parentNode.submit();
console.log(pen.parentNode.nodeName);
}
function sendRequest(but){
but.parentNode.submit();
}
function showMe(hoot){
hoot.parentNode.submit();
}
function requestPage(){
window.location="requests.php";
}
function accept(yes){
var id=yes.parentNode.parentNode.elements['chillz'].value;
var request=new XMLHttpRequest();
request.open("POST","accept.php",true);
request.onload=function(){
if(request.responseText=='done')
yes.parentNode.parentNode.innerHTML="You are now friends";
};
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("senderId="+id);
}
function addPostImage(postPic){
postPic.parentNode.parentNode.elements['pImage'].click();
}
/*function unfriend(uf){
var id=uf.parentNode.elements['unfriendId'].value;
var request=new XMLHttpRequest();
request.open("POST","unfriend.php",true);
request.onload=function(){
if(request.responseText=='done'){
uf.parentNode.parentNode.parentNode.style.display="none";
}
}
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("unfriendId="+id);
}*/
function unfriend(uf){
var id=uf.parentNode.submit();
}
function ignore(no){
var id=no.parentNode.parentNode.elements['chillz'].value;
var request=new XMLHttpRequest();
request.open("POST","ignore.php",true);
request.onload=function(){
if(request.responseText=='done')
no.parentNode.parentNode.style.display="none";
};
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("senderId="+id);
}
function change(ch) {
var file=document.getElementById('picpic');
file.click();
document.getElementById('chbut').style.display="block";
}
function showLikes(ll){
window.location="showLikes.php?postId="+ll.parentNode.elements['hiddenPostId'].value;
}
function makeProPic(mkpp){
var id=mkpp.parentNode.elements['pictureId'].value;
var request=new XMLHttpRequest();
request.open("POST","pictureAction.php",true);
request.onload=function(){
if(request.responseText=='done1'){
}
}
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("pictureId="+id+"&code=1");
}
function deletePic(delP){
var id=delP.parentNode.elements['pictureId'].value;
var request=new XMLHttpRequest();
request.open("POST","pictureAction.php",true);
request.onload=function(){
if(request.responseText=='done2'){
delP.parentNode.parentNode.parentNode.style.display="none";
}
}
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("pictureId="+id+"&code=2");
}