/* 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 = {}; /** * Apply change events * @private * @param {object} current_sel * @param {string} div * @return {undefined} */ self._eventsChange = function(current_sel, div) { try { // Create the attached events switch(div) { // Login tool case 'loginer': current_sel.find('a.to-anonymous').click(function() { return self.change('anonymouser'); }); current_sel.find('a.advanced').click(self.showAdvanced); current_sel.find('form').submit(self.loginForm); break; // Anonymous login tool case 'anonymouser': current_sel.find('a.to-home').click(function() { return self.change('loginer'); }); current_sel.find('form').submit(Connection.doAnonymous); // Keyup event on anonymous join's room input current_sel.find('input.room').keyup(function() { var value = $(this).val(); var report_sel = current_sel.find('.report'); var span_sel = current_sel.find('span'); if(!value) { report_sel.hide(); span_sel.text(''); } else { report_sel.show(); span_sel.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_sel.find('form').submit(self.registerForm); break; } } catch(e) { Console.error('Home._eventsChange', e); } }; /** * Create obsolete form * @private * @param {string} home * @param {string} locale * @return {undefined} */ self._obsolete = function(home, locale) { try { // Add the code $(locale).after( '
' + '

' + Common._e("Your browser is out of date!") + '

' + '' + '' + '' + '' + '' + '
' ); // Display it later $(home + '.obsolete').oneTime('1s', function() { $(this).slideDown(); }); Console.warn('Jappix does not support this browser!'); } catch(e) { Console.error('Home._obsolete', e); } }; /** * 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)) { $(right + '.homediv.default').after( '
' + code + '
' ); self._eventsChange( $(current), div ); } // 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 path_sel = $('#home .loginer'); var lServer = path_sel.find('.server').val(); var lNick = Common.nodeprep(path_sel.find('.nick').val()); var lPass = path_sel.find('.password').val(); var lResource = path_sel.find('.resource').val(); var lPriority = path_sel.find('.priority').val(); var lRemember = path_sel.find('.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 path = '#home .registerer'; var path_sel = $(path); // Remove the success info path_sel.find('.success').remove(); // Get the values var username = Common.nodeprep(path_sel.find('.nick').val()); var domain = path_sel.find('.server').val(); var pass = path_sel.find('.password').val(); var spass = path_sel.find('.spassword').val(); var captcha = path_sel.find('.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 { $(path + ' input[type="text"], ' + path + ' 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