From 09b5a38c959c99010253d459493cd31f27479c77 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 5 Nov 2013 09:17:44 +0100 Subject: [PATCH] Fixed issue with masstag in endless scrolling mode --- public_html/media/js/core.js | 135 ++++++++++++---------- public_html/media/js/mass-tag.js | 55 ++++----- public_html/media/js/paginator-endless.js | 1 + 3 files changed, 107 insertions(+), 84 deletions(-) diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js index 5080ab6b..2466139a 100644 --- a/public_html/media/js/core.js +++ b/public_html/media/js/core.js @@ -1,3 +1,4 @@ +//core functionalities, prototypes $.fn.hasAttr = function(name) { return this.attr(name) !== undefined; @@ -20,6 +21,9 @@ if ($.when.all === undefined) } } + + +//safety trigger $(function() { $('.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 = $('').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 = $('').attr({ + name: $(this).attr('name'), + value: $(this).val() + }); + form.append(input); + }); + }); + }); + $('body').trigger('dom-update'); +}); + + + //modify DOM on small viewports $(window).resize(function() { @@ -131,6 +146,7 @@ $(function() }); + //autocomplete function split(val) { @@ -214,6 +230,9 @@ function getTagItOptions() }; } + + +//hotkeys $(function() { Mousetrap.bind('q', function() { $('#top-nav input').focus(); return false; }, 'keyup'); diff --git a/public_html/media/js/mass-tag.js b/public_html/media/js/mass-tag.js index 32a9501a..6afd4a99 100644 --- a/public_html/media/js/mass-tag.js +++ b/public_html/media/js/mass-tag.js @@ -1,34 +1,37 @@ $(function() { - $('.post a.toggle-tag').click(function(e) + $('body').bind('dom-update', function() { - 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) + $('.post a.toggle-tag').click(function(e) { - 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'); - aDom.parents('.post').toggleClass('tagged'); - aDom.text(aDom.parents('.post').hasClass('tagged') - ? aDom.attr('data-text-tagged') - : aDom.attr('data-text-untagged')); - } - else - { - alert(data['errorMessage']); - aDom.removeClass('inactive'); - } + if (data['success']) + { + aDom.removeClass('inactive'); + aDom.parents('.post').toggleClass('tagged'); + aDom.text(aDom.parents('.post').hasClass('tagged') + ? aDom.attr('data-text-tagged') + : aDom.attr('data-text-untagged')); + } + else + { + alert(data['errorMessage']); + aDom.removeClass('inactive'); + } + }); }); }); }); diff --git a/public_html/media/js/paginator-endless.js b/public_html/media/js/paginator-endless.js index aaef4317..ded9e59e 100644 --- a/public_html/media/js/paginator-endless.js +++ b/public_html/media/js/paginator-endless.js @@ -18,6 +18,7 @@ function scrolled() var nextPage = dom.find('.paginator .next:not(.disabled) a').attr('href'); $(document).data('page-next', nextPage); $('.paginator-content').append($(response).find('.paginator-content').children().css({opacity: 0}).animate({opacity: 1}, 'slow')); + $('body').trigger('dom-update'); scrolled(); }); }