-
Notifications
You must be signed in to change notification settings - Fork 18
/
site.js
executable file
·90 lines (64 loc) · 2.14 KB
/
site.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
$(function() {
//TABS
function reloadtabs(){
var hash = document.location.hash;
var example = hash.substring(1);
if(hash == '') example = 'findnotes-example'
$('.container .tabs>li>a').removeClass('active');
$('.container .content').removeClass('active');
$('.container .'+example).addClass('active');
}
window.onhashchange = reloadtabs;
reloadtabs();
//
$('.account .logout').click(function() {
$.getJSON('/logout', function (user) {
window.location = '/';
});
return false;
})
//------------------------- Get User - example -------------------------
//example_getUser.js
exampleGetUser(function(err, user) {
if(err) {
alert('Invalid Authentication')
window.location = '/';
}else{
$('#username').text(user.username)
}
})
//------------------------- Find Notes - example -------------------------
function reloadNotes(value){
//example_findNotes.js
exampleFindNotes(value, function(err,noteList) {
if(err) return null;
$('.findnotes-example ul').html('');
for(var i in noteList.notes){
var note = noteList.notes[i]
$('.findnotes-example ul').append('<li>'+note.title+'</li>')
}
})
}
reloadNotes('');
$(".findnotes-example input[type=text]").live('keyup', function () {
var value=$(".findnotes-example input[type=text]").val();
setTimeout(function(){
if ($(".findnotes-example input[type=text]").val() == value) {
//example_findNotes.js
reloadNotes(value);
}
},500);
});
//------------------------- Create Note - example -------------------------
$(".create-example>a").click(function () {
var title=$(".create-example input[type=text]").val();
var content=$(".create-example textarea").val();
if(!confirm('Do you want to create note "'+title+'"')) return;
exampleCreateNote(title,content,function(err, note) {
if(note) alert('"'+title+'" is created')
else alert('ERROR')
$(".create-example input[type=text]").val('')
content=$(".create-example textarea").val('')
})
});
})