4         // create containers for all ajaxable form links
 
   5         $('.ajaxable').each(function() {
 
   6             var $window = $("#ajaxable-window").clone();
 
   7             $window.attr("id", this.id + "-window");
 
   8             $('body').append($window);
 
  10             var $trigger = $(this)
 
  11             var trigger = '#' + this.id;
 
  15                 ajaxText: '<p><img src="' + STATIC_URL + 'img/indicator.gif" alt="*"/> ' + gettext("Loading") + '</p>',
 
  16                 target: $('.target', $window)[0],
 
  19                 onShow: function(hash) {
 
  20                     var offset = $(hash.t).offset();
 
  21                     var oleft = offset.left - hash.w.width() + $(hash.t).width();
 
  22                     if (oleft < 0) oleft = 0;
 
  23                     hash.w.css({position: 'absolute', left: oleft, top: offset.top});
 
  24                     var width = $(hash.t).width();
 
  25                     width = width > 50 ? width : 50;
 
  26                     $('.header', hash.w).css({width: width});
 
  29                 onLoad: function(hash) {
 
  30                     $('form', hash.w).ajaxForm({
 
  32                         target: $('.target', $window),
 
  33                         success: function(response) {
 
  34                             if (response.success) {
 
  35                                 $('.target', $window).text(response.message);
 
  36                                 setTimeout(function() { $window.jqmHide() }, 1000);
 
  37                                 callback = ajaxable_callbacks[$trigger.attr('data-callback')];
 
  38                                 callback && callback($trigger, response);
 
  39                                 if (response.redirect)
 
  40                                     window.location = response.redirect;
 
  43                                 $('.error', $window).remove();
 
  44                                 $.each(response.errors, function(id, errors) {
 
  45                                     $('#id_' + id, $window).before('<span class="error">' + errors[0] + '</span>');
 
  47                                 $('input[type=submit]', $window).removeAttr('disabled');
 
  57         var login_and_retry = function($form) {
 
  58             var $window = $("#ajaxable-window").clone();
 
  59             $window.attr("id", "context-login-window");
 
  60             $('body').append($window);
 
  63                 ajax: '/uzytkownik/zaloguj-utworz/?next=' + escape(window.location),
 
  64                 ajaxText: '<p><img src="' + STATIC_URL + 'img/indicator.gif" alt="*"/> ' + gettext("Loading") + '</p>',
 
  65                 target: $('.target', $window)[0],
 
  67                 onShow: function(hash) {
 
  68                     var offset = $form.offset();
 
  69                     hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $form.width(), top: offset.top});
 
  70                     var width = $form.width();
 
  71                     width = width > 50 ? width : 50;
 
  72                     $('.header', hash.w).css({width: width});
 
  75                 onLoad: function(hash) {
 
  76                     $('form', hash.w).ajaxForm({
 
  78                         target: $('.target', $window),
 
  79                         success: function(response) {
 
  80                             if (response.success) {
 
  81                                 $('.target', $window).text(response.message);
 
  82                                 setTimeout(function() { $window.jqmHide() }, 1000);
 
  87                                 $('.error', $window).remove();
 
  88                                 $.each(response.errors, function(id, errors) {
 
  89                                     $('#id_' + id, $window).before('<span class="error">' + errors[0] + '</span>');
 
  91                                 $('input[type=submit]', $window).removeAttr('disabled');
 
 102         $('.ajax-form').each(function() {
 
 106                 beforeSubmit: function() {
 
 107                     $('input[type=submit]', $form)
 
 108                         .attr('disabled', 'disabled')
 
 109                         .after('<img src="/static/img/indicator.gif" style="margin-left: 0.5em"/>');
 
 111                 error: function(response) {
 
 112                         if (response.status == 403)
 
 113                             login_and_retry($form);
 
 115                 success: function(response) {
 
 116                     if (response.success) {
 
 117                         callback = ajax_form_callbacks[$form.attr('data-callback')];
 
 118                         callback && callback($form, response);
 
 121                         $('span.error', $form).remove();
 
 122                         $.each(response.errors, function(id, errors) {
 
 123                             $('#id_' + id, $form).before('<span class="error">' + errors[0] + '</span>');
 
 125                         $('input[type=submit]', $form).removeAttr('disabled');
 
 126                         $('img', $form).remove();
 
 133         var update_star = function($elem, response) {
 
 134             /* updates the star after successful ajax */
 
 135             var $star = $elem.closest('.star');
 
 137                 $star.addClass('like');
 
 138                 $star.removeClass('unlike');
 
 141                 $star.addClass('unlike');
 
 142                 $star.removeClass('like');
 
 146         var ajax_form_callbacks = {
 
 147             'social-like-book': update_star
 
 150         var ajaxable_callbacks = {
 
 151             'social-book-sets': location.reload
 
 156     // check placeholder browser support
 
 157     if (!Modernizr.input.placeholder)
 
 159         // set placeholder values
 
 160         $(this).find('[placeholder]').each(function()
 
 162             $(this).val( $(this).attr('placeholder') ).addClass('placeholder');
 
 165         // focus and blur of placeholders
 
 166         $('[placeholder]').focus(function()
 
 168             if ($(this).val() == $(this).attr('placeholder'))
 
 171                 $(this).removeClass('placeholder');
 
 175             if ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))
 
 177                 $(this).val($(this).attr('placeholder'));
 
 178                 $(this).addClass('placeholder');
 
 182         // remove placeholders on submit
 
 183         $('[placeholder]').closest('form').submit(function()
 
 185             $(this).find('[placeholder]').each(function()
 
 187                 if ($(this).val() == $(this).attr('placeholder'))