3 Jappix - An open social platform
4 These are the homepage JS scripts for Jappix
6 -------------------------------------------------
9 Authors: Vanaryon, LinkMauve
10 Last revision: 15/01/12
14 // Allows the user to switch the difference home page elements
15 function switchHome(div) {
18 var right = home + 'right ';
19 var current = right + '.homediv.' + div;
22 $(right + '.homediv, ' + right + '.top').hide();
23 $(right + '.' + div).show();
25 // We reset the homedivs
26 $(home + 'homediv:not(.default), ' + home + 'top:not(.default)').remove();
28 // Get the HTML code to display
29 var disable_form = '';
33 // Apply the previous link
38 if(!exists(right + '.top.sub')) {
39 // Append the HTML code for previous link
40 $(right + '.top.default').after('<h1 class="top sub loginer anonymouser registerer">« <a href="#" class="previous">' + _e("Previous") + '</a></h1>');
42 // Click event on previous link
43 $(home + 'top.sub a.previous').click(function() {
44 return switchHome('default');
55 lock_host = disableInput(LOCK_HOST, 'on');
56 code = '<p>' + printf(_e("Login to your existing XMPP account. You can also use the %s to join a groupchat."), '<a href="#" class="to-anonymous">' + _e("anonymous mode") + '</a>') + '</p>' +
58 '<form action="#" method="post">' +
60 '<legend>' + _e("Required") + '</legend>' +
62 '<label for="lnick">' + _e("Address") + '</label>' +
63 '<input type="text" class="nick" id="lnick" pattern="[^@/]+" required="" /><span class="jid">@</span><input type="text" class="server" id="lserver" value="' + HOST_MAIN + '" ' + lock_host + ' pattern="[^@/]+" required="" />' +
64 '<label for="lpassword">' + _e("Password") + '</label>' +
65 '<input type="password" class="password" id="lpassword" required="" />' +
66 '<label for="lremember">' + _e("Remember me") + '</label>' +
67 '<input type="checkbox" class="remember" id="lremember" />' +
70 '<a href="#" class="advanced home-images">' + _e("Advanced") + '</a>' +
72 '<fieldset class="advanced">' +
73 '<legend>' + _e("Advanced") + '</legend>' +
75 '<label for="lresource">' + _e("Resource") + '</label>' +
76 '<input type="text" class="resource" id="lresource" value="' + JAPPIX_RESOURCE + '" />' +
77 '<label for="lpriority">' + _e("Priority") + '</label>' +
78 '<select class="priority" id="lpriority">' +
79 '<option value="1">' + _e("Low") + '</option>' +
80 '<option value="10" selected="">' + _e("Medium") + '</option>' +
81 '<option value="100">' + _e("High") + '</option>' +
85 '<input type="submit" value="' + _e("Here we go!") + '" />' +
90 // Anonymous login tool
92 disable_form = disableInput(ANONYMOUS, 'off');
93 code = '<p>' + printf(_e("Enter the groupchat you want to join and the nick you want to have. You can also go back to the %s."), '<a href="#" class="to-home">' + _e("login page") + '</a>') + '</p>' +
95 '<form action="#" method="post">' +
97 '<legend>' + _e("Required") + '</legend>' +
99 '<label>' + _e("Room") + '</label>' +
100 '<input type="text" class="room"' + disable_form + ' pattern="[^/]+" required="" />' +
102 '<label>' + _e("Nickname") + '</label>' +
103 '<input type="text" class="nick"' + disable_form + ' required="" />' +
106 '<input type="submit" value="' + _e("Here we go!") + '"' + disable_form + ' />' +
109 '<div class="info report">' +
110 _e("Share this link with your friends:") + ' <span></span>' +
117 disable_form = disableInput(REGISTRATION, 'off');
120 lock_host = disableInput(LOCK_HOST, 'on');
122 code = '<p>' + _e("Register a new XMPP account to join your friends on your own social cloud. That's simple!") + '</p>' +
124 '<form action="#" method="post">' +
126 '<legend>' + _e("Required") + '</legend>' +
128 '<label for="rnick">' + _e("Address") + '</label>' +
129 '<input type="text" class="nick" id="rnick" ' + disable_form + ' pattern="[^@/]+" required="" /><span class="jid">@</span><input type="text" class="server" id="rserver" value="' + HOST_MAIN + '" ' + disable_form + lock_host + ' pattern="[^@/]+" required="" />' +
130 '<label for="rpassword">' + _e("Password") + '</label>' +
131 '<input type="password" class="password" id="rpassword" ' + disable_form + ' required="" />' +
132 '<label for="spassword">' + _e("Confirm") + '</label><input type="password" class="spassword" id="spassword" ' + disable_form + ' required="" />' +
135 '<input type="submit" value="' + _e("Here we go!") + '" ' + disable_form + '/>' +
143 code += '<div class="info fail">' +
144 _e("This tool has been disabled, you cannot use it!") +
147 // Create this HTML code
148 if(code && !exists(current)) {
150 $(right + '.homediv.default').after('<div class="' + div + ' homediv">' + code + '</div>');
152 // Create the attached events
156 $(current + ' a.to-anonymous').click(function() {
157 return switchHome('anonymouser');
160 $(current + ' a.advanced').click(showAdvanced);
162 $(current + ' form').submit(loginForm);
166 // Anonymous login tool
168 $(current + ' a.to-home').click(function() {
169 return switchHome('loginer');
172 $(current + ' form').submit(doAnonymous);
174 // Keyup event on anonymous join's room input
175 $(current + ' input.room').keyup(function() {
176 var value = $(this).val();
177 var report = current + ' .report';
178 var span = report + ' span';
187 $(span).text(JAPPIX_LOCATION + '?r=' + value);
195 $(current + ' form').submit(registerForm);
201 // We focus on the first input
202 $(document).oneTime(10, function() {
203 $(right + 'input:visible:first').focus();
209 // Allows the user to display the advanced login options
210 function showAdvanced() {
212 $('#home a.advanced').hide();
215 $('#home fieldset.advanced').show();
220 // Reads the login form values
221 function loginForm() {
223 var lPath = '#home .loginer ';
224 var lServer = $(lPath + '.server').val();
225 var lNick = $(lPath + '.nick').val();
226 var lPass = $(lPath + '.password').val();
227 var lResource = $(lPath + '.resource').val();
228 var lPriority = $(lPath + '.priority').val();
229 var lRemember = $(lPath + '.remember').filter(':checked').size();
232 if(lServer && lNick && lPass && lResource && lPriority)
233 doLogin(lNick, lServer, lPass, lResource, lPriority, lRemember);
235 // Something is missing?
237 $(lPath + 'input[type=text], ' + lPath + 'input[type=password]').each(function() {
238 var select = $(this);
241 $(document).oneTime(10, function() {
242 select.addClass('please-complete').focus();
245 select.removeClass('please-complete');
252 // Reads the register form values
253 function registerForm() {
254 var rPath = '#home .registerer ';
256 // Remove the success info
257 $(rPath + '.success').remove();
260 var username = $(rPath + '.nick').val();
261 var domain = $(rPath + '.server').val();
262 var pass = $(rPath + '.password').val();
263 var spass = $(rPath + '.spassword').val();
266 if(domain && username && pass && spass && (pass == spass)) {
267 // We remove the not completed class to avoid problems
268 $('#home .registerer input').removeClass('please-complete');
270 // Fire the register event!
271 doRegister(username, domain, pass);
274 // Something is missing?
276 $(rPath + 'input[type=text], ' + rPath + 'input[type=password]').each(function() {
277 var select = $(this);
279 if(!select.val() || (select.is('#spassword') && pass && (pass != spass)))
280 $(document).oneTime(10, function() {
281 select.addClass('please-complete').focus();
284 select.removeClass('please-complete');
292 function launchHome() {
295 var button = home + 'button';
296 var corp = home + '.corporation';
297 var locale = home + '.locale';
299 // Removes the <noscript /> elements to lighten the DOM
300 $('noscript').remove();
302 // Allows the user to switch the home page
303 $(button).click(function() {
305 if($(this).is('.login'))
306 return switchHome('loginer');
310 return switchHome('registerer');
313 // Allows the user to view the corporation infobox
314 $(corp).hover(function() {
315 $(corp).addClass('hovered');
317 $(corp).removeClass('hovered');
320 // Allows the user to switch the language
321 $(locale).hover(function() {
322 // Initialize the HTML code
323 var keepget = $(locale).attr('data-keepget');
324 var html = '<div class="list">';
326 // Generate each locale HTML code
327 for(i in LOCALES_AVAILABLE_ID)
328 html += '<a href="./?l=' + LOCALES_AVAILABLE_ID[i] + keepget + '">' + LOCALES_AVAILABLE_NAMES[i].htmlEnc() + '</a>';
332 // Append the HTML code
333 $(locale).append(html);
335 $(locale + ' .list').remove();
338 // Disables the browser HTTP-requests stopper
339 $(document).keydown(function(e) {
340 if((e.keyCode == 27) && !isDeveloper())
344 // Warns for an obsolete browser
348 '<div class="obsolete">' +
349 '<p>' + _e("Your browser is out of date!") + '</p>' +
351 '<a class="firefox browsers-images" title="' + printf(_e("Last %s version is better!"), 'Mozilla Firefox') + '" href="http://www.mozilla.com/firefox/"></a>' +
352 '<a class="chrome browsers-images" title="' + printf(_e("Last %s version is better!"), 'Google Chrome') + '" href="http://www.google.com/chrome"></a>' +
353 '<a class="safari browsers-images" title="' + printf(_e("Last %s version is better!"), 'Safari') + '" href="http://www.apple.com/safari/"></a>' +
354 '<a class="opera browsers-images" title="' + printf(_e("Last %s version is better!"), 'Opera') + '" href="http://www.opera.com/"></a>' +
355 '<a class="ie browsers-images" title="' + printf(_e("Last %s version is better!"), 'Internet Explorer') + '" href="http://www.microsoft.com/hk/windows/internet-explorer/"></a>' +
360 $(home + '.obsolete').oneTime('1s', function() {
364 logThis('Jappix does not support this browser!', 2);
367 logThis('Welcome to Jappix! Happy coding in developer mode!');
370 // Launch this plugin!
371 $(document).ready(launchHome);