-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfess.js
71 lines (57 loc) · 1.98 KB
/
confess.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
//Count characters
$('#confession-textbox').keyup(function() {
var max = 1000;
var min = 20;
var len = $(this).val().length;
if (len >= max) {
$('#charNum').text(messages.charlimitreached);
} else {
var char = max - len;
$('#charNum').text(char + messages.charleft);
}
});
//Upload Confession
$(document).on('click', '.confess-btn', function() {
var text = $('#confession-textbox').val();
if (text.length < 20) {
$('#conf-short').fadeIn(400);
$('#conf-short').delay(3000).fadeOut(400);
} else {
$("#confession-textbox").val('');
$.ajax({
type: 'POST',
url: 'includes/upload_confession.php',
data: {
confession: text
},
success: function(data) {
if (data.status === 'ok') {
$.cookie('perday', 'true', {
expires: 1
});
$('#conf-success').fadeIn(400);
$('#conf-success').delay(3000).fadeOut(400);
setTimeout(function() {
$(location).attr('href', 'index.php');
}, 3800);
} else if (data.status === 'limit_reached') {
$('#conf-limit').fadeIn(400);
$('#conf-limit').delay(3000).fadeOut(400);
setTimeout(function() {
$(location).attr('href', 'index.php');
}, 3800);
} else {
$('#conf-error').fadeIn(400);
$('#conf-error').delay(3000).fadeOut(400);
setTimeout(function() {
$(location).attr('href', 'index.php');
}, 3800);
}
},
error: function() {
$('#conf-error').fadeIn(400);
$('#conf-error').delay(3000).fadeOut(400);
}
});
}
});