look changes
[wolnelektury.git] / wolnelektury / static / js / base.js
1 (function($) {
2     $(function() {
3         $.fn.toggle_slide = function(p) {
4             cont = $(this);
5             short_el = p['short_el'] || $(':first-child', this);
6             long_el = p['long_el'] || short_el.next();
7             button = p['button'];
8             short_text = p['short_text'],
9             long_text = p['long_text'];
10
11             var toggle_fun = function(cont, short_el, long_el, button, short_text, long_text) {
12                 var toggle = function() {
13                     if (cont.hasClass('short')) {
14                         cont.animate({"height": long_el.attr("cont_h")+'px'}, {duration: "fast" }).removeClass('short');
15                         short_el.hide();
16                         long_el.show();
17                         if (button && long_text) button.html(long_text);
18                     } else {
19                         cont.animate({"height": short_el.attr("cont_h")+'px'}, {duration: "fast" }).addClass('short');
20                         long_el.hide();
21                         short_el.show();
22                         if (button && short_text) button.html(short_text);
23                     }
24                     return false;
25                 }
26                 return toggle;
27             }
28             if (long_el.html().length <= short_el.html().length)
29                 return;
30
31             // ensure long element shown first
32             long_el.show();short_el.hide();
33             long_el.attr("cont_h", $(this).height()).hide();
34             short_el.show().attr("cont_h", $(this).height());
35             $(this).addClass('short');
36
37             if (button && short_text) button.html(short_text);
38             if (button) button.hover(
39                 function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
40                 function() { $(this).css({background: '#EEE'}); }
41             ).click(toggle_fun(cont, short_el, long_el, button, short_text, long_text));
42             short_el.hover(
43                 function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
44                 function() { $(this).css({background: '#FFF'}); }
45             ).click(toggle_fun(cont, short_el, long_el, button, short_text, long_text));
46             long_el.hover(
47                 function() { $(this).css({background: '#F3F3F3', cursor: 'pointer'}); },
48                 function() { $(this).css({background: '#FFF'}); }
49             ).click(toggle_fun(cont, short_el, long_el, button, short_text, long_text));
50         };
51
52
53         // Fragments
54         $('.fragment-short-text').each(function() {
55             var fragment = $(this).closest('.fragment');
56             fragment.toggle_slide({
57                 short_el: $(this),
58                 long_el: fragment.find('.fragment-text')
59             })
60         });
61
62
63
64
65
66
67 $('#themes-list-toggle').click(function(event) {
68     event.preventDefault();
69     $('#themes-list').toggle('slow');
70 });
71
72
73 $('.open-player').click(function(event) {
74     event.preventDefault();
75     window.open($(this).attr('href'),
76         'player',
77         'width=420, height=500'
78         );
79 });
80
81
82         $('.book-list-index').click(function(){
83             $('.book-list-show-index').hide('slow');
84             if($(this).parent().next('ul:not(:hidden)').length == 0){
85                 $(this).parent().next('ul').toggle('slow');
86             }
87             return false;
88         });
89
90
91     });
92 })(jQuery)
93