X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/b07520a11332374de645ed22c74959afa8a4b7ed..56511fcfdd20abcaf54827a90125c527d154125b:/wolnelektury/static/js/dialogs.js diff --git a/wolnelektury/static/js/dialogs.js b/wolnelektury/static/js/dialogs.js index bf9d94b54..d44dab32e 100755 --- a/wolnelektury/static/js/dialogs.js +++ b/wolnelektury/static/js/dialogs.js @@ -7,15 +7,11 @@ $window.attr("id", this.id + "-window"); $('body').append($window); + var $trigger = $(this) var trigger = '#' + this.id; - var href = $(this).attr('href'); - if (href.search('\\?') != -1) - href += '&ajax=1'; - else href += '?ajax=1'; - $window.jqm({ - ajax: href, + ajax: '@href', ajaxText: '
' + gettext("Loading") + '
' + gettext("Loading") + '
');
+ },
+ error: function(response) {
+ if (response.status == 403)
+ login_and_retry($form);
+ },
+ success: function(response) {
+ if (response.success) {
+ callback = ajax_form_callbacks[$form.attr('data-callback')];
+ callback && callback($form, response);
+
+ } else {
+ $('span.error', $form).remove();
+ $.each(response.errors, function(id, errors) {
+ $('#id_' + id, $form).before('' + errors[0] + '');
+ });
+ $('input[type=submit]', $form).removeAttr('disabled');
+ $('img', $form).remove();
+ }
+ }
+ });
+ });
+
+
+ var update_star = function($elem, response) {
+ /* updates the star after successful ajax */
+ var $star = $elem.closest('.star');
+ if (response.like) {
+ $star.addClass('like');
+ $star.removeClass('unlike');
+ }
+ else {
+ $star.addClass('unlike');
+ $star.removeClass('like');
+ }
+ };
+
+ var ajax_form_callbacks = {
+ 'social-like-book': update_star
+ };
+
+ var ajaxable_callbacks = {
+ 'social-book-sets': location.reload
+ };
+
+
+
+ // check placeholder browser support
+ if (!Modernizr.input.placeholder)
+ {
+ // set placeholder values
+ $(this).find('[placeholder]').each(function()
+ {
+ $(this).val( $(this).attr('placeholder') ).addClass('placeholder');
+ });
+
+ // focus and blur of placeholders
+ $('[placeholder]').focus(function()
+ {
+ if ($(this).val() == $(this).attr('placeholder'))
+ {
+ $(this).val('');
+ $(this).removeClass('placeholder');
+ }
+ }).blur(function()
+ {
+ if ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))
+ {
+ $(this).val($(this).attr('placeholder'));
+ $(this).addClass('placeholder');
+ }
+ });
+
+ // remove placeholders on submit
+ $('[placeholder]').closest('form').submit(function()
+ {
+ $(this).find('[placeholder]').each(function()
+ {
+ if ($(this).val() == $(this).attr('placeholder'))
+ {
+ $(this).val('');
+ }
+ })
+ });
+ }
+
+
+
});
})(jQuery)