/* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · Q V I T T E R · · · · http://github.com/hannesmannerheim/qvitter · · · · · · \\\\_\ · · \\) \____) · · · · · · · · Qvitter is free software: you can redistribute it and / or modify it · · under the terms of the GNU Affero General Public License as published by · · the Free Software Foundation, either version three of the License or (at · · your option) any later version. · · · · Qvitter is distributed in hope that it will be useful but WITHOUT ANY · · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS · · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for · · more details. · · · · You should have received a copy of the GNU Affero General Public License · · along with Qvitter. If not, see . · · · · Contact h@nnesmannerhe.im if you have any questions. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */ // object to keep old states of streams in, to speed up stream change window.oldStreams = new Object(); /* · · · Update stream on back button · · · · · · · · · · · · · · */ window.onpopstate = function(event) { if(event && event.state) { display_spinner(); setNewCurrentStream(event.state.strm,function(){ remove_spinner(); },false); } } /* · · · fix login and register box to top when they reach top · · · · · · · · · · · · · · */ window.loginContentStartPos = $('.front-welcome-text').height()+45; $(window).scroll(function(e){ if ($(this).scrollTop() > window.loginContentStartPos && $('#login-content').css('position') != 'fixed'){ $('#login-content, .front-signup').not('#popup-signup').css({'position': 'fixed', 'top': '50px'}); } else if ($(this).scrollTop() < window.loginContentStartPos && $('#login-content').css('position') != 'absolute'){ $('#login-content, .front-signup').not('#popup-signup').css({'position': 'absolute', 'top': 'auto'}); } }); /* · · · Tooltip to show what federated means · · · · · · · · · · · · · · */ $('#federated-tooltip').on('mouseenter',function(){ $('#what-is-federation').fadeIn(100); }); $('#what-is-federation').on('mouseleave',function(){ $('#what-is-federation').fadeOut(100); }); /* · · · Register · · · · · · · · · · · · · · */ if(!window.registrationsClosed) { $('.front-signup input, .front-signup button').removeAttr('disabled'); // clear this onload $('#signup-btn-step1').click(function(){ display_spinner(); $('.front-signup input, .front-signup button').addClass('disabled'); $('.front-signup input, .front-signup button').attr('disabled','disabled'); // 7 s timeout to annoy human spammers setTimeout(function(){ remove_spinner(); popUpAction('popup-register',window.sL.signUp,'',false); // ask api if nickname is ok, if no typing for 1 s $('#signup-user-nickname-step2').on('keyup',function(){ clearTimeout(window.checkNicknameTimeout); if($('#signup-user-nickname-step2').val().length>1 && /^[a-zA-Z0-9]+$/.test($('#signup-user-nickname-step2').val())) { $('#signup-user-nickname-step2').addClass('nickname-taken'); if($('.spinner-wrap').length==0) { $('#signup-user-nickname-step2').after('
'); } window.checkNicknameTimeout = setTimeout(function(){ getFromAPI('check_nickname.json?nickname=' + encodeURIComponent($('#signup-user-nickname-step2').val()),function(data){ $('.spinner-wrap').remove(); console.log($('.spinner-wrap').length); if(data==0) { $('#signup-user-password2-step2').trigger('keyup'); // revalidates } else { $('#signup-user-nickname-step2').removeClass('nickname-taken'); $('#signup-user-password2-step2').trigger('keyup'); } }); },1000); } else { $('.spinner-wrap').remove(); } }); // validate on keyup $('#popup-register input').on('keyup',function(){ if(validateRegisterForm($('#popup-register'))) { if(!$('#signup-user-nickname-step2').hasClass('nickname-taken')) { $('#signup-btn-step2').removeClass('disabled'); } else { $('#signup-btn-step2').addClass('disabled'); } } else { $('#signup-btn-step2').addClass('disabled'); } }); $('#popup-register input').trigger('keyup'); // submit on enter $('input#signup-user-name-step2,input#signup-user-email-step2,input#signup-user-password1-step2, input#signup-user-password2-step2').keyup(function(e){ if(e.keyCode==13) { $('#signup-btn-step2').trigger('click'); } }); $('#signup-btn-step2').click(function(){ $('#popup-register input,#popup-register button').addClass('disabled'); display_spinner(); $.ajax({ url: window.apiRoot + 'account/register.json', type: "POST", data: { nickname: $('#signup-user-nickname-step2').val(), email: $('#signup-user-email-step2').val(), fullname: $('#signup-user-name-step2').val(), homepage: $('#signup-user-homepage-step2').val(), bio: $('#signup-user-bio-step2').val(), location: $('#signup-user-location-step2').val(), password: $('#signup-user-password1-step2').val(), confirm: $('#signup-user-password2-step2').val(), cBS: window.cBS, cBSm: window.cBSm, username: 'none', }, dataType:"json", error: function(data){ console.log('error'); console.log(data); }, success: function(data) { remove_spinner(); if(typeof data.error == 'undefined') { $('input#nickname').val($('#signup-user-nickname-step2').val()); $('input#password').val($('#signup-user-password1-step2').val()); $('input#rememberme').prop('checked', true); $('#submit-login').trigger('click'); $('#popup-register').remove(); } else { alert('Try again! ' + data.error); $('#popup-register input,#popup-register button').removeClass('disabled'); } } }); }); // reactivate register form on popup close $('#popup-register').on('remove',function(){ $('.front-signup input, .front-signup button').removeAttr('disabled'); $('.front-signup input, .front-signup button').removeClass('disabled'); }); },7000); }); // submit on enter $('input#signup-user-name,input#signup-user-email,input#signup-user-password').keyup(function(e){ if(e.keyCode==13) { $('#signup-btn-step1').trigger('click'); } }); } /* · · · autologin or show welcome screen · · · · · · · · · · · · · · */ $('#submit-login').removeAttr('disabled'); // might be remebered by browser... $(window).load(function() { $('#user-container').css('display','block'); $('#feed').css('display','block'); // login or not if(window.loggedIn) { console.log('logged in user: ' + window.loggedIn.screen_name); doLogin(getStreamFromUrl()); } else { display_spinner(); window.currentStream = ''; // force reload stream setNewCurrentStream(getStreamFromUrl(),function(){ logoutWithoutReload(false); remove_spinner(); },true); } }); /* · · · Login action · · · · · · · · · · · · · · */ $('#form_login').submit(function(e) { if(typeof window.loginCheckSuccessful == 'undefined') { e.preventDefault(); checkLogin($('input#nickname').val(),$('input#password').val(),function(data){ window.loginCheckSuccessful = true; $('#form_login').submit(); }); } }); function doLogin(streamToSet) { $('#submit-login').attr('disabled','disabled'); $('#submit-login').focus(); // prevents submit on enter to close alert-popup on wrong credentials display_spinner(); // set colors if the api supports it if(typeof window.loggedIn.linkcolor != 'undefined' && typeof window.loggedIn.backgroundcolor != 'undefined') { window.loggedIn.linkcolor = window.loggedIn.linkcolor || ''; // no null value window.loggedIn.backgroundcolor = window.loggedIn.backgroundcolor || ''; // no null value window.userLinkColor = window.loggedIn.linkcolor; window.userBackgroundColor = window.loggedIn.backgroundcolor; if(window.userLinkColor.length != 6) { window.userLinkColor = window.defaultLinkColor; } if(window.userBackgroundColor.length != 6) { window.userBackgroundColor = window.defaultBackgroundColor; } } // add user data to DOM, show search form, remeber user id, show the feed $('#user-container').css('z-index','1000'); $('#top-compose').removeClass('hidden'); $('#user-avatar').attr('src', window.loggedIn.profile_image_url_profile_size); $('#user-name').append(window.loggedIn.name); $('#user-screen-name').append(window.loggedIn.screen_name); $('#user-profile-link').append('' + window.sL.viewMyProfilePage + ''); $('#user-queets strong').html(window.loggedIn.statuses_count); $('#user-following strong').html(window.loggedIn.friends_count); $('#user-followers strong').html(window.loggedIn.followers_count); $('#user-groups strong').html(window.loggedIn.groups_count); $('.stream-selection.friends-timeline').attr('href', window.loggedIn.statusnet_profile_url + '/all'); $('.stream-selection.mentions').attr('href', window.loggedIn.statusnet_profile_url + '/replies'); $('.stream-selection.my-timeline').attr('href', window.loggedIn.statusnet_profile_url); $('.stream-selection.favorites').attr('href', window.loggedIn.statusnet_profile_url + '/favorites'); window.myUserID = window.loggedIn.id; // load history loadHistoryFromLocalStorage(); // set stream window.currentStream = ''; // always reload stream on login setNewCurrentStream(streamToSet,function(){ $('.language-dropdown').css('display','none'); $('.dropdown-menu.quitter-settings li.language').css('display','block'); $('#user-header').animate({opacity:'1'},800); $('#user-body').animate({opacity:'1'},800); $('#user-footer').animate({opacity:'1'},800); $('.menu-container').animate({opacity:'1'},800); $('#page-container').animate({opacity:'1'},200); $('.front-welcome-text').slideUp(1000); $('#settingslink').fadeIn('slow'); $('#search').fadeIn('slow'); $('#login-content').css('display','none'); $('.front-signup').css('display','none'); remove_spinner(); },true); } /* · · · In the login form, we want to check the remember-me-checkbox when its label is clicked · · · · · · · · · · · · · · */ $('#rememberme_label').click(function(){ if($('#rememberme').prop('checked')) { $('#rememberme').prop('checked', false); } else { $('#rememberme').prop('checked', true); } }); $('#rememberme_label').disableSelection(); /* · · · Logout · · · · · · · · · · · · · · */ $('#logout').click(function(){ window.location.href =window.siteInstanceURL + 'main/logout'; }); /* · · · Settings · · · · · · · · · · · · · · */ $('#settings').click(function(){ // buttons to add later: '
' popUpAction('popup-settings', window.sL.settings,'
' + window.sL.moreSettings + '
',false); $('#link-color-selection').minicolors({ change: function(hex) { changeLinkColor(hex); postNewLinkColor(hex.substring(1)); } }); $('#background-color-selection').minicolors({ change: function(hex) { $('body').css('background-color',hex); postNewBackgroundColor(hex.substring(1)); } }); // also on keyup in input (minicolors 'change' event does not do this, apparently) $('#link-color-selection').on('keyup',function(){ keyupSetLinkColor($(this).val()); }); $('#background-color-selection').on('keyup',function(){ keyupSetBGColor($(this).val()); }); }); // idle function for linkcolor selection by keyboard input var keyupLinkColorTimer; function keyupSetLinkColor(hex) { clearTimeout(keyupLinkColorTimer); keyupLinkColorTimer = setTimeout(function () { $('#link-color-selection').minicolors('value',hex); changeLinkColor($('#link-color-selection').val()); postNewLinkColor($('#link-color-selection').val().substring(1)); }, 500); } // idle function for bgcolor selection by keyboard input var keyupBGColorTimer; function keyupSetBGColor(hex) { clearTimeout(keyupBGColorTimer); keyupBGColorTimer = setTimeout(function () { $('#background-color-selection').minicolors('value',hex); $('body').css('background-color',$('#background-color-selection').val()); postNewBackgroundColor($('#background-color-selection').val().substring(1)); }, 500); } // go to standard settingspage $('body').on('click','#moresettings',function(){ $(document.body).append('