3 Jappix - An open social platform
4 These are the interface JS scripts for Jappix
6 -------------------------------------------------
10 Last revision: 26/08/11
14 // Changes the title of the document
15 function pageTitle(title) {
17 var head_name = getName();
20 head_name = ANONYMOUS_ROOM + ' (' + _e("anonymous mode") + ')';
22 // We change the title to give essential informations
25 document.title = SERVICE_NAME + ' • ' + _e("An open social network");
30 document.title = 'Jappix • ' + head_name;
35 document.title = '[' + pendingEvents() + '] Jappix • ' + head_name;
40 document.title = 'Jappix • ' + _e("Please wait...");
46 // Creates a general-wait item
47 function showGeneralWait() {
49 if(exists('#general-wait'))
52 // Generate the HTML code
54 '<div id="general-wait" class="removable">' +
55 '<div class="general-wait-content wait-big"></div>' +
58 // Append the HTML code
59 $('body').append(html);
64 // Removes the general-wait item
65 function removeGeneralWait() {
66 $('#general-wait').remove();
69 // Generates a file upload valid form content
70 function generateFileShare() {
71 return '<input type="hidden" name="MAX_FILE_SIZE" value="' + encodeQuotes(JAPPIX_MAX_FILE_SIZE) + '">' +
72 '<input type="hidden" name="user" value="' + encodeQuotes(getXID()) + '" />' +
73 '<input type="hidden" name="location" value="' + encodeQuotes(generateURL(JAPPIX_LOCATION)) + '" />' +
74 '<input type="hidden" name="id" value="' + (new Date()).getTime() + '" />' +
75 '<input type="file" name="file" required="" />' +
76 '<input type="submit" value="' + _e("Send") + '" />';
79 // Switches to the given chan
80 function switchChan(id) {
81 if(exists('#' + id)) {
82 // We show the page-engine content
83 $('.page-engine-chan').hide();
86 // We edit the tab switcher
87 $('#page-switch .switcher').removeClass('activechan').addClass('chan');
88 $('#page-switch .' + id).addClass('activechan').removeClass('chan');
90 // Scroll down to the last message
101 // Loads the complete chat switcher
102 function loadChatSwitch() {
104 var more_content = '#page-switch .more-content';
107 if(exists(more_content))
108 return closeBubbles();
111 showBubble(more_content);
113 // Append the content
114 $('#page-switch .more').append(
115 '<div class="more-content bubble removable">' +
116 $('#page-switch .chans').html() +
123 // Puts the selected smiley in the good page-engine input
124 function insertSmiley(smiley, hash) {
125 // We define the variables
126 var selector = $('#' + hash + ' .message-area');
127 var oValue = selector.val();
130 if(oValue && !oValue.match(/^(.+)(\s)+$/))
133 var nValue = oValue + smiley + ' ';
135 // Put the new value and focus on it
136 $(document).oneTime(10, function() {
137 selector.val(nValue).focus();
143 // Deletes all the associated elements of the chat we want to remove
144 function deleteThisChat(hash) {
145 $('#' + hash + ', #page-switch .' + hash).remove();
148 // Closes the given chat
149 function quitThisChat(xid, hash, type) {
150 if(type == 'groupchat') {
151 // Send our unavailable presence
152 sendPresence(xid + '/' + getMUCNick(hash), 'unavailable');
154 // Remove all presence database entries for this groupchat
155 for(var i = 0; i < sessionStorage.length; i++) {
156 // Get the pointer values
157 var current = sessionStorage.key(i);
158 var cXID = explodeThis('_', current, 1);
160 // If the pointer is on a presence from this groupchat
161 if((explodeThis('_', current, 0) == 'presence') && (bareXID(cXID) == xid)) {
162 // Generate the hash for the current XID
163 var cHash = hex_md5(cXID);
165 // Disable the message textarea
166 $('#' + cHash + ' .message-area').attr('disabled', true);
168 // Remove the presence for this XID
169 removeDB('presence', cXID);
170 presenceFunnel(cXID, cHash);
176 chatStateSend('gone', xid, hash);
178 // Get the chat ID which is before
179 var previous = $('#' + hash).prev().attr('id');
182 deleteThisChat(hash);
184 // Reset the switcher
185 if(!exists('#page-switch .switcher.activechan'))
186 switchChan(previous);
188 // Reset the notifications
189 chanCleanNotify(hash);
194 // Generates the chat logs
195 function generateChatLog(xid, hash) {
196 // Get the main values
197 var path = '#' + hash + ' .';
198 var content = $(path + 'content').clone().contents();
199 var avatar = $(path + 'top .avatar-container:first').html();
200 var nick = $(path + 'top .bc-name').text();
201 var date = getXMPPTime('local');
202 var type = $('#' + hash).attr('data-type');
204 // Filter the content smileys
205 $(content).find('img.emoticon').each(function() {
206 $(this).replaceWith($(this).attr('alt'));
209 // Remove the useless attributes
210 $(content).removeAttr('data-type').removeAttr('data-stamp');
212 // Remove the content avatars
213 $(content).find('.avatar-container').remove();
215 // Remove the content click events
216 $(content).find('a').removeAttr('onclick');
218 // Extract the content HTML code
219 content = $(content).parent().html();
222 if(!avatar || !avatar.match(/data:/))
225 // POST the values to the server
226 $.post('./php/generate-chat.php', { content: content, xid: xid, nick: nick, avatar: avatar, date: date, type: type }, function(data) {
228 $(path + 'tooltip-waitlog').replaceWith('<a class="tooltip-actionlog" href="./php/download-chat.php?id=' + data + '" target="_blank">' + _e("Download file!") + '</a>');
234 // Notifies the user from a new incoming message
235 function messageNotify(hash, type) {
236 // Initialize the vars
237 var chat_switch = '#page-switch .';
238 var tested = chat_switch + hash;
239 var active = $(tested).hasClass('activechan');
241 // We notify the user if he has not the focus on the chat
242 if(!active || !isFocused()) {
244 if(type == 'personnal')
245 $(tested + ', ' + chat_switch + 'more-button').addClass('chan-newmessage');
246 else if(type == 'unread')
247 $(tested).addClass('chan-unread');
250 // Count the number of pending messages
253 if(exists('#' + hash + '[data-counter]'))
254 pending = parseInt($('#' + hash).attr('data-counter')) + 1;
256 $('#' + hash).attr('data-counter', pending);
259 // Update the page title
263 // Returns the number of pending events
264 function pendingEvents() {
265 // Count the number of notifications
268 $('.one-counter[data-counter]').each(function() {
269 number = number + parseInt($(this).attr('data-counter'));
275 // Updates the page title
276 function updateTitle() {
277 // Any pending events?
278 if(exists('.one-counter[data-counter]'))
284 // Cleans the given chat notifications
285 function chanCleanNotify(hash) {
286 // We remove the class that tell the user of a new message
287 var chat_switch = '#page-switch .';
288 $(chat_switch + hash).removeClass('chan-newmessage chan-unread');
290 // We reset the global notifications if no more unread messages
291 if(!$(chat_switch + 'chans .chan-newmessage').size())
292 $(chat_switch + 'more-button').removeClass('chan-newmessage');
294 // We reset the chat counter
295 $('#' + hash).removeAttr('data-counter');
297 // Update the page title
301 // Scrolls to the last chat message
302 function autoScroll(hash) {
304 if(exists('#' + hash)) {
305 var container = document.getElementById('chat-content-' + hash);
308 container.scrollTop = container.scrollHeight;
312 // Shows all the buddies in the buddy-list
313 function showAllBuddies(from) {
317 // We switch the two modes
318 $('.buddy-conf-more-display-unavailable').hide();
319 $('.buddy-conf-more-display-available').show();
321 // Security: reset all the groups toggle event
322 $('#buddy-list .group-buddies').show();
323 $('#buddy-list .group span').text('-');
325 // We show the disconnected buddies
326 $('.hidden-buddy').show();
328 // We show all the groups
329 $('#buddy-list .one-group').show();
332 funnelFilterBuddySearch();
334 // Store this in the options
335 if((from == 'roster') && loadedOptions()) {
336 setDB('options', 'roster-showall', '1');
341 // Shows only the online buddies in the buddy-list
342 function showOnlineBuddies(from) {
346 // We switch the two modes
347 $('.buddy-conf-more-display-available').hide();
348 $('.buddy-conf-more-display-unavailable').show();
350 // Security: reset all the groups toggle event
351 $('#buddy-list .group-buddies').show();
352 $('#buddy-list .group span').text('-');
354 // We hide the disconnected buddies
355 $('.hidden-buddy').hide();
357 // We check the groups to hide
361 funnelFilterBuddySearch();
363 // Store this in the options
364 if((from == 'roster') && loadedOptions()) {
365 setDB('options', 'roster-showall', '0');
370 // Focuses on the right input
371 function inputFocus() {
373 if(!exists('.popup'))
374 $(document).oneTime(10, function() {
375 $('.focusable:visible:first').focus();
380 function launchInterface() {
381 // Focus on the first visible input
382 $(window).focus(inputFocus);
385 // Launch this plugin!
386 $(document).ready(launchInterface);