]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/DomainWhitelist/js/whitelistinvite.js
01e493fa6aaec12c622d4a42979e4dfe922d31d8
[quix0rs-gnu-social.git] / plugins / DomainWhitelist / js / whitelistinvite.js
1 // XXX: Should I do crazy SN.X.Y.Z.A namespace instead?
2 var SN_WHITELIST = SN_WHITELIST || {};
3
4 SN_WHITELIST.updateButtons = function() {
5    $("ul > li > a.remove_row").show();
6    $("ul > li > a.add_row").hide();
7
8     var lis = $('ul > li > input[name^="username[]"]');
9     if (lis.length === 1) {
10         $("ul > li > a.remove_row").hide();
11     } else {
12         $("ul > li > a.remove_row:first").show();
13     }
14     $("ul > li > a.add_row:last").show();
15 };
16
17 SN_WHITELIST.resetRow = function(row) {
18     $("input", row).val('');
19     // Make sure the default domain is the first selection
20     $("select option:first", row).val();
21     $("a.remove_row", row).show();
22 };
23
24 SN_WHITELIST.addRow = function() {
25     var row = $(this).closest("li");
26     var newRow = row.clone();
27     $(row).find('a.add_row').hide();
28     SN_WHITELIST.resetRow(newRow);
29         $(newRow).insertAfter(row).show("blind", "fast", function() {
30             SN_WHITELIST.updateButtons();
31         });
32 };
33
34 SN_WHITELIST.removeRow = function() {
35     var that = this;
36
37     $("#confirm-dialog").dialog({
38         buttons : {
39             "Confirm" : function() {
40                 $(this).dialog("close");
41                 $(that).closest("li").hide("blind", "fast", function() {
42                     $(this).remove();
43                     SN_WHITELIST.updateButtons();
44                 });
45             },
46             "Cancel" : function() {
47                 $(this).dialog("close");
48             }
49         }
50     });
51
52     if ($(this).closest('li').find(':input[name^=username]').val()) {
53         $("#confirm-dialog").dialog("open");
54     } else {
55         $(that).closest("li").hide("blind", "fast", function() {
56             $(this).remove();
57             SN_WHITELIST.updateButtons();
58         });
59     }
60 };
61
62 $(document).ready(function() {
63     $("#confirm-dialog").dialog({
64         autoOpen: false,
65         modal: true
66     });
67
68     $('.add_row').live('click', SN_WHITELIST.addRow);
69     $('.remove_row').live('click', SN_WHITELIST.removeRow);
70
71     SN_WHITELIST.updateButtons();
72 });