/* Jappix - An open social platform These are the homepage JS scripts for Jappix ------------------------------------------------- License: AGPL Authors: Vanaryon, LinkMauve Last revision: 15/01/12 */ // Allows the user to switch the difference home page elements function switchHome(div) { // Path to var home = '#home .'; var right = home + 'right '; var current = right + '.homediv.' + div; // We switch the div $(right + '.homediv, ' + right + '.top').hide(); $(right + '.' + div).show(); // We reset the homedivs $(home + 'homediv:not(.default), ' + home + 'top:not(.default)').remove(); // Get the HTML code to display var disable_form = ''; var lock_host = ''; var code = ''; // Apply the previous link switch(div) { case 'loginer': case 'anonymouser': case 'registerer': if(!exists(right + '.top.sub')) { // Append the HTML code for previous link $(right + '.top.default').after('

«

'); // Click event on previous link $(home + 'top.sub a.previous').click(function() { return switchHome('default'); }); } break; } // Apply the form switch(div) { // Login tool case 'loginer': lock_host = disableInput(LOCK_HOST, 'on'); code = '

' + printf(_e("Login to your existing XMPP account. You can also use the %s to join a groupchat."), '' + _e("anonymous mode") + '') + '

' + '
' + '
' + '' + _e("Required") + '' + '' + '@' + '' + '' + '' + '' + '
' + '' + _e("Advanced") + '' + '
' + '' + _e("Advanced") + '' + '' + '' + '' + '' + '
' + '' + '
'; break; // Anonymous login tool case 'anonymouser': disable_form = disableInput(ANONYMOUS, 'off'); code = '

' + printf(_e("Enter the groupchat you want to join and the nick you want to have. You can also go back to the %s."), '' + _e("login page") + '') + '

' + '
' + '
' + '' + _e("Required") + '' + '' + '' + '' + '' + '
' + '' + '
' + '
' + _e("Share this link with your friends:") + ' ' + '
'; break; // Register tool case 'registerer': disable_form = disableInput(REGISTRATION, 'off'); if(!disable_form) lock_host = disableInput(LOCK_HOST, 'on'); code = '

' + _e("Register a new XMPP account to join your friends on your own social cloud. That's simple!") + '

' + '
' + '
' + '' + _e("Required") + '' + '' + '@' + '' + '' + '' + '
' + '' + '
'; break; } // Form disabled? if(disable_form) code += '
' + _e("This tool has been disabled, you cannot use it!") + '
'; // Create this HTML code if(code && !exists(current)) { // Append it! $(right + '.homediv.default').after('
' + code + '
'); // Create the attached events switch(div) { // Login tool case 'loginer': $(current + ' a.to-anonymous').click(function() { return switchHome('anonymouser'); }); $(current + ' a.advanced').click(showAdvanced); $(current + ' form').submit(loginForm); break; // Anonymous login tool case 'anonymouser': $(current + ' a.to-home').click(function() { return switchHome('loginer'); }); $(current + ' form').submit(doAnonymous); // Keyup event on anonymous join's room input $(current + ' input.room').keyup(function() { var value = $(this).val(); var report = current + ' .report'; var span = report + ' span'; if(!value) { $(report).hide(); $(span).text(''); } else { $(report).show(); $(span).text(JAPPIX_LOCATION + '?r=' + value); } }); break; // Register tool case 'registerer': $(current + ' form').submit(registerForm); break; } } // We focus on the first input $(document).oneTime(10, function() { $(right + 'input:visible:first').focus(); }); return false; } // Allows the user to display the advanced login options function showAdvanced() { // Hide the link $('#home a.advanced').hide(); // Show the fieldset $('#home fieldset.advanced').show(); return false; } // Reads the login form values function loginForm() { // We get the values var lPath = '#home .loginer '; var lServer = $(lPath + '.server').val(); var lNick = $(lPath + '.nick').val(); var lPass = $(lPath + '.password').val(); var lResource = $(lPath + '.resource').val(); var lPriority = $(lPath + '.priority').val(); var lRemember = $(lPath + '.remember').filter(':checked').size(); // Enough values? if(lServer && lNick && lPass && lResource && lPriority) doLogin(lNick, lServer, lPass, lResource, lPriority, lRemember); // Something is missing? else { $(lPath + 'input[type=text], ' + lPath + 'input[type=password]').each(function() { var select = $(this); if(!select.val()) $(document).oneTime(10, function() { select.addClass('please-complete').focus(); }); else select.removeClass('please-complete'); }); } return false; } // Reads the register form values function registerForm() { var rPath = '#home .registerer '; // Remove the success info $(rPath + '.success').remove(); // Get the values var username = $(rPath + '.nick').val(); var domain = $(rPath + '.server').val(); var pass = $(rPath + '.password').val(); var spass = $(rPath + '.spassword').val(); // Enough values? if(domain && username && pass && spass && (pass == spass)) { // We remove the not completed class to avoid problems $('#home .registerer input').removeClass('please-complete'); // Fire the register event! doRegister(username, domain, pass); } // Something is missing? else { $(rPath + 'input[type=text], ' + rPath + 'input[type=password]').each(function() { var select = $(this); if(!select.val() || (select.is('#spassword') && pass && (pass != spass))) $(document).oneTime(10, function() { select.addClass('please-complete').focus(); }); else select.removeClass('please-complete'); }); } return false; } // Addon launcher function launchHome() { // Define the vars var home = '#home '; var button = home + 'button'; var corp = home + '.corporation'; var locale = home + '.locale'; // Removes the