mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 07:25:46 +01:00
closes #2792, closes #2791, closes #2788, closes #2787, closes #2786, closes #2785, closes #2784, closes #2783
Squashed commit of the following: commit ca5064a4effa3904ce936b521b169bba8d24f1a1 Author: Julian Lam <julian@designcreateplay.com> Date: Thu Feb 26 08:19:32 2015 -0500 Revert "added ajaxify popstate cache, so back/forward will just put back the already loaded page" This reverts commit77d154bb8b. commit ae07fc56c156074de8048bb627f5d9be849c8ad1 Author: Julian Lam <julian@designcreateplay.com> Date: Thu Feb 26 08:19:24 2015 -0500 Revert "on click, topics are marked read from the unread page. Also fixed an issue where isPopState kept getting set to true, causing issues" This reverts commitd8c9ec0d40. Conflicts: public/src/client/unread.js commit 96ee3631d7e4e1fc2c1b7632d86684fecd1e430f Author: Julian Lam <julian@designcreateplay.com> Date: Thu Feb 26 08:18:25 2015 -0500 Revert "actually fixed isPopState error" This reverts commite6701c5a1f.
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var ajaxify = ajaxify || {
|
||||
isPopState: false
|
||||
};
|
||||
var ajaxify = ajaxify || {};
|
||||
|
||||
$(document).ready(function() {
|
||||
require(['templates', 'ajaxifyCache'], function (templatesModule, cache) {
|
||||
require(['templates'], function (templatesModule) {
|
||||
/*global app, templates, utils, socket, translator, config, RELATIVE_PATH*/
|
||||
|
||||
var location = document.location || window.location,
|
||||
@@ -15,9 +13,7 @@ $(document).ready(function() {
|
||||
|
||||
window.onpopstate = function (event) {
|
||||
if (event !== null && event.state && event.state.url !== undefined && !ajaxify.initialLoad) {
|
||||
ajaxify.isPopState = true;
|
||||
ajaxify.go(event.state.url, function() {
|
||||
ajaxify.isPopState = false;
|
||||
$(window).trigger('action:popstate', {url: event.state.url});
|
||||
}, true);
|
||||
}
|
||||
@@ -59,10 +55,6 @@ $(document).ready(function() {
|
||||
// "quiet": If set to true, will not call pushState
|
||||
app.enterRoom('');
|
||||
|
||||
// If the url is in the cache, load from cache instead
|
||||
if (cache.get(url, callback)) { return true; }
|
||||
else { cache.url = ajaxify.currentPage; }
|
||||
|
||||
$(window).off('scroll');
|
||||
|
||||
if ($('#content').hasClass('ajaxifying') && apiXHR) {
|
||||
@@ -122,7 +114,6 @@ $(document).ready(function() {
|
||||
templates.parse(tpl_url, data, function(template) {
|
||||
translator.translate(template, function(translatedTemplate) {
|
||||
setTimeout(function() {
|
||||
cache.set();
|
||||
$('#content').html(translatedTemplate);
|
||||
|
||||
ajaxify.variables.parse();
|
||||
|
||||
@@ -12,8 +12,6 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
||||
});
|
||||
|
||||
Unread.init = function() {
|
||||
var topicsContainer = $('#topics-container');
|
||||
|
||||
app.enterRoom('recent_posts');
|
||||
|
||||
$('#new-topics-alert').on('click', function() {
|
||||
@@ -44,7 +42,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
||||
|
||||
app.alertSuccess('[[unread:topics_marked_as_read.success]]');
|
||||
|
||||
topicsContainer.empty();
|
||||
$('#topics-container').empty();
|
||||
$('#category-no-topics').removeClass('hidden');
|
||||
$('.markread').addClass('hidden');
|
||||
});
|
||||
@@ -70,22 +68,11 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
||||
});
|
||||
});
|
||||
|
||||
topicsContainer.on('click', '.topic-title, .replies a', function(e) {
|
||||
var tid = $(e.target).parents('[data-tid]').attr('data-tid');
|
||||
socket.emit('topics.markAsRead', [tid], function(err) {
|
||||
if(err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
doneRemovingTids([tid], true);
|
||||
});
|
||||
});
|
||||
|
||||
socket.emit('categories.get', onCategoriesLoaded);
|
||||
|
||||
topicSelect.init();
|
||||
|
||||
if ($("body").height() <= $(window).height() && topicsContainer.children().length >= 20) {
|
||||
if ($("body").height() <= $(window).height() && $('#topics-container').children().length >= 20) {
|
||||
$('#load-more-btn').show();
|
||||
}
|
||||
|
||||
@@ -96,16 +83,16 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
||||
infinitescroll.init(loadMoreTopics);
|
||||
|
||||
function loadMoreTopics(direction) {
|
||||
if(direction < 0 || !topicsContainer.length) {
|
||||
if(direction < 0 || !$('#topics-container').length) {
|
||||
return;
|
||||
}
|
||||
|
||||
infinitescroll.loadMore('topics.loadMoreUnreadTopics', {
|
||||
after: topicsContainer.attr('data-nextstart')
|
||||
after: $('#topics-container').attr('data-nextstart')
|
||||
}, function(data, done) {
|
||||
if (data.topics && data.topics.length) {
|
||||
recent.onTopicsLoaded('unread', data.topics, true, done);
|
||||
topicsContainer.attr('data-nextstart', data.nextStart);
|
||||
$('#topics-container').attr('data-nextstart', data.nextStart);
|
||||
} else {
|
||||
done();
|
||||
$('#load-more-btn').hide();
|
||||
@@ -114,10 +101,10 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
||||
}
|
||||
};
|
||||
|
||||
function doneRemovingTids(tids, quiet) {
|
||||
function doneRemovingTids(tids) {
|
||||
removeTids(tids);
|
||||
|
||||
if (!quiet) { app.alertSuccess('[[unread:topics_marked_as_read.success]]'); }
|
||||
app.alertSuccess('[[unread:topics_marked_as_read.success]]');
|
||||
|
||||
if (!$('#topics-container').children().length) {
|
||||
$('#category-no-topics').removeClass('hidden');
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
'use strict';
|
||||
/* globals define, app, ajaxify */
|
||||
|
||||
define('ajaxifyCache', function() {
|
||||
var Cache = {
|
||||
url: undefined,
|
||||
DOM: undefined,
|
||||
tempDOM: undefined
|
||||
};
|
||||
|
||||
Cache.set = function() {
|
||||
Cache.DOM = $('#content > *').detach();
|
||||
};
|
||||
|
||||
Cache.get = function(url, callback) {
|
||||
if (url === Cache.url && ajaxify.isPopState) {
|
||||
// Swap DOM elements
|
||||
// setTimeout(function() {
|
||||
Cache.tempDOM = $('#content > *').detach();
|
||||
$('#content').append(Cache.DOM);
|
||||
Cache.DOM = Cache.tempDOM;
|
||||
// }, 100); // 100ms for realism! :sunglasses:
|
||||
|
||||
// Set the values that normally get set on ajaxify
|
||||
Cache.url = ajaxify.currentPage;
|
||||
ajaxify.currentPage = url;
|
||||
|
||||
if (typeof callback === 'function') { callback(); }
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return Cache;
|
||||
});
|
||||
Reference in New Issue
Block a user