2014-01-25 16:34:20 +01:00
|
|
|
$(function()
|
2013-10-12 14:53:47 +02:00
|
|
|
{
|
2014-01-25 16:34:20 +01:00
|
|
|
function onDomUpdate()
|
2013-10-13 12:28:16 +02:00
|
|
|
{
|
2014-02-19 20:46:37 +01:00
|
|
|
$('#sidebar a.edit-post').bindOnce('edit-post', 'click', function(e)
|
2014-01-25 16:34:20 +01:00
|
|
|
{
|
|
|
|
e.preventDefault();
|
2013-10-13 21:42:43 +02:00
|
|
|
|
2014-01-25 16:34:20 +01:00
|
|
|
var aDom = $(this);
|
|
|
|
if (aDom.hasClass('inactive'))
|
|
|
|
return;
|
|
|
|
aDom.addClass('inactive');
|
2013-10-13 12:28:16 +02:00
|
|
|
|
2013-10-27 22:47:20 +01:00
|
|
|
var formDom = $('form.edit-post');
|
2014-01-25 16:34:20 +01:00
|
|
|
if (formDom.find('.tagit').length == 0)
|
2013-10-27 22:47:20 +01:00
|
|
|
{
|
2014-02-18 21:15:00 +01:00
|
|
|
attachTagIt($('.tags input'));
|
|
|
|
aDom.removeClass('inactive');
|
2014-02-01 10:10:09 +01:00
|
|
|
|
2014-02-18 21:15:00 +01:00
|
|
|
formDom.find('input[type=text]:visible:eq(0)').focus();
|
|
|
|
formDom.find('textarea, input').bind('change keyup', function()
|
|
|
|
{
|
|
|
|
if (formDom.serialize() != formDom.data('original-data'))
|
|
|
|
enableExitConfirmation();
|
2014-01-25 16:34:20 +01:00
|
|
|
});
|
2013-10-27 22:47:20 +01:00
|
|
|
}
|
2014-01-25 16:34:20 +01:00
|
|
|
else
|
|
|
|
aDom.removeClass('inactive');
|
2013-10-25 15:41:09 +02:00
|
|
|
|
2014-02-17 22:59:11 +01:00
|
|
|
var editUnit = formDom.parents('.unit');
|
|
|
|
var postUnit = $('.post-wrapper');
|
2014-01-25 16:34:20 +01:00
|
|
|
if (!$(formDom).is(':visible'))
|
2014-01-25 22:50:15 +01:00
|
|
|
{
|
2014-02-17 22:59:11 +01:00
|
|
|
formDom.data('original-data', formDom.serialize());
|
|
|
|
|
|
|
|
editUnit.show();
|
|
|
|
var editUnitHeight = formDom.height();
|
|
|
|
editUnit.css('height', editUnitHeight);
|
|
|
|
editUnit.hide();
|
|
|
|
|
|
|
|
if (postUnit.height() < editUnitHeight)
|
|
|
|
postUnit.animate({height: editUnitHeight + 'px'}, 'fast');
|
|
|
|
|
|
|
|
editUnit.slideDown('fast', function()
|
2014-01-25 22:50:15 +01:00
|
|
|
{
|
|
|
|
$(this).css('height', 'auto');
|
|
|
|
});
|
|
|
|
}
|
2014-02-17 22:59:11 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
editUnit.slideUp('fast');
|
|
|
|
|
|
|
|
var postUnitOldHeight = postUnit.height();
|
|
|
|
postUnit.height('auto');
|
|
|
|
var postUnitHeight = postUnit.height();
|
|
|
|
postUnit.height(postUnitOldHeight);
|
|
|
|
if (postUnitHeight != postUnitOldHeight)
|
|
|
|
postUnit.animate({height: postUnitHeight + 'px'});
|
|
|
|
|
|
|
|
if ($('.post-wrapper').height() < editUnitHeight)
|
|
|
|
$('.post-wrapper').animate({height: editUnitHeight + 'px'});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-25 16:34:20 +01:00
|
|
|
formDom.find('input[type=text]:visible:eq(0)').focus();
|
2013-10-13 12:28:16 +02:00
|
|
|
});
|
|
|
|
|
2014-01-25 16:34:20 +01:00
|
|
|
$('.comments.unit a.simple-action').data('callback', function()
|
2013-11-16 22:37:43 +01:00
|
|
|
{
|
2014-01-25 16:34:20 +01:00
|
|
|
$.get(window.location.href, function(data)
|
|
|
|
{
|
|
|
|
$('.comments-wrapper').replaceWith($(data).find('.comments-wrapper'));
|
|
|
|
$('body').trigger('dom-update');
|
|
|
|
});
|
2013-11-16 22:37:43 +01:00
|
|
|
});
|
|
|
|
|
2014-01-25 16:34:20 +01:00
|
|
|
$('#sidebar a.simple-action').data('callback', function()
|
2013-11-16 22:37:43 +01:00
|
|
|
{
|
2014-01-25 16:34:20 +01:00
|
|
|
$.get(window.location.href, function(data)
|
|
|
|
{
|
|
|
|
$('#sidebar').replaceWith($(data).find('#sidebar'));
|
|
|
|
$('body').trigger('dom-update');
|
|
|
|
});
|
2013-11-16 22:37:43 +01:00
|
|
|
});
|
2014-01-25 16:34:20 +01:00
|
|
|
}
|
2013-11-16 22:37:43 +01:00
|
|
|
|
|
|
|
$('body').bind('dom-update', onDomUpdate);
|
|
|
|
|
2013-10-17 22:57:32 +02:00
|
|
|
$('form.edit-post').submit(function(e)
|
2013-10-13 12:28:16 +02:00
|
|
|
{
|
|
|
|
e.preventDefault();
|
2013-11-24 21:50:46 +01:00
|
|
|
rememberLastSearchQuery();
|
2013-10-13 12:28:16 +02:00
|
|
|
|
|
|
|
var formDom = $(this);
|
|
|
|
if (formDom.hasClass('inactive'))
|
|
|
|
return;
|
|
|
|
formDom.addClass('inactive');
|
|
|
|
formDom.find(':input').attr('readonly', true);
|
|
|
|
|
|
|
|
var url = formDom.attr('action') + '?json';
|
|
|
|
var fd = new FormData(formDom[0]);
|
|
|
|
|
|
|
|
var ajaxData =
|
|
|
|
{
|
|
|
|
url: url,
|
|
|
|
data: fd,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
type: 'POST',
|
|
|
|
|
|
|
|
success: function(data)
|
|
|
|
{
|
2014-05-01 22:29:36 +02:00
|
|
|
disableExitConfirmation();
|
2014-02-01 10:10:09 +01:00
|
|
|
|
2014-05-01 22:29:36 +02:00
|
|
|
$.get(window.location.href, function(data)
|
2013-10-13 12:28:16 +02:00
|
|
|
{
|
2014-05-01 22:29:36 +02:00
|
|
|
$('#sidebar').replaceWith($(data).find('#sidebar'));
|
|
|
|
$('#edit-token').replaceWith($(data).find('#edit-token'));
|
|
|
|
$('body').trigger('dom-update');
|
|
|
|
});
|
|
|
|
formDom.parents('.unit').hide();
|
2013-11-23 09:51:57 +01:00
|
|
|
formDom.find(':input').attr('readonly', false);
|
|
|
|
formDom.removeClass('inactive');
|
|
|
|
},
|
2014-05-01 22:29:36 +02:00
|
|
|
error: function(xhr)
|
2013-11-23 09:51:57 +01:00
|
|
|
{
|
2014-05-01 22:29:36 +02:00
|
|
|
alert(xhr.responseJSON
|
|
|
|
? xhr.responseJSON.message
|
|
|
|
: 'Fatal error');
|
2013-11-23 09:51:57 +01:00
|
|
|
formDom.find(':input').attr('readonly', false);
|
|
|
|
formDom.removeClass('inactive');
|
2013-10-17 22:57:32 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax(ajaxData);
|
|
|
|
});
|
2013-10-25 15:41:09 +02:00
|
|
|
|
2014-03-05 22:14:30 +01:00
|
|
|
Mousetrap.bind('a', function()
|
|
|
|
{
|
|
|
|
var a = $('#sidebar .left a');
|
|
|
|
var url = a.attr('href');
|
|
|
|
if (typeof url !== 'undefined')
|
|
|
|
{
|
|
|
|
a.click();
|
|
|
|
window.location.href = url;
|
|
|
|
}
|
|
|
|
}, 'keyup');
|
|
|
|
|
|
|
|
Mousetrap.bind('d', function()
|
|
|
|
{
|
|
|
|
var a = $('#sidebar .right a');
|
|
|
|
var url = a.attr('href');
|
|
|
|
if (typeof url !== 'undefined')
|
|
|
|
{
|
|
|
|
a.click();
|
|
|
|
window.location.href = url;
|
|
|
|
}
|
|
|
|
}, 'keyup');
|
|
|
|
|
|
|
|
Mousetrap.bind('e', function()
|
|
|
|
{
|
|
|
|
$('a.edit-post').trigger('click');
|
|
|
|
return false;
|
|
|
|
}, 'keyup');
|
2013-10-12 14:53:47 +02:00
|
|
|
});
|