Fixed issue with masstag in endless scrolling mode

This commit is contained in:
Marcin Kurczewski 2013-11-05 09:17:44 +01:00
parent b093a090eb
commit 09b5a38c95
3 changed files with 107 additions and 84 deletions

View file

@ -1,3 +1,4 @@
//core functionalities, prototypes
$.fn.hasAttr = function(name) $.fn.hasAttr = function(name)
{ {
return this.attr(name) !== undefined; return this.attr(name) !== undefined;
@ -20,6 +21,9 @@ if ($.when.all === undefined)
} }
} }
//safety trigger
$(function() $(function()
{ {
$('.safety a').click(function(e) $('.safety a').click(function(e)
@ -44,67 +48,78 @@ $(function()
} }
}); });
}); });
function confirmEvent(e)
{
if (!confirm($(this).attr('data-confirm-text')))
{
e.preventDefault();
e.stopPropagation();
}
}
$('form[data-confirm-text]').submit(confirmEvent);
$('a[data-confirm-text]').click(confirmEvent);
$('a.simple-action').click(function(e)
{
if(e.isPropagationStopped())
return;
e.preventDefault();
var aDom = $(this);
if (aDom.hasClass('inactive'))
return;
aDom.addClass('inactive');
var url = $(this).attr('href') + '?json';
$.get(url, {submit: 1}, function(data)
{
if (data['success'])
{
if (aDom.hasAttr('data-redirect-url'))
window.location.href = aDom.attr('data-redirect-url');
else
window.location.reload();
}
else
{
alert(data['errorMessage']);
aDom.removeClass('inactive');
}
});
});
//attach data from submit buttons to forms before .submit() gets called
$(':submit').each(function()
{
$(this).click(function()
{
var form = $(this).closest('form');
form.find('.faux-submit').remove();
var input = $('<input class="faux-submit" type="hidden"/>').attr({
name: $(this).attr('name'),
value: $(this).val()
});
form.append(input);
});
});
}); });
//basic event listeners
$(function()
{
$('body').bind('dom-update', function()
{
function confirmEvent(e)
{
if (!confirm($(this).attr('data-confirm-text')))
{
e.preventDefault();
e.stopPropagation();
}
}
$('form[data-confirm-text]').submit(confirmEvent);
$('a[data-confirm-text]').click(confirmEvent);
$('a.simple-action').click(function(e)
{
if(e.isPropagationStopped())
return;
e.preventDefault();
var aDom = $(this);
if (aDom.hasClass('inactive'))
return;
aDom.addClass('inactive');
var url = $(this).attr('href') + '?json';
$.get(url, {submit: 1}, function(data)
{
if (data['success'])
{
if (aDom.hasAttr('data-redirect-url'))
window.location.href = aDom.attr('data-redirect-url');
else
window.location.reload();
}
else
{
alert(data['errorMessage']);
aDom.removeClass('inactive');
}
});
});
//attach data from submit buttons to forms before .submit() gets called
$(':submit').each(function()
{
$(this).click(function()
{
var form = $(this).closest('form');
form.find('.faux-submit').remove();
var input = $('<input class="faux-submit" type="hidden"/>').attr({
name: $(this).attr('name'),
value: $(this).val()
});
form.append(input);
});
});
});
$('body').trigger('dom-update');
});
//modify DOM on small viewports //modify DOM on small viewports
$(window).resize(function() $(window).resize(function()
{ {
@ -131,6 +146,7 @@ $(function()
}); });
//autocomplete //autocomplete
function split(val) function split(val)
{ {
@ -214,6 +230,9 @@ function getTagItOptions()
}; };
} }
//hotkeys
$(function() $(function()
{ {
Mousetrap.bind('q', function() { $('#top-nav input').focus(); return false; }, 'keyup'); Mousetrap.bind('q', function() { $('#top-nav input').focus(); return false; }, 'keyup');

View file

@ -1,34 +1,37 @@
$(function() $(function()
{ {
$('.post a.toggle-tag').click(function(e) $('body').bind('dom-update', function()
{ {
if(e.isPropagationStopped()) $('.post a.toggle-tag').click(function(e)
return;
e.preventDefault();
e.stopPropagation();
var aDom = $(this);
if (aDom.hasClass('inactive'))
return;
aDom.addClass('inactive');
var url = $(this).attr('href') + '?json';
$.get(url, {submit: 1}, function(data)
{ {
if (data['success']) if(e.isPropagationStopped())
return;
e.preventDefault();
e.stopPropagation();
var aDom = $(this);
if (aDom.hasClass('inactive'))
return;
aDom.addClass('inactive');
var url = $(this).attr('href') + '?json';
$.get(url, {submit: 1}, function(data)
{ {
aDom.removeClass('inactive'); if (data['success'])
aDom.parents('.post').toggleClass('tagged'); {
aDom.text(aDom.parents('.post').hasClass('tagged') aDom.removeClass('inactive');
? aDom.attr('data-text-tagged') aDom.parents('.post').toggleClass('tagged');
: aDom.attr('data-text-untagged')); aDom.text(aDom.parents('.post').hasClass('tagged')
} ? aDom.attr('data-text-tagged')
else : aDom.attr('data-text-untagged'));
{ }
alert(data['errorMessage']); else
aDom.removeClass('inactive'); {
} alert(data['errorMessage']);
aDom.removeClass('inactive');
}
});
}); });
}); });
}); });

View file

@ -18,6 +18,7 @@ function scrolled()
var nextPage = dom.find('.paginator .next:not(.disabled) a').attr('href'); var nextPage = dom.find('.paginator .next:not(.disabled) a').attr('href');
$(document).data('page-next', nextPage); $(document).data('page-next', nextPage);
$('.paginator-content').append($(response).find('.paginator-content').children().css({opacity: 0}).animate({opacity: 1}, 'slow')); $('.paginator-content').append($(response).find('.paginator-content').children().css({opacity: 0}).animate({opacity: 1}, 'slow'));
$('body').trigger('dom-update');
scrolled(); scrolled();
}); });
} }