2013-10-29 09:04:42 +01:00
|
|
|
$(function()
|
|
|
|
{
|
2013-11-05 09:17:44 +01:00
|
|
|
$('body').bind('dom-update', function()
|
2013-10-29 09:04:42 +01:00
|
|
|
{
|
2014-02-19 20:46:37 +01:00
|
|
|
$('.post a.toggle-tag').bindOnce('toggle-tag', 'click', function(e)
|
2013-11-05 09:17:44 +01:00
|
|
|
{
|
|
|
|
e.preventDefault();
|
2013-10-29 09:04:42 +01:00
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
var aDom = $(this);
|
|
|
|
if (aDom.hasClass('inactive'))
|
|
|
|
return;
|
|
|
|
aDom.addClass('inactive');
|
2013-10-29 09:04:42 +01:00
|
|
|
|
2013-11-25 11:59:59 +01:00
|
|
|
var enable = !aDom.parents('.post').hasClass('tagged');
|
2014-05-15 23:11:53 +02:00
|
|
|
var url = $(this).attr('href');
|
2014-05-16 19:31:04 +02:00
|
|
|
url = url.replace(/\/[01]\/?$/, '/' + (enable ? '1' : '0'));
|
2014-05-15 23:11:53 +02:00
|
|
|
postJSON({ url: url }).success(function(data)
|
2013-10-29 09:04:42 +01:00
|
|
|
{
|
2014-05-01 22:29:36 +02:00
|
|
|
aDom.removeClass('inactive');
|
|
|
|
aDom.parents('.post').removeClass('tagged');
|
|
|
|
if (enable)
|
|
|
|
aDom.parents('.post').addClass('tagged');
|
|
|
|
aDom.text(enable
|
|
|
|
? aDom.attr('data-text-tagged')
|
|
|
|
: aDom.attr('data-text-untagged'));
|
|
|
|
}).error(function(xhr)
|
|
|
|
{
|
|
|
|
alert(xhr.responseJSON
|
|
|
|
? xhr.responseJSON.message
|
|
|
|
: 'Fatal error');
|
|
|
|
aDom.removeClass('inactive');
|
2013-11-05 09:17:44 +01:00
|
|
|
});
|
2013-10-29 09:04:42 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|