Updated dependencies.
[wolnelektury.git] / media / js / catalogue.js
1 (function($) {
2     $(function() {
3         $('#id_q').labelify({labelledClass: 'blur'});
4         
5         target = $('#login-register-window div.target');
6         
7         $('#show-registration-form').click(function() {
8             $('#login-form').hide();
9             $('#registration-form').show();
10         });
11         
12         $('#show-login-form').click(function() {
13             $('#registration-form').hide();
14             $('#login-form').show();
15         });
16         
17         $('#registration-form').ajaxForm({
18             dataType: 'json',
19             beforeSubmit: function() {
20                 $('#registration-form input[type=submit]')
21                     .attr('disabled', 'disabled')
22                     .after('<img src="/media/img/indicator.gif" style="margin-left: 0.5em"/>');
23             },
24             success: function(response) {
25                 if (response.success) {
26                     location.reload(true);
27                 } else {
28                     $('#registration-form span.error').remove();
29                     $.each(response.errors, function(id, errors) {
30                         $('#id_registration-' + id).before('<span class="error">' + errors[0] + '</span>');
31                     });
32                     $('#registration-form input[type=submit]').removeAttr('disabled');
33                     $('#registration-form img').remove();
34                 }
35             }
36         });
37         
38         $('#login-form').ajaxForm({
39             dataType: 'json',
40             beforeSubmit: function() {
41                 $('#login-form input[type=submit]')
42                     .attr('disabled', 'disabled')
43                     .after('<img src="/media/img/indicator.gif" style="margin-left: 0.5em"/>');
44             },
45             success: function(response) {
46                 if (response.success) {
47                     location.reload(true);
48                 } else {
49                     $('#login-form span.error').remove();
50                     $.each(response.errors, function(id, errors) {
51                         $('#id_login-' + id).before('<span class="error">' + errors[0] + '</span>');
52                     });
53                     $('#login-form input[type=submit]').removeAttr('disabled');
54                     $('#login-form img').remove();
55                 }
56             }
57         });
58         
59         $('#login-register-window').jqm({
60             target: target[0],
61             overlay: 60,
62             trigger: '#login-register-link',
63             onShow: function(hash) {
64                 var offset = $(hash.t).offset();
65                 hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top});
66                 $('div.header', hash.w).css({width: $(hash.t).width()});
67                 hash.w.show();
68             }
69         });
70         $('#login-register-window').labelify({labelledClass: 'blur'});
71     });
72 })(jQuery)