-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui.js
More file actions
112 lines (92 loc) · 3.03 KB
/
ui.js
File metadata and controls
112 lines (92 loc) · 3.03 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Roster = {
jid_to_id: function (jid) {
return Strophe.getBareJidFromJid(jid)
.replace("@", "_")
.replace(".", "-");
},
id_to_jid: function (id) {
return id
.replace("_", "@")
.replace("-", ".");
},
update_roster_list: function (data) {
function onListItemClick (item) {
var id = item.attr('id');
$(document).trigger("roster_item_action", {
jid: Roster.id_to_jid(id)
});
};
data.friends.forEach(function (contact) {
var jid_id = Roster.jid_to_id(contact.jid);
var elem = $("<li id='" + jid_id + "'>" +
contact.name + "<span class='ui-li-count'></span></li>");
$('#friends_list').append(elem);
$('#' + jid_id).click(function () {
onListItemClick($(this));
});
Roster.set_item_status(contact.jid, 'none');
});
$('#friends_list').listview('refresh');
},
get_item_status: function (jid) {
return $('#' + Roster.jid_to_id(jid)).attr('status');
},
set_item_status: function (jid, status) {
var item = $('#' + Roster.jid_to_id(jid));
item.attr('status', status);
$('#' + Roster.jid_to_id(jid) + ' span').text(status);
}
};
Chat = {
add_recieved_signal: function () {
var label = $('#recieved_label');
var count = parseInt(label.text());
label.text(count + 1);
},
clear_recieved_signal: function () {
$('#recieved_label').text(0);
}
},
UI = {
init: function () {
$('#login_button').click(function () {
var creds = {
login: $('#login').val(),
password: $('#password').val()
};
if ($('#login').val() == "") {
$('#login').focus();
return;
} else if ($('#password').val() == "") {
$('#password').focus();
return;
}
$(document).trigger("login_action", creds);
});
$('#tap_button').click(function () {
$(document).trigger("taptap_action");
});
$('#quit_chat_button').click(function () {
Chat.clear_recieved_signal();
$(document).trigger("quit_chat_action");
});
},
st_login: function(data) {
$('#password').val('');
$('#login, #password').textinput('enable');
$('#login_button').button('enable');
$('#message_label').text(data && data.message || "");
},
st_login_connecting: function () {
$('#login, #password').textinput('disable');
$('#login_button').button('disable');
$('#message_label').text("Connecting...");
},
st_roster: function () {
$.mobile.changePage($('#roster_page'));
},
st_chat: function (data) {
Chat.clear_recieved_signal();
$.mobile.changePage($('#chat_page'));
}
};