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-01-25 16:34:20 +01:00
|
|
|
$('#sidebar .edit a').click(function(e)
|
|
|
|
{
|
|
|
|
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-01-25 16:34:20 +01:00
|
|
|
$.getJSON('/tags?json', {filter: 'order:popularity,desc'}, function(data)
|
|
|
|
{
|
|
|
|
aDom.removeClass('inactive');
|
|
|
|
var tags = data['tags'];
|
|
|
|
|
|
|
|
var tagItOptions = getTagItOptions();
|
|
|
|
tagItOptions.availableTags = tags;
|
|
|
|
tagItOptions.placeholderText = $('.tags input').attr('placeholder');
|
|
|
|
$('.tags input').tagit(tagItOptions);
|
2014-01-30 21:53:34 +01:00
|
|
|
formDom.find('input[type=text]:visible:eq(0)').focus();
|
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-01-25 16:34:20 +01:00
|
|
|
if (!$(formDom).is(':visible'))
|
2014-01-25 22:50:15 +01:00
|
|
|
{
|
|
|
|
formDom.parents('.unit')
|
|
|
|
.show().css('height', formDom.height()).hide()
|
|
|
|
.slideDown(function()
|
|
|
|
{
|
|
|
|
$(this).css('height', 'auto');
|
|
|
|
});
|
|
|
|
}
|
2013-10-25 15:41:09 +02:00
|
|
|
$('html, body').animate({ scrollTop: $(formDom).offset().top + 'px' }, 'fast');
|
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)
|
|
|
|
{
|
|
|
|
if (data['success'])
|
|
|
|
{
|
2014-01-25 16:34:20 +01:00
|
|
|
$.get(window.location.href, function(data)
|
|
|
|
{
|
|
|
|
$('#sidebar').replaceWith($(data).find('#sidebar'));
|
|
|
|
$('#edit-token').replaceWith($(data).find('#edit-token'));
|
|
|
|
$('body').trigger('dom-update');
|
|
|
|
});
|
|
|
|
formDom.parents('.unit').hide();
|
2013-10-13 12:28:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-16 21:14:27 +01:00
|
|
|
alert(data['message']);
|
2013-10-13 12:28:16 +02:00
|
|
|
}
|
2013-11-23 09:51:57 +01:00
|
|
|
formDom.find(':input').attr('readonly', false);
|
|
|
|
formDom.removeClass('inactive');
|
|
|
|
},
|
|
|
|
error: function()
|
|
|
|
{
|
|
|
|
alert('Fatal error');
|
|
|
|
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
|
|
|
|
2013-11-24 21:50:46 +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');
|
2013-10-26 12:39:15 +02:00
|
|
|
Mousetrap.bind('e', function() { $('li.edit a').trigger('click'); return false; }, 'keyup');
|
2013-10-12 14:53:47 +02:00
|
|
|
});
|