bump librarian version
[wolnelektury.git] / wolnelektury / static / js / dialogs.js
1 (function($) {
2     $(function() {
3
4         // create containers for all ajaxable form links
5         $('.ajaxable').each(function() {
6             var $window = $("#ajaxable-window").clone();
7             $window.attr("id", this.id + "-window");
8             $('body').append($window);
9
10             var trigger = '#' + this.id;
11
12             var href = $(this).attr('href');
13             if (href.search('\\?') != -1)
14                 href += '&ajax=1';
15             else href += '?ajax=1';
16
17             $window.jqm({
18                 ajax: href,
19                 ajaxText: '<p><img src="' + STATIC_URL + 'img/indicator.gif" alt="*"/> ' + gettext("Loading") + '</p>',
20                 target: $('.target', $window)[0],
21                 overlay: 60,
22                 trigger: trigger,
23                 onShow: function(hash) {
24                     var offset = $(hash.t).offset();
25                     hash.w.css({position: 'absolute', left: offset.left - hash.w.width() + $(hash.t).width(), top: offset.top});
26                     $('.header', hash.w).css({width: $(hash.t).width()});
27                     hash.w.show();
28                 },
29                 onLoad: function(hash) {
30                     $('form', hash.w).each(function() {this.action += '?ajax=1';});
31                     $('form', hash.w).ajaxForm({
32                         dataType: 'json',
33                         target: $('.target', $window),
34                         success: function(response) {
35                             if (response.success) {
36                                 $('.target', $window).text(response.message);
37                                 setTimeout(function() { $window.jqmHide() }, 1000)
38                             }
39                             else {
40                                 $('.error', $window).remove();
41                                 $.each(response.errors, function(id, errors) {
42                                     $('#id_' + id, $window).before('<span class="error">' + errors[0] + '</span>');
43                                 });
44                                 $('input[type=submit]', $window).removeAttr('disabled');
45                                 return false;
46                             }
47                         }
48                     });
49                 }
50             });
51         });
52
53
54     });
55 })(jQuery)
56