utils.js
2.72 KB
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
var ConfJuvAppUtils = {
pathTo: function(endpoint, noPrefix) {
var prefix = '/api/' + ConfJuvAppConfig.noosferoApiVersion + '/';
if (noPrefix) {
prefix = '/';
}
return ConfJuvAppConfig.noosferoApiHost + prefix + endpoint;
},
normalizeLogin: function(login) {
return login.replace(/@.*/g, '').toLowerCase().replace(' ', '-').replace(/[^a-z0-9-]/g, '');
},
setPrivateToken: function(value) {
if (value == undefined || value == '' || value == null) {
window.localStorage.removeItem('private_token');
}
else {
window.localStorage['private_token'] = value;
}
},
getPrivateToken: function() {
return window.localStorage['private_token'];
},
shareOnTwitter: function() {
var title = document.getElementById('proposal-title').innerHTML,
id = document.getElementById('proposal-id').innerHTML,
text = 'Comente minha proposta para a #3ConfJuv: ' + title + ' ' + ConfJuvAppConfig.noosferoApiPublicHost + '/?proposal=' + id,
url = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(text);
return url;
},
shareOnFacebook: function() {
var title = document.getElementById('proposal-title').innerHTML,
id = document.getElementById('proposal-id').innerHTML,
link = ConfJuvAppConfig.noosferoApiPublicHost + '/?proposal=' + id,
url = 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(link);
return url;
},
dateDiff: function(start, end) {
var oneday = 24 * 60 * 60 * 1000, // hours * minutes * seconds * milliseconds
today = new Date(),
msg = '',
s = start.split('/'),
e = end.split('/');
start = new Date(s[2], parseInt(s[1]) - 1, s[0]);
end = new Date(e[2], parseInt(e[1]) - 1, e[0]);
if (today > start && today < end) {
start = today;
var days = Math.round(Math.abs((start.getTime() - end.getTime())/(oneday)));
msg = '+ ' + days + ' dia';
if (days > 1) {
msg += 's';
}
}
else {
msg = s[0] + '/' + s[1] + ' a ' + e[0] + '/' + e[1];
}
return msg;
},
setTopicFilter: function(value) {
if (value == undefined || value == '' || value == null) {
window.localStorage.removeItem('topic_filter');
}
else {
window.localStorage['topic_filter'] = value;
}
},
getTopicFilter: function() {
var value = window.localStorage['topic_filter'];
if (value == null) {
value = 'all';
}
return value;
},
sawIntro: function() {
return window.localStorage['saw_intro_3'];
}
};
document.addEventListener('backbutton', function(event) {
if ($('#login-modal').is(':visible')) {
event.preventDefault();
navigator.app.exitApp();
}
});