11d30b8c275adb72fa65b381e0efe0ebe62727b2
[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         $('.fragment-text').toggle(
18             function() { $(this).addClass('fragment-text-full').removeClass('fragment-text'); }, 
19             function() { $(this).addClass('fragment-text').removeClass('fragment-text-full'); }
20         ).hover(
21             function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
22             function() { $(this).css({background: '#FFF'}); }
23         )
24         
25         $('#registration-form').ajaxForm({
26             dataType: 'json',
27             beforeSubmit: function() {
28                 $('#registration-form input[type=submit]')
29                     .attr('disabled', 'disabled')
30                     .after('<img src="/media/img/indicator.gif" style="margin-left: 0.5em"/>');
31             },
32             success: function(response) {
33                 if (response.success) {
34                     location.reload(true);
35                 } else {
36                     $('#registration-form span.error').remove();
37                     $.each(response.errors, function(id, errors) {
38                         $('#id_registration-' + id).before('<span class="error">' + errors[0] + '</span>');
39                     });
40                     $('#registration-form input[type=submit]').removeAttr('disabled');
41                     $('#registration-form img').remove();
42                 }
43             }
44         });
45         
46         $('#login-form').ajaxForm({
47             dataType: 'json',
48             beforeSubmit: function() {
49                 $('#login-form input[type=submit]')
50                     .attr('disabled', 'disabled')
51                     .after('<img src="/media/img/indicator.gif" style="margin-left: 0.5em"/>');
52             },
53             success: function(response) {
54                 if (response.success) {
55                     location.reload(true);
56                 } else {
57                     $('#login-form span.error').remove();
58                     $.each(response.errors, function(id, errors) {
59                         $('#id_login-' + id).before('<span class="error">' + errors[0] + '</span>');
60                     });
61                     $('#login-form input[type=submit]').removeAttr('disabled');
62                     $('#login-form img').remove();
63                 }
64             }
65         });
66         
67         $('#login-register-window').jqm({
68             target: target[0],
69             overlay: 60,
70             trigger: '#login-register-link',
71             onShow: function(hash) {
72                 var offset = $(hash.t).offset();
73                 hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top});
74                 $('div.header', hash.w).css({width: $(hash.t).width()});
75                 hash.w.show();
76             }
77         });
78         $('#login-register-window').labelify({labelledClass: 'blur'});
79     });
80 })(jQuery)