From 83d5a84eddd6ed204d7d5854fdab4a64277d174f Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Tue, 24 Sep 2013 14:56:51 -0400 Subject: [PATCH] login redirects back --- public/src/app.js | 181 +++++++++++++++------------- public/src/forum/footer.js | 1 + public/src/forum/login.js | 7 +- public/src/forum/topic.js | 24 ++-- public/templates/category.tpl | 46 ++++--- public/themes/vanilla/category.less | 2 +- 6 files changed, 141 insertions(+), 120 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 53d102c81f..f9a793c055 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -7,7 +7,7 @@ var socket, (function () { var showWelcomeMessage = false; - function loadConfig() { + app.loadConfig = function() { $.ajax({ url: RELATIVE_PATH + '/api/config', @@ -15,108 +15,114 @@ var socket, API_URL = data.api_url; config = data; - socket = io.connect(config.socket.address); - - var reconnecting = false; - var reconnectTries = 0; - - socket.on('event:connect', function (data) { - app.username = data.username; - app.showLoginMessage(); - }); + if(socket) { + socket.disconnect(); + socket.socket.connect(); + } else { + socket = io.connect(config.socket.address); + + var reconnecting = false; + var reconnectTries = 0; + + socket.on('event:connect', function (data) { + app.username = data.username; + app.showLoginMessage(); + socket.emit('api:updateHeader', { + fields: ['username', 'picture', 'userslug'] + }); + }); - socket.on('event:alert', function (data) { - app.alert(data); - }); + socket.on('event:alert', function (data) { + app.alert(data); + }); - socket.on('connect', function (data) { - if (reconnecting) { - setTimeout(function () { - app.alert({ - alert_id: 'connection_alert', - title: 'Connected', - message: 'Connection successful.', - type: 'success', - timeout: 5000 + socket.on('connect', function (data) { + if (reconnecting) { + setTimeout(function () { + app.alert({ + alert_id: 'connection_alert', + title: 'Connected', + message: 'Connection successful.', + type: 'success', + timeout: 5000 + }); + }, 1000); + reconnecting = false; + reconnectTries = 0; + socket.emit('api:updateHeader', { + fields: ['username', 'picture', 'userslug'] }); - }, 1000); - reconnecting = false; - reconnectTries = 0; - socket.emit('api:updateHeader', { - fields: ['username', 'picture', 'userslug'] - }); - } - }); + } + }); - socket.on('reconnecting', function (data) { - function showDisconnectModal() { - $('#disconnect-modal').modal({ - backdrop: 'static', - show: true - }); + socket.on('reconnecting', function (data) { + function showDisconnectModal() { + $('#disconnect-modal').modal({ + backdrop: 'static', + show: true + }); - $('#reload-button').on('click', function () { - $('#disconnect-modal').modal('hide'); - window.location.reload(); - }); - } + $('#reload-button').on('click', function () { + $('#disconnect-modal').modal('hide'); + window.location.reload(); + }); + } - reconnecting = true; - reconnectTries++; + reconnecting = true; + reconnectTries++; - if (reconnectTries > 4) { - showDisconnectModal(); - return; - } + if (reconnectTries > 4) { + showDisconnectModal(); + return; + } - app.alert({ - alert_id: 'connection_alert', - title: 'Reconnecting', - message: 'You have disconnected from NodeBB, we will try to reconnect you.
', - type: 'warning', - timeout: 5000 + app.alert({ + alert_id: 'connection_alert', + title: 'Reconnecting', + message: 'You have disconnected from NodeBB, we will try to reconnect you.
', + type: 'warning', + timeout: 5000 + }); }); - }); - socket.on('api:user.get_online_users', function (users) { - jQuery('a.username-field').each(function () { - if (this.processed === true) - return; + socket.on('api:user.get_online_users', function (users) { + jQuery('a.username-field').each(function () { + if (this.processed === true) + return; - var el = jQuery(this), - uid = el.parents('li').attr('data-uid'); + var el = jQuery(this), + uid = el.parents('li').attr('data-uid'); - if (uid && jQuery.inArray(uid, users) !== -1) { - el.find('i').remove(); - el.prepend(''); - } else { - el.find('i').remove(); - el.prepend(''); - } + if (uid && jQuery.inArray(uid, users) !== -1) { + el.find('i').remove(); + el.prepend(''); + } else { + el.find('i').remove(); + el.prepend(''); + } - el.processed = true; - }); - jQuery('button .username-field').each(function () { - //DRY FAIL - if (this.processed === true) - return; + el.processed = true; + }); + jQuery('button .username-field').each(function () { + //DRY FAIL + if (this.processed === true) + return; - var el = jQuery(this), - uid = el.parents('li').attr('data-uid'); + var el = jQuery(this), + uid = el.parents('li').attr('data-uid'); - if (uid && jQuery.inArray(uid, users) !== -1) { - el.parent().addClass('btn-success'); - } else { - el.parent().addClass('btn-danger'); - } + if (uid && jQuery.inArray(uid, users) !== -1) { + el.parent().addClass('btn-success'); + } else { + el.parent().addClass('btn-danger'); + } - el.processed = true; + el.processed = true; + }); }); - }); - - app.enter_room('global'); - + app.enter_room('global'); + } }, async: false }); @@ -402,7 +408,8 @@ var socket, function animateScroll() { $('body,html').animate({ scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop() - $('#header-menu').height() - }); + }, 400); + //$('body,html').scrollTop(scrollTo.offset().top - container.offset().top + container.scrollTop() - $('#header-menu').height()); } if (!scrollTo.length && tid) { @@ -437,6 +444,6 @@ var socket, showWelcomeMessage = location.href.indexOf('loggedin') !== -1; - loadConfig(); + app.loadConfig(); }()); \ No newline at end of file diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index eb04220b2c..3f91308384 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -58,6 +58,7 @@ if (data['username']) userLabel.find('span').html(data['username']); } else { + rightMenu.empty(); var userli = $('
  • \ \ \ diff --git a/public/src/forum/login.js b/public/src/forum/login.js index 5ff7a2de58..0fbf475521 100644 --- a/public/src/forum/login.js +++ b/public/src/forum/login.js @@ -32,7 +32,12 @@ $('#login-error-notify').show(); } else { $('#login-error-notify').hide(); - window.location.replace(RELATIVE_PATH + "/?loggedin"); + //window.location.replace(RELATIVE_PATH + "/?loggedin"); + history.go(-1); + //setTimeout(function(){ + app.loadConfig(); + //}, 500); + //socket.emit('api:updateHeader'); } }, error: function(data, textStatus, jqXHR) { diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 33c62b4e78..246d25a409 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -215,21 +215,12 @@ }, false); } - $(window).off('scroll').on('scroll', function() { - var bottom = ($(document).height() - $(window).height()) * 0.9; - - if ($(window).scrollTop() > bottom && !app.infiniteLoaderActive && $('#post-container').children().length) { - app.loadMorePosts(tid); - } - }); + enableInfiniteLoading(); var bookmark = localStorage.getItem('topic:' + tid + ':bookmark'); if(bookmark) { - // need to find out why it doesnt work without setTimeout -baris - setTimeout(function() { - app.scrollToPost(parseInt(bookmark, 10)); - }, 300); + app.scrollToPost(parseInt(bookmark, 10)); } $('#post-container').on('click', '.deleted', function(ev) { @@ -237,6 +228,17 @@ }); }); + function enableInfiniteLoading() { + $(window).off('scroll').on('scroll', function() { + var bottom = ($(document).height() - $(window).height()) * 0.9; + + if ($(window).scrollTop() > bottom && !app.infiniteLoaderActive && $('#post-container').children().length) { + app.loadMorePosts(tid); + console.log('window scrolling'); + } + }); + } + var reply_fn = function() { var selectionText = '', selection = window.getSelection() || document.getSelection(); diff --git a/public/templates/category.tpl b/public/templates/category.tpl index d5cb9186e9..60720c8b4a 100644 --- a/public/templates/category.tpl +++ b/public/templates/category.tpl @@ -29,29 +29,35 @@ -
  • + + diff --git a/public/themes/vanilla/category.less b/public/themes/vanilla/category.less index e1db73525c..8e5f5887e7 100644 --- a/public/themes/vanilla/category.less +++ b/public/themes/vanilla/category.less @@ -7,7 +7,7 @@ padding-right: 30px; } - a { + ul { li { list-style: none; padding-bottom: 10px;