Folding of taq lists on main page.
[wolnelektury.git] / wolnelektury / media / js / catalogue.js
1 (function($) {
2     $(function() {
3         $('form input').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         // Fragments
18         $('.fragment-text').each(function() {
19             if ($(this).prev().filter('.fragment-short-text').length) {
20                 $(this).hover(
21                     function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
22                     function() { $(this).css({background: '#FFF'}); }
23                 ).click(function() {
24                     $(this).fadeOut(function() {
25                         $(this).prev().fadeIn()
26                     });
27                 })
28             }
29         });
30         
31         $('.fragment-short-text').click(function() {
32             $(this).fadeOut(function() { $(this).next().fadeIn() });
33         }).hover(
34             function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
35             function() { $(this).css({background: '#FFF'}); }
36         );
37         
38         $('.show-all-tags').click(function() {
39             $(this).parent().parent().fadeOut(function() { 
40                 $(this).next().fadeIn();
41             });
42         });
43         
44         
45         
46         $('#registration-form').ajaxForm({
47             dataType: 'json',
48             beforeSubmit: function() {
49                 $('#registration-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                     $('#registration-form span.error').remove();
58                     $.each(response.errors, function(id, errors) {
59                         $('#id_registration-' + id).before('<span class="error">' + errors[0] + '</span>');
60                     });
61                     $('#registration-form input[type=submit]').removeAttr('disabled');
62                     $('#registration-form img').remove();
63                 }
64             }
65         });
66         
67         $('#login-form').ajaxForm({
68             dataType: 'json',
69             beforeSubmit: function() {
70                 $('#login-form input[type=submit]')
71                     .attr('disabled', 'disabled')
72                     .after('<img src="/media/img/indicator.gif" style="margin-left: 0.5em"/>');
73             },
74             success: function(response) {
75                 if (response.success) {
76                     location.reload(true);
77                 } else {
78                     $('#login-form span.error').remove();
79                     $.each(response.errors, function(id, errors) {
80                         $('#id_login-' + id).before('<span class="error">' + errors[0] + '</span>');
81                     });
82                     $('#login-form input[type=submit]').removeAttr('disabled');
83                     $('#login-form img').remove();
84                 }
85             }
86         });
87         
88         $('#login-register-window').jqm({
89             target: target[0],
90             overlay: 60,
91             trigger: '.login-register-link',
92             onShow: function(hash) {
93                 var offset = $(hash.t).offset();
94                 hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top});
95                 $('div.header', hash.w).css({width: $(hash.t).width()});
96                 hash.w.show();
97             }
98         });
99         
100         $('ul.shelf-list li').hover(function() {
101             $(this).css({background: '#EEE', cursor: 'pointer'});
102         }, function() {
103             $(this).css({background: 'transparent'});
104         }).click(function() {
105             location.href = $('a.visit-shelf', this).attr('href');
106         });
107         
108         $('.delete-shelf').click(function() { 
109             var link = $(this);
110             var shelf_name = $('.visit-shelf', link.parent()).text();
111             if (confirm('Czy na pewno usunąć półkę ' + shelf_name + '?')) {
112                 $.post(link.attr('href'), function(data, textStatus) {
113                     link.parent().remove();
114                 });
115             }
116             return false;
117         });
118         
119         $('#user-shelves-window').jqm({
120             ajax: '@href',
121             target: $('#user-shelves-window div.target')[0],
122             overlay: 60,
123             trigger: '#user-shelves-link',
124             onShow: function(hash) {
125                 var offset = $(hash.t).offset();
126                 hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top});
127                 $('div.header', hash.w).css({width: $(hash.t).width()});
128                 hash.w.show();
129             },
130             onLoad: function(hash) { 
131                 $('form', hash.w).ajaxForm({
132                     target: $('#user-shelves-window div.target'),
133                     success: function() { setTimeout(function() { $('#user-shelves-window').jqmHide() }, 1000) }
134                 });
135                 
136                 $('input', hash.w).labelify({labelledClass: 'blur'});
137                 
138                 $('ul.shelf-list li', hash.w).hover(function() {
139                     $(this).css({background: '#EEE', cursor: 'pointer'});
140                 }, function() {
141                     $(this).css({background: 'transparent'});
142                 }).click(function() {
143                     location.href = $('a.visit-shelf', this).attr('href');
144                 });
145                 
146                 $('.delete-shelf').click(function() {
147                     var link = $(this);
148                     var shelf_name = $('.visit-shelf', link.parent()).text();
149                     console.log(shelf_name);
150                     if (confirm('Czy na pewno usunąć półkę ' + shelf_name + '?')) {
151                         $.post(link.attr('href'), function(data, textStatus) {
152                             link.parent().remove();
153                         });
154                     }
155                     return false;
156                 });
157             }
158         });
159     });
160 })(jQuery)