Extracted DOM option creation into function to apply IE workaround
This commit is contained in:
parent
265525c1a7
commit
988323b1d0
@ -11,10 +11,10 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
if (context.data.new_item) {
|
if (context.data.new_item) {
|
||||||
var newItemInfo = context.data.new_item;
|
var newItemInfo = context.data.new_item;
|
||||||
var option = new Option(newItemInfo.label, newItemInfo.url, true, true);
|
var option = makeOption(newItemInfo.label, newItemInfo.url, true, true);
|
||||||
context.select.append(option);
|
context.select.append(option);
|
||||||
|
|
||||||
context.select.append(new Option('-'.repeat(newItemInfo.label.length), '', false, false));
|
context.select.append(makeOption('-'.repeat(newItemInfo.label.length), '', false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < context.data.collection.length; i++) {
|
for (var i = 0; i < context.data.collection.length; i++) {
|
||||||
@ -27,7 +27,7 @@ $(document).ready(function() {
|
|||||||
for (var j = 0; j < obj.items.length; j++) {
|
for (var j = 0; j < obj.items.length; j++) {
|
||||||
var innerObj = obj.items[j];
|
var innerObj = obj.items[j];
|
||||||
if ($.inArray(innerObj[1], context.data.taken_ids) == -1) {
|
if ($.inArray(innerObj[1], context.data.taken_ids) == -1) {
|
||||||
optgroup.append(new Option(innerObj[0], innerObj[1], false, false));
|
optgroup.append(makeOption(innerObj[0], innerObj[1], false, false));
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,8 +36,7 @@ $(document).ready(function() {
|
|||||||
} else {
|
} else {
|
||||||
if ($.inArray(obj[1], context.data.taken_ids) == -1)
|
if ($.inArray(obj[1], context.data.taken_ids) == -1)
|
||||||
{
|
{
|
||||||
var option = new Option("", obj[1], false, false);
|
var option = makeOption(obj[0], obj[1], false, false);
|
||||||
$(option).text(obj[0]);
|
|
||||||
context.select.append(option);
|
context.select.append(option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,11 @@ Object.size = function(obj) {
|
|||||||
if (obj.hasOwnProperty(key)) size++;
|
if (obj.hasOwnProperty(key)) size++;
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Make a DOM option for a select box. This code works around a bug in IE
|
||||||
|
function makeOption(text, value, defaultSelected, selected) {
|
||||||
|
var option = new Option('', value, defaultSelected, selected);
|
||||||
|
$(option).text(text);
|
||||||
|
return option;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user