szurubooru/public_html/media/js/post-view.js

125 lines
2.2 KiB
JavaScript
Raw Normal View History

2013-10-12 14:53:47 +02:00
$(function()
{
2013-10-13 12:28:16 +02:00
$('.add-fav a, .rem-fav a, .hide a, .unhide a').click(function(e)
2013-10-12 14:53:47 +02:00
{
e.preventDefault();
2013-10-13 12:28:16 +02:00
var aDom = $(this);
if (aDom.hasClass('inactive'))
return;
aDom.addClass('inactive');
var url = $(this).attr('href') + '?json';
2013-10-12 14:53:47 +02:00
$.get(url, function(data)
{
2013-10-13 12:28:16 +02:00
if (data['success'])
2013-10-12 14:53:47 +02:00
{
2013-10-13 12:28:16 +02:00
window.location.reload();
2013-10-12 14:53:47 +02:00
}
else
{
2013-10-13 12:28:16 +02:00
alert(data['errorMessage']);
aDom.removeClass('inactive');
2013-10-12 14:53:47 +02:00
}
});
});
2013-10-13 12:28:16 +02:00
$('.delete a').click(function(e)
{
e.preventDefault();
var aDom = $(this);
if (aDom.hasClass('inactive'))
return;
aDom.addClass('inactive');
//todo: move this string literal to html
if (confirm(aDom.attr('data-confirm-text')))
{
var url = $(this).attr('href') + '?json';
$.get(url, function(data)
{
if (data['success'])
{
window.location.href = aDom.attr('data-redirect-url');
}
else
{
alert(data['errorMessage']);
aDom.removeClass('inactive');
}
});
}
else
{
aDom.removeClass('inactive');
}
});
$('li.edit a').click(function(e)
{
2013-10-13 21:42:43 +02:00
e.preventDefault();
2013-10-13 12:28:16 +02:00
var aDom = $(this);
if (aDom.hasClass('inactive'))
return;
aDom.addClass('inactive');
var tags = [];
$.getJSON('/tags?json', function(data)
{
tags = data['tags'];
var tagItOptions =
{
caseSensitive: true,
availableTags: tags,
placeholderText: $('.tags input').attr('placeholder')
};
$('.tags input').tagit(tagItOptions);
e.preventDefault();
$('form.edit').slideDown();
});
});
$('form.edit').submit(function(e)
{
e.preventDefault();
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'])
{
window.location.reload();
}
else
{
alert(data['errorMessage']);
formDom.find(':input').attr('readonly', false);
formDom.removeClass('inactive');
}
}
};
$.ajax(ajaxData);
});
2013-10-12 14:53:47 +02:00
});