1 var SN_EXTENDED = SN_EXTENDED || {};
3 SN_EXTENDED.reorder = function(cls) {
5 var divs = $('div[class=' + cls + ']');
7 $(divs).each(function(i, div) {
8 $(div).find('a.remove_row').show();
9 SN_EXTENDED.replaceIndex(SN_EXTENDED.rowIndex(div), i);
12 var lastDiv = $(divs).last().closest('tr');
13 lastDiv.addClass('supersizeme');
15 $(divs).last().find('a.add_row').show();
17 if (divs.length == 1) {
18 $(divs).find('a.remove_row').hide();
22 SN_EXTENDED.rowIndex = function(div) {
23 var idstr = $(div).attr('id');
24 var id = idstr.match(/\d+/);
28 SN_EXTENDED.rowCount = function(cls) {
29 var divs = $.find('div[class=' + cls + ']');
33 SN_EXTENDED.replaceIndex = function(elem, oldIndex, newIndex) {
34 $(elem).find('*').each(function() {
35 $.each(this.attributes, function(i, attrib) {
36 var regexp = /extprofile-.*-\d.*/;
37 var value = attrib.value;
38 var match = value.match(regexp);
40 attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
46 SN_EXTENDED.resetRow = function(elem) {
47 $(elem).find('input').attr('value', '');
48 $(elem).find("select option[value='office']").attr("selected", true);
51 SN_EXTENDED.addRow = function() {
52 var div = $(this).closest('div');
53 var id = div.attr('id');
54 var cls = div.attr('class');
55 var index = id.match(/\d+/);
56 var newIndex = parseInt(index) + 1;
57 var newtr = $(div).closest('tr').clone();
58 SN_EXTENDED.replaceIndex(newtr, index, newIndex);
59 $(newtr).removeClass('supersizeme');
60 SN_EXTENDED.resetRow(newtr);
61 $(div).closest('tr').after(newtr);
62 SN_EXTENDED.reorder(cls);
65 SN_EXTENDED.removeRow = function() {
66 var div = $(this).closest('div');
67 var id = $(div).attr('id');
68 var cls = $(div).attr('class');
70 var cnt = SN_EXTENDED.rowCount(cls);
72 var target = $(this).closest('tr');
74 SN_EXTENDED.reorder(cls);
78 $(document).ready(function() {
80 $("input#extprofile-manager").autocomplete({
84 var multifields = ["phone-item", "experience-item", "education-item", "im-item"];
86 for (f in multifields) {
87 SN_EXTENDED.reorder(multifields[f]);
90 $("input#extprofile-manager").autocomplete({
94 $('.add_row').live('click', SN_EXTENDED.addRow);
95 $('.remove_row').live('click', SN_EXTENDED.removeRow);