/* Jappix - An open social platform These are the homepage JS scripts for Jappix ------------------------------------------------- License: AGPL Authors: Valérian Saliou, LinkMauve */ // Bundle var Home = (function () { /** * Alias of this * @private */ var self = {}; /** * Allows the user to switch the difference home page elements * @public * @param {string} div * @return {boolean} */ self.change = function(div) { try { // 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(!Common.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 self.change('default'); }); } break; } // Apply the form switch(div) { // Login tool case 'loginer': lock_host = Utils.disableInput(LOCK_HOST, 'on'); code = '

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

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

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

'; if(LEGAL) code += '

' + Common.printf(Common._e("By using our service, you accept %s."), '' + Common._e("our terms of use") + '') + '

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

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

'; if(LEGAL) code += '

' + Common.printf(Common._e("By using our service, you accept %s."), '' + Common._e("our terms of use") + '') + '

'; code += '
' + '
' + '' + Common._e("Required") + '' + '' + '@' + '' + ''; if(REGISTER_API == 'on') code += '
' + '' + '
'; code += '
' + '' + '
'; break; } // Form disabled? if(disable_form) code += '
' + Common._e("This tool has been disabled!") + '
'; // Create this HTML code if(code && !Common.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 self.change('anonymouser'); }); $(current + ' a.advanced').click(self.showAdvanced); $(current + ' form').submit(self.loginForm); break; // Anonymous login tool case 'anonymouser': $(current + ' a.to-home').click(function() { return self.change('loginer'); }); $(current + ' form').submit(Connection.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': // Server input change $('#home input.server').keyup(function(e) { if($.trim($(this).val()) == HOST_MAIN) { $('#home .captcha_grp').show(); $('#home input.captcha').removeAttr('disabled'); } else { $('#home .captcha_grp').hide(); $('#home input.captcha').attr('disabled', true); } }); // Register input placeholder // FIXME: breaks IE compatibility //$('#home input[placeholder]').placeholder(); // Register form submit $(current + ' form').submit(self.registerForm); break; } } // We focus on the first input $(document).oneTime(10, function() { $(right + 'input:visible:first').focus(); }); } catch(e) { Console.error('Home.change', e); } finally { return false; } }; /** * Allows the user to display the advanced login options * @public * @return {boolean} */ self.showAdvanced = function() { try { // Hide the link $('#home a.advanced').hide(); // Show the fieldset $('#home fieldset.advanced').show(); } catch(e) { Console.error('Home.showAdvanced', e); } finally { return false; } }; /** * Reads the login form values * @public * @return {boolean} */ self.loginForm = function() { try { // We get the values var lPath = '#home .loginer '; var lServer = $(lPath + '.server').val(); var lNick = Common.nodeprep($(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) { Connection.doLogin(lNick, lServer, lPass, lResource, lPriority, lRemember); } 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'); }); } } catch(e) { Console.error('Home.loginForm', e); } finally { return false; } }; /** * Reads the register form values * @public * @return {boolean} */ self.registerForm = function() { try { var rPath = '#home .registerer '; // Remove the success info $(rPath + '.success').remove(); // Get the values var username = Common.nodeprep($(rPath + '.nick').val()); var domain = $(rPath + '.server').val(); var pass = $(rPath + '.password').val(); var spass = $(rPath + '.spassword').val(); var captcha = $(rPath + '.captcha').val(); // Enough values? if(domain && username && pass && spass && (pass == spass) && !((REGISTER_API == 'on') && (domain == HOST_MAIN) && !captcha)) { // We remove the not completed class to avoid problems $('#home .registerer input').removeClass('please-complete'); // Fire the register event! Connection.doRegister(username, domain, pass, captcha); } // 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'); }); } } catch(e) { Console.error('Home.registerForm', e); } finally { return false; } }; /** * Plugin launcher * @public * @param {type} name * @return {undefined} */ self.launch = function() { try { $(document).ready(function() { // Define the vars var home = '#home '; var button = home + 'button'; var corp = home + '.corporation'; var aboutus = home + '.aboutus'; var locale = home + '.locale'; // Removes the