Fixed problem with comment edit links

This commit is contained in:
Marcin Kurczewski 2014-02-19 20:27:45 +01:00
parent 38771eb7be
commit b879a7c38b

View file

@ -3,12 +3,15 @@ $(function()
function onDomUpdate() function onDomUpdate()
{ {
$('form.edit-comment textarea, form.add-comment textarea') $('form.edit-comment textarea, form.add-comment textarea')
.bind('change keyup', function(e) .off('change keyp')
.on('change keyup', function(e)
{ {
enableExitConfirmation(); enableExitConfirmation();
}); });
$('form.edit-comment, form.add-comment').submit(function(e) $('form.edit-comment, form.add-comment')
.off('submit')
.on('submit', function(e)
{ {
e.preventDefault(); e.preventDefault();
rememberLastSearchQuery(); rememberLastSearchQuery();
@ -93,19 +96,30 @@ $(function()
$.ajax(ajaxData); $.ajax(ajaxData);
}); });
$('.comment .edit a').click(function(e) $('.comment .edit a').off('click').on('click').click(function(e)
{ {
e.preventDefault(); e.preventDefault();
var commentDom = $(this).parents('.comment'); var commentDom = $(this).parents('.comment');
var formDom = commentDom.find('form.edit-comment');
var cb = function(formDom)
{
formDom.slideToggle();
$('body').trigger('dom-update');
};
if (formDom.length == 0)
{
$.get($(this).attr('href'), function(data) $.get($(this).attr('href'), function(data)
{ {
commentDom.find('form.edit-comment').remove();
var otherForm = $(data).find('form.edit-comment'); var otherForm = $(data).find('form.edit-comment');
otherForm.hide(); otherForm.hide();
commentDom.find('.body').append(otherForm); commentDom.find('.body').append(otherForm);
otherForm.slideDown(); formDom = commentDom.find('form.edit-comment');
$('body').trigger('dom-update'); cb(formDom);
}); });
}
else
cb(formDom);
}); });
} }