Extended profile - fix issue with JavaScript not executing in Firefox

This commit is contained in:
Zach Copley 2011-03-15 21:23:34 -07:00
parent b11a2faf54
commit bde85a6685
2 changed files with 22 additions and 31 deletions

View File

@ -1,39 +1,32 @@
var SN_EXTENDED = SN_EXTENDED || {}; var SN_EXTENDED = SN_EXTENDED || {};
SN_EXTENDED.reorder = function(class) { SN_EXTENDED.reorder = function(cls) {
console.log("QQQ Enter reorder");
var divs = $.find('div[class=' + class + ']'); var divs = $('div[class=' + cls + ']');
console.log('divs length = ' + divs.length);
$(divs).find('a').hide();
$(divs).each(function(i, div) { $(divs).each(function(i, div) {
console.log("ROW " + i);
$(div).find('a.remove_row').show(); $(div).find('a.remove_row').show();
SN_EXTENDED.replaceIndex(SN_EXTENDED.rowIndex(div), i); SN_EXTENDED.replaceIndex(SN_EXTENDED.rowIndex(div), i);
}); });
$this = $(divs).last().closest('tr'); var lastDiv = $(divs).last().closest('tr');
$this.addClass('supersizeme'); lastDiv.addClass('supersizeme');
$(divs).last().find('a.add_row').show(); $(divs).last().find('a.add_row').show();
if (divs.length == 1) { if (divs.length == 1) {
$(divs).find('a.remove_row').hide(); $(divs).find('a.remove_row').hide();
} }
}; };
SN_EXTENDED.rowIndex = function(div) { SN_EXTENDED.rowIndex = function(div) {
var idstr = $(div).attr('id'); var idstr = $(div).attr('id');
var id = idstr.match(/\d+/); var id = idstr.match(/\d+/);
console.log("id = " + id);
return id; return id;
}; };
SN_EXTENDED.rowCount = function(class) { SN_EXTENDED.rowCount = function(cls) {
var divs = $.find('div[class=' + class + ']'); var divs = $.find('div[class=' + cls + ']');
return divs.length; return divs.length;
}; };
@ -45,7 +38,6 @@ SN_EXTENDED.replaceIndex = function(elem, oldIndex, newIndex) {
var match = value.match(regexp); var match = value.match(regexp);
if (match !== null) { if (match !== null) {
attrib.value = value.replace("-" + oldIndex, "-" + newIndex); attrib.value = value.replace("-" + oldIndex, "-" + newIndex);
console.log('match: oldIndex = ' + oldIndex + ' newIndex = ' + newIndex + ' name = ' + attrib.name + ' value = ' + attrib.value);
} }
}); });
}); });
@ -54,41 +46,40 @@ SN_EXTENDED.replaceIndex = function(elem, oldIndex, newIndex) {
SN_EXTENDED.resetRow = function(elem) { SN_EXTENDED.resetRow = function(elem) {
$(elem).find('input').attr('value', ''); $(elem).find('input').attr('value', '');
$(elem).find("select option[value='office']").attr("selected", true); $(elem).find("select option[value='office']").attr("selected", true);
} };
SN_EXTENDED.addRow = function() { SN_EXTENDED.addRow = function() {
var div = $(this).closest('div'); var div = $(this).closest('div');
var id = $(div).attr('id'); var id = div.attr('id');
var class = $(div).attr('class'); var cls = div.attr('class');
var index = id.match(/\d+/); var index = id.match(/\d+/);
console.log("Current row = " + index + ', class = ' + class);
var trold = $(this).closest('tr');
var tr = $(trold).removeClass('supersizeme');
var newtr = $(tr).clone();
var newIndex = parseInt(index) + 1; var newIndex = parseInt(index) + 1;
var newtr = $(div).closest('tr').clone();
SN_EXTENDED.replaceIndex(newtr, index, newIndex); SN_EXTENDED.replaceIndex(newtr, index, newIndex);
$(newtr).removeClass('supersizeme');
SN_EXTENDED.resetRow(newtr); SN_EXTENDED.resetRow(newtr);
$(tr).after(newtr); $(div).closest('tr').after(newtr);
SN_EXTENDED.reorder(class); SN_EXTENDED.reorder(cls);
}; };
SN_EXTENDED.removeRow = function() { SN_EXTENDED.removeRow = function() {
var div = $(this).closest('div'); var div = $(this).closest('div');
var id = $(div).attr('id'); var id = $(div).attr('id');
var class = $(div).attr('class'); var cls = $(div).attr('class');
cnt = SN_EXTENDED.rowCount(class); var cnt = SN_EXTENDED.rowCount(cls);
console.debug("removeRow - cnt = " + cnt);
if (cnt > 1) { if (cnt > 1) {
var target = $(this).closest('tr'); var target = $(this).closest('tr');
target.remove(); target.remove();
SN_EXTENDED.reorder(class); SN_EXTENDED.reorder(cls);
} }
}; };
$(document).ready( $(document).ready(function() {
function() { $("input#extprofile-manager").autocomplete({
source: 'finduser',
minLength: 2 });
var multifields = ["phone-item", "experience-item", "education-item", "im-item"]; var multifields = ["phone-item", "experience-item", "education-item", "im-item"];