some fixes from ui checks
[wolnelektury.git] / apps / wolnelektury_core / 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.click(toggle_fun(cont, short_el, long_el, button, short_text, long_text));
39         };
40
41
42         // Fragments
43         $('.fragment-with-short').each(function() {
44             $(this).toggle_slide({
45                 short_el: $('.fragment-short-text', this),
46                 long_el: $('.fragment-long-text', this),
47                 button: $('.toggle', this)
48             })
49         });
50         $('#description').each(function() {
51             $(this).toggle_slide({
52                 short_el: $('#description-short', this),
53                 long_el: $('#description-long', this),
54                 button: $(this)
55             })
56         });
57
58
59
60                 (function() {
61                         var $current = null;
62             var menu_loaded = false;
63                         $('.hidden-box-wrapper').each(function() {
64                                 var $hidden = $('.hidden-box', this);
65                                 $('.hidden-box-trigger', this).click(function(event) {
66                                         event.preventDefault();
67                                         if ($current == $hidden) {
68                                                 $current = null;
69                                                 $hidden.hide('fast');
70                                         } else {
71                                                 $current && $current.hide('fast');
72                                                 $hidden.show('fast');
73                                                 $current = $hidden;
74                         if ($(this).hasClass('load-menu') && !menu_loaded) {
75                             $.ajax({
76                                 url: '/katalog/',
77                                 dataType: "json",
78                             }).done(function(data) {
79                                 $.each(data, function(index, value) {
80                                     $('#menu-' + index).html(value);
81                                 });
82                                 menu_loaded = true;
83                             });
84                         }
85                                         } 
86                                 });
87                         });
88                         $('body').click(function(e) {
89                                 if ($current == null) return;
90                                 var p = $(e.target);
91                                 while (p.length) {
92                                         if (p == $current)
93                                                 return;
94                                         if (p.hasClass('hidden-box-trigger'))
95                                                 return;
96                                         p = p.parent();
97                                 }
98                                 $current.hide('fast');
99                                 $current = null;
100                         });
101                 })();
102                 
103
104
105
106 $('#themes-list-toggle').click(function(event) {
107     event.preventDefault();
108     $('#themes-list').toggle('slow');
109 });
110
111
112         $('.book-list-index').click(function(){
113             $('.book-list-show-index').hide('slow');
114             if($(this).parent().next('ul:not(:hidden)').length == 0){
115                 $(this).parent().next('ul').toggle('slow');
116             }
117             return false;
118         });
119
120         $('.hoverclick').click(function() {$(this).closest('.hoverget').toggleClass('hover');});
121
122         $(function(){
123             $("#search").search();});
124
125     });
126 })(jQuery);
127