Post view actions don't reload the page anymore

This commit is contained in:
Marcin Kurczewski 2013-11-16 22:37:43 +01:00
parent 4e64431a96
commit 4166200dbc
2 changed files with 49 additions and 14 deletions

View file

@ -39,13 +39,9 @@ $(function()
$.get(url, function(data)
{
if (data['success'])
{
window.location.reload();
}
else
{
alert(data['message']);
}
});
});
});
@ -88,6 +84,8 @@ $(function()
{
if (aDom.hasAttr('data-redirect-url'))
window.location.href = aDom.attr('data-redirect-url');
else if (aDom.data('callback'))
aDom.data('callback')();
else
window.location.reload();
}
@ -115,16 +113,13 @@ $(function()
});
});
});
$('body').trigger('dom-update');
});
//modify DOM on small viewports
$(window).resize(function()
function processSidebar()
{
if ($('body').width() == $('body').data('last-width'))
return;
$('#inner-content .unit').addClass('bottom-unit');
if ($('body').width() < 600)
{
@ -139,10 +134,15 @@ $(window).resize(function()
$('#sidebar .unit').removeClass('bottom-unit').addClass('left-unit');
}
$('body').data('last-width', $('body').width());
});
}
$(function()
{
$(window).resize();
$(window).resize(function()
{
if ($('body').width() == $('body').data('last-width'))
return;
});
$('body').bind('dom-update', processSidebar);
});
@ -242,3 +242,9 @@ $(function()
Mousetrap.bind('d', function() { var url = $('.paginator:visible .next:not(.disabled) a').attr('href'); if (typeof url !== 'undefined') window.location.href = url; }, 'keyup');
Mousetrap.bind('p', function() { $('.post a').eq(0).focus(); return false; }, 'keyup');
});
$(function()
{
$('body').trigger('dom-update');
});

View file

@ -1,4 +1,4 @@
$(function()
function onDomUpdate()
{
$('li.edit a').click(function(e)
{
@ -30,6 +30,30 @@ $(function()
});
});
$('.comments.unit a.simple-action').data('callback', function()
{
$.get(window.location.href, function(data)
{
$('.comments.unit').replaceWith($(data).find('.comments.unit'));
$('body').trigger('dom-update');
});
});
$('#sidebar a.simple-action').data('callback', function()
{
$.get(window.location.href, function(data)
{
$('#sidebar').replaceWith($(data).find('#sidebar'));
$('body').trigger('dom-update');
});
});
}
$(function()
{
$('body').bind('dom-update', onDomUpdate);
onDomUpdate();
$('form.edit-post').submit(function(e)
{
e.preventDefault();
@ -104,13 +128,18 @@ $(function()
if (preview)
{
formDom.find('.preview').html(data['textPreview']).show();
formDom.find(':input').attr('readonly', false);
formDom.removeClass('inactive');
}
else
{
window.location.reload();
$.get(window.location.href, function(data)
{
$('.comments.unit').replaceWith($(data).find('.comments.unit'));
$('body').trigger('dom-update');
});
formDom.find('textarea').val('');
}
formDom.find(':input').attr('readonly', false);
formDom.removeClass('inactive');
}
else
{