]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/js/interface.js
Update strings
[friendica-addons.git] / jappixmini / jappix / js / interface.js
1 /*
2
3 Jappix - An open social platform
4 These are the interface JS scripts for Jappix
5
6 -------------------------------------------------
7
8 License: AGPL
9 Author: Vanaryon
10 Last revision: 26/08/11
11
12 */
13
14 // Changes the title of the document
15 function pageTitle(title) {
16         // Anonymous mode?
17         var head_name = getName();
18         
19         if(isAnonymous())
20                 head_name = ANONYMOUS_ROOM + ' (' + _e("anonymous mode") + ')';
21         
22         // We change the title to give essential informations
23         switch(title) {
24                 case 'home':
25                         document.title = SERVICE_NAME + ' • ' + _e("An open social network");
26                         
27                         break;
28                 
29                 case 'talk':
30                         document.title = 'Jappix • ' + head_name;
31                         
32                         break;
33                 
34                 case 'new':
35                         document.title = '[' + pendingEvents() + '] Jappix • ' + head_name;
36                         
37                         break;
38                 
39                 case 'wait':
40                         document.title = 'Jappix • ' + _e("Please wait...");
41                         
42                         break;
43         }
44 }
45
46 // Creates a general-wait item
47 function showGeneralWait() {
48         // Item exists?
49         if(exists('#general-wait'))
50                 return false;
51         
52         // Generate the HTML code
53         var html = 
54         '<div id="general-wait" class="removable">' + 
55                 '<div class="general-wait-content wait-big"></div>' + 
56         '</div>';
57         
58         // Append the HTML code
59         $('body').append(html);
60         
61         return true;
62 }
63
64 // Removes the general-wait item
65 function removeGeneralWait() {
66         $('#general-wait').remove();
67 }
68
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") + '" />';
77 }
78
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();
84                 $('#' + id).show();
85                 
86                 // We edit the tab switcher
87                 $('#page-switch .switcher').removeClass('activechan').addClass('chan');
88                 $('#page-switch .' + id).addClass('activechan').removeClass('chan');
89                 
90                 // Scroll down to the last message
91                 if(id != 'channel')
92                         autoScroll(id);
93                 
94                 // Manage input focus
95                 inputFocus();
96         }
97         
98         return false;
99 }
100
101 // Loads the complete chat switcher
102 function loadChatSwitch() {
103         // Path
104         var more_content = '#page-switch .more-content';
105         
106         // Yet displayed?
107         if(exists(more_content))
108                 return closeBubbles();
109         
110         // Add the bubble
111         showBubble(more_content);
112         
113         // Append the content
114         $('#page-switch .more').append(
115                 '<div class="more-content bubble removable">' + 
116                         $('#page-switch .chans').html() + 
117                 '</div>'
118         );
119         
120         return false;
121 }
122
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();
128         
129         // Any old value?
130         if(oValue && !oValue.match(/^(.+)(\s)+$/))
131                 oValue += ' ';
132         
133         var nValue = oValue + smiley + ' ';
134         
135         // Put the new value and focus on it
136         $(document).oneTime(10, function() {
137                 selector.val(nValue).focus();
138         });
139         
140         return false;
141 }
142
143 // Deletes all the associated elements of the chat we want to remove
144 function deleteThisChat(hash) {
145         $('#' + hash + ', #page-switch .' + hash).remove();
146 }
147
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');
153                 
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);
159                         
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);
164                                 
165                                 // Disable the message textarea
166                                 $('#' + cHash + ' .message-area').attr('disabled', true);
167                                 
168                                 // Remove the presence for this XID
169                                 removeDB('presence', cXID);
170                                 presenceFunnel(cXID, cHash);
171                         }
172                 }
173         }
174         
175         else
176                 chatStateSend('gone', xid, hash);
177         
178         // Get the chat ID which is before
179         var previous = $('#' + hash).prev().attr('id');
180         
181         // Remove the chat
182         deleteThisChat(hash);
183         
184         // Reset the switcher
185         if(!exists('#page-switch .switcher.activechan'))
186                 switchChan(previous);
187         
188         // Reset the notifications
189         chanCleanNotify(hash);
190         
191         return false;
192 }
193
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');
203         
204         // Filter the content smileys
205         $(content).find('img.emoticon').each(function() {
206                 $(this).replaceWith($(this).attr('alt'));
207         });
208         
209         // Remove the useless attributes
210         $(content).removeAttr('data-type').removeAttr('data-stamp');
211         
212         // Remove the content avatars
213         $(content).find('.avatar-container').remove();
214         
215         // Remove the content click events
216         $(content).find('a').removeAttr('onclick');
217         
218         // Extract the content HTML code
219         content = $(content).parent().html();
220         
221         // No avatar?
222         if(!avatar || !avatar.match(/data:/))
223                 avatar = 'none';
224         
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) {
227                 // Handled!
228                 $(path + 'tooltip-waitlog').replaceWith('<a class="tooltip-actionlog" href="./php/download-chat.php?id=' + data + '" target="_blank">' + _e("Download file!") + '</a>');
229         });
230         
231         return false;
232 }
233
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');
240         
241         // We notify the user if he has not the focus on the chat
242         if(!active || !isFocused()) {
243                 if(!active) {
244                         if(type == 'personnal')
245                                 $(tested + ', ' + chat_switch + 'more-button').addClass('chan-newmessage');
246                         else if(type == 'unread')
247                                 $(tested).addClass('chan-unread');
248                 }
249                 
250                 // Count the number of pending messages
251                 var pending = 1;
252                 
253                 if(exists('#' + hash + '[data-counter]'))
254                         pending = parseInt($('#' + hash).attr('data-counter')) + 1;
255                 
256                 $('#' + hash).attr('data-counter', pending);
257         }
258         
259         // Update the page title
260         updateTitle();
261 }
262
263 // Returns the number of pending events
264 function pendingEvents() {
265         // Count the number of notifications
266         var number = 0;
267         
268         $('.one-counter[data-counter]').each(function() {
269                 number = number + parseInt($(this).attr('data-counter'));
270         });
271         
272         return number;
273 }
274
275 // Updates the page title
276 function updateTitle() {
277         // Any pending events?
278         if(exists('.one-counter[data-counter]'))
279                 pageTitle('new');
280         else
281                 pageTitle('talk');
282 }
283
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');
289         
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');
293         
294         // We reset the chat counter
295         $('#' + hash).removeAttr('data-counter');
296         
297         // Update the page title
298         updateTitle();
299 }
300
301 // Scrolls to the last chat message
302 function autoScroll(hash) {
303         // Avoid a JS error
304         if(exists('#' + hash)) {
305                 var container = document.getElementById('chat-content-' + hash);
306                 
307                 // Scroll down!
308                 container.scrollTop = container.scrollHeight;
309         }
310 }
311
312 // Shows all the buddies in the buddy-list
313 function showAllBuddies(from) {
314         // Put a marker
315         BLIST_ALL = true;
316         
317         // We switch the two modes
318         $('.buddy-conf-more-display-unavailable').hide();
319         $('.buddy-conf-more-display-available').show();
320         
321         // Security: reset all the groups toggle event
322         $('#buddy-list .group-buddies').show();
323         $('#buddy-list .group span').text('-');
324         
325         // We show the disconnected buddies
326         $('.hidden-buddy').show();
327         
328         // We show all the groups
329         $('#buddy-list .one-group').show();
330         
331         if(SEARCH_FILTERED)
332                 funnelFilterBuddySearch();
333         
334         // Store this in the options
335         if((from == 'roster') && loadedOptions()) {
336                 setDB('options', 'roster-showall', '1');
337                 storeOptions();
338         }
339 }
340
341 // Shows only the online buddies in the buddy-list
342 function showOnlineBuddies(from) {
343         // Remove the marker
344         BLIST_ALL = false;
345         
346         // We switch the two modes
347         $('.buddy-conf-more-display-available').hide();
348         $('.buddy-conf-more-display-unavailable').show();
349         
350         // Security: reset all the groups toggle event
351         $('#buddy-list .group-buddies').show();
352         $('#buddy-list .group span').text('-');
353         
354         // We hide the disconnected buddies
355         $('.hidden-buddy').hide();
356         
357         // We check the groups to hide
358         updateGroups();
359         
360         if(SEARCH_FILTERED)
361                 funnelFilterBuddySearch();
362         
363         // Store this in the options
364         if((from == 'roster') && loadedOptions()) {
365                 setDB('options', 'roster-showall', '0');
366                 storeOptions();
367         }
368 }
369
370 // Focuses on the right input
371 function inputFocus() {
372         // No popup shown
373         if(!exists('.popup'))
374                 $(document).oneTime(10, function() {
375                         $('.focusable:visible:first').focus();
376                 });
377 }
378
379 // Addon launcher
380 function launchInterface() {
381         // Focus on the first visible input
382         $(window).focus(inputFocus);
383 }
384
385 // Launch this addon!
386 $(document).ready(launchInterface);