Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
chore(select): remove inherit, replace with expression locals
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Feb 22, 2012
1 parent 761b2ed commit 6216dc0
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/widget/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ var selectDirective = ['$formFactory', '$compile', '$parse',
widget.$apply(function() {
var optionGroup,
collection = valuesFn(modelScope) || [],
tempScope = inherit(modelScope),
locals = {},
key, value, optionElement, index, groupIndex, length, groupLength;

if (multiple) {
Expand All @@ -257,9 +257,9 @@ var selectDirective = ['$formFactory', '$compile', '$parse',
for(index = 1, length = optionGroup.length; index < length; index++) {
if ((optionElement = optionGroup[index].element)[0].selected) {
key = optionElement.val();
if (keyName) tempScope[keyName] = key;
tempScope[valueName] = collection[key];
value.push(valueFn(tempScope));
if (keyName) locals[keyName] = key;
locals[valueName] = collection[key];
value.push(valueFn(modelScope, locals));
}
}
}
Expand All @@ -270,9 +270,9 @@ var selectDirective = ['$formFactory', '$compile', '$parse',
} else if (key == ''){
value = null;
} else {
tempScope[valueName] = collection[key];
if (keyName) tempScope[keyName] = key;
value = valueFn(tempScope);
locals[valueName] = collection[key];
if (keyName) locals[keyName] = key;
value = valueFn(modelScope, locals);
}
}
if (isDefined(value) && modelScope.$viewVal !== value) {
Expand All @@ -296,7 +296,7 @@ var selectDirective = ['$formFactory', '$compile', '$parse',
keys = keyName ? sortedKeys(values) : values,
groupLength, length,
groupIndex, index,
optionScope = inherit(modelScope),
locals = {},
selected,
selectedSet = false, // nothing is selected yet
lastElement,
Expand All @@ -312,21 +312,21 @@ var selectDirective = ['$formFactory', '$compile', '$parse',

// We now build up the list of options we need (we merge later)
for (index = 0; length = keys.length, index < length; index++) {
optionScope[valueName] = values[keyName ? optionScope[keyName]=keys[index]:index];
optionGroupName = groupByFn(optionScope) || '';
locals[valueName] = values[keyName ? locals[keyName]=keys[index]:index];
optionGroupName = groupByFn(modelScope, locals) || '';
if (!(optionGroup = optionGroups[optionGroupName])) {
optionGroup = optionGroups[optionGroupName] = [];
optionGroupNames.push(optionGroupName);
}
if (multiple) {
selected = selectedSet.remove(valueFn(optionScope)) != undefined;
selected = selectedSet.remove(valueFn(modelScope, locals)) != undefined;
} else {
selected = modelValue === valueFn(optionScope);
selected = modelValue === valueFn(modelScope, locals);
selectedSet = selectedSet || selected; // see if at least one item is selected
}
optionGroup.push({
id: keyName ? keys[index] : index, // either the index into array or key from object
label: displayFn(optionScope) || '', // what will be seen by the user
label: displayFn(modelScope, locals) || '', // what will be seen by the user
selected: selected // determine if we should be selected
});
}
Expand Down

0 comments on commit 6216dc0

Please sign in to comment.