Further i18n.
[wolnelektury.git] / wolnelektury / static / js / catalogue.js
1 alert(LANGUAGE_CODE);
2 var LOCALE_TEXTS = {
3         "pl": {
4                 "DELETE_SHELF": "Czy na pewno usunąć półkę",
5                 "HIDE_DESCRIPTION": "Zwiń opis",
6                 "EXPAND DESCRIPTION": "Rozwiń opis",
7                 "LOADING": "Ładowanie",                
8         },
9         "fr": {
10                 "DELETE_SHELF": "Translate me!",
11                 "HIDE_DESCRIPTION": "Translate me!",
12                 "EXPAND DESCRIPTION": "Translate me!",
13                 "LOADING": "Translate me!",                             
14         },
15         "ru": {
16                 "DELETE_SHELF": "Translate me!",
17                 "HIDE_DESCRIPTION": "Translate me!",
18                 "EXPAND DESCRIPTION": "Translate me!",
19                 "LOADING": "Translate me!",                             
20         },
21         "en": {
22                 "DELETE_SHELF": "Translate me!",
23                 "HIDE_DESCRIPTION": "Translate me!",
24                 "EXPAND DESCRIPTION": "Translate me!",
25                 "LOADING": "Translate me!",             
26         }, 
27         "ru": {
28                 "DELETE_SHELF": "Translate me!",
29                 "HIDE_DESCRIPTION": "Translate me!",
30                 "EXPAND DESCRIPTION": "Translate me!",
31                 "LOADING": "Translate me!",             
32         },
33         "es": {
34                 "DELETE_SHELF": "Translate me!",
35                 "HIDE_DESCRIPTION": "Translate me!",
36                 "EXPAND DESCRIPTION": "Translate me!",
37                 "LOADING": "Translate me!",                             
38         },
39         "lt":{
40                 "DELETE_SHELF": "Translate me!",
41                 "HIDE_DESCRIPTION": "Translate me!",
42                 "EXPAND DESCRIPTION": "Translate me!",
43                 "LOADING": "Translate me!",                             
44         }
45 }
46
47 alert(LOCALE_TEXTS[LANGUAGE_CODE]['DELETE_SHELF']);
48 var BANNER_TEXTS = [
49     'Przekaż 1% żeby ukryć ten baner.',
50     'Jak dobrze wydać 1% swojego podatku? <strong>Poradnik dla opornych</strong>.',
51     'Wiadomość systemowa: wystąpił błąd brak funduszy. Wykonaj procedurę 1%.',
52     '<strong>FREE!</strong> Wygraj darmowe lektury!',
53     'Confidential business offer. Not scam! 1% for you.',
54     'Biblioteka Wolne Lektury wymaga aktualizacji. Kliknij dalej.',
55     '1000 lektur. <strong>1 procent</strong>.',
56     '1% dla biblioteki lektur szkolnych. 1% dla Twojej biblioteki.',
57     '1% na lektury szkolne.',
58     '1% dla wolności lektur szkolnych.',
59     'Podaruj Jeden Procent na rzecz szkolnej biblioteki internetowej.',
60     '1% podatku dla biblioteki szkolnej Wolne Lektury.',
61     '1% na rzecz darmowego dostępu do szkolnych lektur.',
62     'Żeby czytać teksty a nie skany. Przekaż 1%.',
63     'Czytaj teksty a nie skany. Przekaż 1%',
64     'Motyw artysty w literaturze - 47 cytatów. Pomóż znaleźć następne.',
65     'Twój 1% uwolni więcej lektur.',
66     'Ponad 400 motywów, blisko 10 000 000 cytatów. Pomóż znaleźć następne. Przekaż swój 1%.',
67     'Twój 1% uwolni lektury.',
68     'Rozlicz swój PIT z Wolnymi Lekturami. Skorzystaj z darmowego programu do rozliczania podatków.',
69     'Lektury 2010: Pan Tadeusz, Trylogia.',
70     'Pan Tadeusz też chce być w Internecie! Przekaż 1% swojego podatku.',
71     'Pomóż uwolnić 286 utworów z listy lektur szkolnych. Przekaż swój 1% na Wolne Lektury.'
72 ]
73
74
75 function changeBannerText() {
76     var index = Math.floor(Math.random() * BANNER_TEXTS.length);
77     if (BANNER_TEXTS[index] == $('#onepercent-text').html()) {
78         // try again
79         changeBannerText();
80     } else {
81         $('#onepercent-text').fadeOut('slow', function() {
82             $(this).html(BANNER_TEXTS[index]);
83             $(this).fadeIn('slow');
84         });
85         
86         setTimeout(changeBannerText, 30 * 1000);
87     }
88 }
89
90 function autocomplete_result_handler(event, item) {
91     $(event.target).closest('form').submit();
92 }
93 function serverTime() { 
94     var time = null; 
95     $.ajax({url: '/katalog/zegar/', 
96         async: false, dataType: 'text', 
97         success: function(text) { 
98             time = new Date(text);
99         }, error: function(http, message, exc) {
100             time = new Date(); 
101     }}); 
102     return time; 
103 }
104
105 (function($) {
106     $(function() {
107         $('form input').labelify({labelledClass: 'blur'});
108         
109         target = $('#login-register-window div.target');
110         
111         $('#show-registration-form').click(function() {
112             $('#login-form').hide();
113             $('#registration-form').show();
114         });
115         
116         $('#show-login-form').click(function() {
117             $('#registration-form').hide();
118             $('#login-form').show();
119         });
120         
121         // Fragments
122         $('.fragment-text').each(function() {
123             if ($(this).prev().filter('.fragment-short-text').length) {
124                 $(this).hover(
125                     function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
126                     function() { $(this).css({background: '#FFF'}); }
127                 ).click(function() {
128                     $(this).fadeOut(function() {
129                         $(this).prev().fadeIn()
130                     });
131                 })
132             }
133         });
134         
135         $('.fragment-short-text').click(function() {
136             $(this).fadeOut(function() { $(this).next().fadeIn() });
137         }).hover(
138             function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
139             function() { $(this).css({background: '#FFF'}); }
140         );
141         
142         $('.show-all-tags').click(function() {
143             $(this).parent().parent().fadeOut(function() { 
144                 $(this).next().fadeIn();
145             });
146             return false;
147         });
148         
149         $('.hide-all-tags').click(function() {
150            $(this).parent().parent().fadeOut(function() {
151                $(this).prev().fadeIn();
152            });
153            return false; 
154         });
155         
156         $('#registration-form').ajaxForm({
157             dataType: 'json',
158             beforeSubmit: function() {
159                 $('#registration-form input[type=submit]')
160                     .attr('disabled', 'disabled')
161                     .after('<img src="/static/img/indicator.gif" style="margin-left: 0.5em"/>');
162             },
163             success: function(response) {
164                 if (response.success) {
165                     location.reload(true);
166                 } else {
167                     $('#registration-form span.error').remove();
168                     $.each(response.errors, function(id, errors) {
169                         $('#id_registration-' + id).before('<span class="error">' + errors[0] + '</span>');
170                     });
171                     $('#registration-form input[type=submit]').removeAttr('disabled');
172                     $('#registration-form img').remove();
173                 }
174             }
175         });
176         
177         $('#login-form').ajaxForm({
178             dataType: 'json',
179             beforeSubmit: function() {
180                 $('#login-form input[type=submit]')
181                     .attr('disabled', 'disabled')
182                     .after('<img src="/static/img/indicator.gif" style="margin-left: 0.5em"/>');
183             },
184             success: function(response) {
185                 if (response.success) {
186                     location.reload(true);
187                 } else {
188                     $('#login-form span.error').remove();
189                     $.each(response.errors, function(id, errors) {
190                         $('#id_login-' + id).before('<span class="error">' + errors[0] + '</span>');
191                     });
192                     $('#login-form input[type=submit]').removeAttr('disabled');
193                     $('#login-form img').remove();
194                 }
195             }
196         });
197         
198         $('#login-register-window').jqm({
199             target: target[0],
200             overlay: 60,
201             trigger: '.login-register-link',
202             onShow: function(hash) {
203                 var offset = $(hash.t).offset();
204                 hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top});
205                 $('div.header', hash.w).css({width: $(hash.t).width()});
206                 hash.w.show();
207             }
208         });
209         
210         $('ul.shelf-list li').hover(function() {
211             $(this).css({background: '#EEE', cursor: 'pointer'});
212         }, function() {
213             $(this).css({background: 'transparent'});
214         }).click(function() {
215             location.href = $('a.visit-shelf', this).attr('href');
216         });
217         
218         $('.delete-shelf').click(function() { 
219             var link = $(this);
220             var shelf_name = $('.visit-shelf', link.parent()).text();
221             if (confirm(LOCALE_TEXTS[LANGUAGE_CODE]['DELETE_SHELF']+ ' '+ shelf_name + '?')) {
222                 $.post(link.attr('href'), function(data, textStatus) {
223                     link.parent().remove();
224                 });
225             }
226             return false;
227         });
228         
229         $('#user-shelves-window').jqm({
230             ajax: '@href',
231             target: $('#user-shelves-window div.target')[0],
232             overlay: 60,
233             trigger: '#user-shelves-link',
234             onShow: function(hash) {
235                 var offset = $(hash.t).offset();
236                 hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top});
237                 $('div.header', hash.w).css({width: $(hash.t).width()});
238                 hash.w.show();
239             },
240             onLoad: function(hash) { 
241                 $('form', hash.w).ajaxForm({
242                     target: $('#user-shelves-window div.target'),
243                     success: function() { setTimeout(function() { $('#user-shelves-window').jqmHide() }, 1000) }
244                 });
245                 
246                 $('input', hash.w).labelify({labelledClass: 'blur'});
247                 
248                 $('ul.shelf-list li', hash.w).hover(function() {
249                     $(this).css({background: '#EEE', cursor: 'pointer'});
250                 }, function() {
251                     $(this).css({background: 'transparent'});
252                 }).click(function() {
253                     location.href = $('a.visit-shelf', this).attr('href');
254                 });
255                 
256                 $('.delete-shelf').click(function() {
257                     var link = $(this);
258                     var shelf_name = $('.visit-shelf', link.parent()).text();
259                     if (confirm(LOCALE_TEXTS[LANGUAGE_CODE]['DELETE_SHELF'] + ' ' + shelf_name + '?')) {
260                         $.post(link.attr('href'), function(data, textStatus) {
261                             link.parent().remove();
262                         });
263                     }
264                     return false;
265                 });
266             }
267         });
268     
269         $('#books-list .book').hover(
270             function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
271             function() { $(this).css({background: '#FFF'}); }
272         ).click(function() {
273             location.href = $('h2 a', this).attr('href');
274         });
275     
276         $('#toggle-description').hover(
277             function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
278             function() { $(this).css({background: '#EEE'}); }
279         ).click(function() {
280             if ($('#description').hasClass('hidden')) {
281                 $('#description').slideDown('fast').removeClass('hidden');
282                 $.cookie('description-state', 'opened', {path: '/', expires: 30});
283                 $('p', this).html(LOCALE_TEXTS[LANGUAGE_CODE]['HIDE_DESCRIPTION'] + ' ▲');
284             } else {
285                 $('#description').slideUp('fast').addClass('hidden');
286                 $.cookie('description-state', 'closed', {path: '/', expires: 30});
287                 $('p', this).html(LOCALE_TEXTS[LANGUAGE_CODE]['HIDE_DESCRIPTION'] + ' ▼');
288             }
289         });
290     
291         var target = $('#set-window div.target');
292     
293         $('#set-window').jqm({
294             ajax: '@href', 
295             target: target[0],
296             overlay: 60,
297             trigger: 'a.jqm-trigger', 
298             onShow: function(hash) { 
299                 var offset = $(hash.t).offset();
300                 target.html('<p><img src="/static/img/indicator.gif" />'+LOCALE_TEXTS[LANGUAGE_CODE]['DELETE_SHELF']+'</p>');
301                 hash.w.css({position: 'absolute', left: offset.left, top: offset.top}).show() },
302             onLoad: function(hash) { 
303                 $('form', hash.w).ajaxForm({
304                     target: target,
305                     success: function() { setTimeout(function() { $('#set-window').jqmHide() }, 1000) }
306                 });
307             }
308         });
309         
310         $('a.remove-from-shelf').click(function(event) {
311             event.preventDefault();
312             link = $(this);
313             $.post(link.attr('href'), function(data, textStatus) {
314                 link.parent().remove();
315             });
316         });
317         
318         if ($.cookie('description-state') == 'closed') {
319             $('#description').hide().addClass('hidden');
320             $('#toggle-description p').html(LOCALE_TEXTS[LANGUAGE_CODE]['EXPAND_SHELF']+' ▼');
321         }
322                 
323         $('#user-info').show();
324         changeBannerText();
325         $('#onepercent-banner').show();
326         
327         var formatsDownloaded = false;
328         $('#download-shelf').click(function() {
329             $('#download-shelf-menu').slideDown('fast');
330             
331             if (!formatsDownloaded) {
332                 // Get info about the formats
333                 formatsDownloaded = true;
334                 $.ajax({
335                     url: $('#download-formats-form').attr('data-formats-feed'),
336                     type: 'GET',
337                     dataType: 'json',
338                     complete: function() {
339                         $('#download-formats-form-submit').attr('disabled', null);
340                         $('#download-formats-form-submit-li img').remove();
341                         $('#updating-formats').fadeOut('fast', function() {
342                             $('#formats-updated').fadeIn('fast');
343                         });
344                     },
345                     success: function(data) {
346                         $('#download-formats-form li').each(function() {
347                             var item = $(this);
348                             if (!!item.attr('data-format') && !data[item.attr('data-format')]) {
349                                 item.fadeOut('fast', function() {
350                                     item.remove();
351                                 });
352                             }
353                         });
354                     }
355                 });
356             }
357             return false;
358         });
359         
360         $('#download-formats-form-cancel').click(function() {
361             $('#download-shelf-menu').slideUp('fast');
362             return false;
363         });
364     });
365 })(jQuery)