Improved next/prev post behavior

This commit is contained in:
Marcin Kurczewski 2014-08-08 20:27:47 +02:00
parent f78d09b424
commit fc569df34e
4 changed files with 24 additions and 16 deletions

View file

@ -12,7 +12,6 @@ $(function()
.bindOnce('comment-submit', 'submit', function(e)
{
e.preventDefault();
rememberLastSearchQuery();
var formDom = $(this);
if (formDom.hasClass('inactive'))
@ -50,7 +49,7 @@ $(function()
formDom.find('.preview').hide();
var cb = function()
{
$.get(window.location.href).success(function(data)
getHtml(window.location.href).success(function(data)
{
$('.comments-wrapper').replaceWith($(data).find('.comments-wrapper'));
$('body').trigger('dom-update');
@ -99,7 +98,7 @@ $(function()
if (formDom.length == 0)
{
$.get($(this).attr('href')).success(function(data)
getHtml($(this).attr('href')).success(function(data)
{
var otherForm = $(data).find('form.edit-comment');
otherForm.hide();

View file

@ -50,6 +50,12 @@ function postJSON(data)
return $.ajax(data);
};
function getHtml(data)
{
rememberLastSearchQuery();
return $.get(data);
}
$.fn.hasAttr = function(name)
{
return this.attr(name) !== undefined;
@ -71,6 +77,18 @@ $.fn.bindOnce = function(name, eventName, callback)
//basic event listeners
$(function()
{
$(window).on('beforeunload', function()
{
rememberLastSearchQuery();
});
if (window.history && window.history.pushState)
{
$(window).on('popstate', function()
{
rememberLastSearchQuery();
});
}
$('body').bind('dom-update', function()
{
//event confirmations
@ -93,9 +111,7 @@ $(function()
{
if (e.isPropagationStopped())
return;
e.preventDefault();
rememberLastSearchQuery();
var aDom = $(this);
if (aDom.hasClass('inactive'))
@ -125,7 +141,6 @@ $(function()
$('form.simple-action').bindOnce('simple-action', 'submit', function(e)
{
e.preventDefault();
rememberLastSearchQuery();
var formDom = $(this);
if (formDom.hasClass('inactive'))
@ -149,7 +164,6 @@ $(function()
{
if (data.message)
alert(data.message);
console.log(data);
disableExitConfirmation();
formDom.find(':input').attr('readonly', false);
formDom.removeClass('inactive');
@ -184,10 +198,6 @@ $(function()
});
});
});
//try to remember last search query
window.onbeforeunload = rememberLastSearchQuery;
});

View file

@ -15,7 +15,7 @@ function scrolled()
if (pageNext != null && pageNext != pageDone)
{
$(document).data('page-done', pageNext);
$.get(pageNext).success(function(response)
getHtml(pageNext).success(function(response)
{
var dom = $(response);
var nextPage = dom.find('.paginator .next:not(.disabled) a').attr('href');

View file

@ -67,7 +67,7 @@ $(function()
$('.comments.unit a.simple-action').data('callback', function()
{
$.get(window.location.href).success(function(data)
getHtml(window.location.href).success(function(data)
{
$('.comments-wrapper').replaceWith($(data).find('.comments-wrapper'));
$('body').trigger('dom-update');
@ -76,7 +76,7 @@ $(function()
$('#sidebar a.simple-action').data('callback', function()
{
$.get(window.location.href).success(function(data)
getHtml(window.location.href).success(function(data)
{
$('#sidebar').replaceWith($(data).find('#sidebar'));
$('body').trigger('dom-update');
@ -89,7 +89,6 @@ $(function()
$('form.edit-post').submit(function(e)
{
e.preventDefault();
rememberLastSearchQuery();
var formDom = $(this);
if (formDom.hasClass('inactive'))
@ -111,7 +110,7 @@ $(function()
{
disableExitConfirmation();
$.get(window.location.href).success(function(data)
getHtml(window.location.href).success(function(data)
{
$('#sidebar').replaceWith($(data).find('#sidebar'));
$('#revision').replaceWith($(data).find('#revision'));