]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ExtendedProfile/js/profiledetail.js
Changing js .live calls to .on for jquery 2.x
[quix0rs-gnu-social.git] / plugins / ExtendedProfile / js / profiledetail.js
1 var SN_EXTENDED = SN_EXTENDED || {};
2
3 SN_EXTENDED.reorder = function (cls) {
4
5     var divs = $('div[class=' + cls + ']');
6
7     $(divs).each(function (i, div) {
8         $(div).find('a.add_row').hide();
9         $(div).find('a.remove_row').show();
10         SN_EXTENDED.replaceIndex(SN_EXTENDED.rowIndex(div), i);
11     });
12
13     var lastDiv = $(divs).last().closest('tr');
14     lastDiv.addClass('supersizeme');
15
16     $(divs).last().find('a.add_row').show();
17
18     if (divs.length == 1) {
19         $(divs).find('a.remove_row').fadeOut("slow");
20     }
21 };
22
23 SN_EXTENDED.rowIndex = function (div) {
24     var idstr = $(div).attr('id');
25     var id = idstr.match(/\d+/);
26     return id;
27 };
28
29 SN_EXTENDED.rowCount = function (cls) {
30     var divs = $.find('div[class=' + cls + ']');
31     return divs.length;
32 };
33
34 SN_EXTENDED.replaceIndex = function (elem, oldIndex, newIndex) {
35     $(elem).find('*').each(function () {
36         $.each(this.attributes, function (i, attrib) {
37             var regexp = /extprofile-.*-\d.*/;
38             var value = attrib.value;
39             var match = value.match(regexp);
40             if (match !== null) {
41                 attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
42             }
43         });
44     });
45 }
46
47 SN_EXTENDED.resetRow = function (elem) {
48     $(elem).find('input, textarea').attr('value', '');
49     $(elem).find('input').removeAttr('disabled');
50     $(elem).find("select option[value='office']").attr("selected", true);
51     $(elem).find("input:checkbox").attr('checked', false);
52     $(elem).find("input[name$=-start], input[name$=-end]").each(function () {
53         $(this).removeClass('hasDatepicker');
54         $(this).datepicker({ dateFormat: 'd M yy' });
55     });
56 };
57
58 SN_EXTENDED.addRow = function () {
59     var div = $(this).closest('div');
60     var id = div.attr('id');
61     var cls = div.attr('class');
62     var index = id.match(/\d+/);
63     var newIndex = parseInt(index) + 1;
64     var newtr = $(div).closest('tr').removeClass('supersizeme').clone();
65     SN_EXTENDED.replaceIndex(newtr, index, newIndex);
66     SN_EXTENDED.resetRow(newtr);
67     $(div).closest('tr').after(newtr);
68     SN_EXTENDED.reorder(cls);
69 };
70
71 SN_EXTENDED.removeRow = function () {
72
73     var div = $(this).closest('div');
74     var id = $(div).attr('id');
75     var cls = $(div).attr('class');
76     var that = this;
77
78     $("#confirm-dialog").dialog({
79         buttons : {
80             "Confirm" : function () {
81                 $(this).dialog("close");
82                 var target = $(that).closest('tr');
83                 target.fadeOut("slow", function () {
84                     $(target).remove();
85                     SN_EXTENDED.reorder(cls);
86                 });
87             },
88             "Cancel" : function () {
89                 $(this).dialog("close");
90             }
91         }
92     });
93
94     var cnt = SN_EXTENDED.rowCount(cls);
95
96     if (cnt > 1) {
97         $("#confirm-dialog").dialog("open");
98     }
99 };
100
101 $(document).ready(function () {
102
103     $("#confirm-dialog").dialog({
104         autoOpen: false,
105         modal: true
106     });
107
108     $("input#extprofile-manager").autocomplete({
109         source: 'finduser',
110         minLength: 2 });
111
112     $("input[name$=-start], input[name$=-end], #extprofile-birthday").datepicker({ dateFormat: 'd M yy' });
113
114     var multifields = ["phone-item", "experience-item", "education-item", "im-item", 'website-item'];
115
116     for (f in multifields) {
117         SN_EXTENDED.reorder(multifields[f]);
118     }
119
120     $("input#extprofile-manager").autocomplete({
121         source: 'finduser',
122         minLength: 2 });
123
124     $(document).on('click', '.add_row', SN_EXTENDED.addRow);
125     $(document).on('click', '.remove_row', SN_EXTENDED.removeRow);
126
127     $('input:checkbox[name$=current]').each(function () {
128         var input = $(this).parent().siblings('input[id$=-end]');
129         if ($(this).is(':checked')) {
130             $(input).attr('disabled', 'true');
131         }
132     });
133
134     $(document).on('click', 'input:checkbox[name$=current]', function ()  {
135         var input = $(this).parent().siblings('input[id$=-end]');
136         if ($(this).is(':checked')) {
137             $(input).val('');
138             $(input).attr('disabled', 'true');
139         } else {
140             $(input).removeAttr('disabled');
141         }
142     });
143
144 });