]> git.openstreetmap.org Git - osqa.git/blob - forum/skins/default/media/js/osqa.user.js
OSQA-357
[osqa.git] / forum / skins / default / media / js / osqa.user.js
1 $().ready(function() {
2     var $dropdown = $('#user-menu-dropdown');
3
4     $('#user-menu').click(function() {
5         $('.dialog').fadeOut('fast', function() {
6             $dialog.remove();
7         });
8         $dropdown.slideToggle('fast', function() {
9             if ($dropdown.is(':visible')) {
10                 $dropdown.one('clickoutside', function() {
11                     $dropdown.slideUp('fast')
12                 });
13             }
14         });
15     });
16
17     $('.confirm').each(function() {
18         var $link = $(this);
19
20         $link.click(function(e) {
21             $dropdown.slideUp('fast');
22
23             show_dialog({
24                 html: messages.confirm,
25                 extra_class: 'confirm',
26                 event: e,
27                 yes_callback: function() {
28                     window.location = $link.attr('href');
29                 },
30                 yes_text: messages.yes,
31                 show_no: true,
32                 no_text: messages.no
33             });
34
35             return false;
36         });
37     });
38
39     $('#award-rep-points').click(function(e) {
40         $dropdown.slideUp('fast');
41
42         var table = '<table><tr><th>' + messages.points + '</th><td><input type="text" id="points-to-award" value="1" /></td></tr>'
43                 + '<tr><th>' + messages.message + '</th><td><textarea id="award-message"></textarea></td></tr></table>';
44
45         show_dialog({
46             html: table,
47             extra_class: 'award-rep-points',
48             event: e,
49             yes_callback: function($dialog) {
50                 var $points_input = $('#points-to-award');
51                 var _points = parseInt($points_input.val());
52
53                 if (!isNaN(_points)) {
54                     $dialog.fadeOut('fast');
55                     var _message = $('#award-message').val();
56                     $.post($('#award-rep-points').attr('href'), {points: _points, message: _message}, function(data) {
57                         if (data.success) {
58                             $('#user-reputation').css('background', 'yellow');
59                             $('#user-reputation').html(data.reputation);
60
61                             $('#user-reputation').animate({ backgroundColor: "transparent" }, 1000);
62
63                         }
64                     }, 'json')
65                 }
66             },
67             show_no: true
68         });
69
70         return false;
71     });
72
73 });