mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 05:29:20 +03:00
Clone 3.5.1 from github
This commit is contained in:
parent
5d281486d0
commit
091c4ec811
65 changed files with 6957 additions and 7 deletions
78
vendors/knockout/src/binding/selectExtensions.js
vendored
Normal file
78
vendors/knockout/src/binding/selectExtensions.js
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
(function () {
|
||||
var hasDomDataExpandoProperty = '__ko__hasDomDataOptionValue__';
|
||||
|
||||
// Normally, SELECT elements and their OPTIONs can only take value of type 'string' (because the values
|
||||
// are stored on DOM attributes). ko.selectExtensions provides a way for SELECTs/OPTIONs to have values
|
||||
// that are arbitrary objects. This is very convenient when implementing things like cascading dropdowns.
|
||||
ko.selectExtensions = {
|
||||
readValue : function(element) {
|
||||
switch (ko.utils.tagNameLower(element)) {
|
||||
case 'option':
|
||||
if (element[hasDomDataExpandoProperty] === true)
|
||||
return ko.utils.domData.get(element, ko.bindingHandlers.options.optionValueDomDataKey);
|
||||
return ko.utils.ieVersion <= 7
|
||||
? (element.getAttributeNode('value') && element.getAttributeNode('value').specified ? element.value : element.text)
|
||||
: element.value;
|
||||
case 'select':
|
||||
return element.selectedIndex >= 0 ? ko.selectExtensions.readValue(element.options[element.selectedIndex]) : undefined;
|
||||
default:
|
||||
return element.value;
|
||||
}
|
||||
},
|
||||
|
||||
writeValue: function(element, value, allowUnset) {
|
||||
switch (ko.utils.tagNameLower(element)) {
|
||||
case 'option':
|
||||
if (typeof value === "string") {
|
||||
ko.utils.domData.set(element, ko.bindingHandlers.options.optionValueDomDataKey, undefined);
|
||||
if (hasDomDataExpandoProperty in element) { // IE <= 8 throws errors if you delete non-existent properties from a DOM node
|
||||
delete element[hasDomDataExpandoProperty];
|
||||
}
|
||||
element.value = value;
|
||||
}
|
||||
else {
|
||||
// Store arbitrary object using DomData
|
||||
ko.utils.domData.set(element, ko.bindingHandlers.options.optionValueDomDataKey, value);
|
||||
element[hasDomDataExpandoProperty] = true;
|
||||
|
||||
// Special treatment of numbers is just for backward compatibility. KO 1.2.1 wrote numerical values to element.value.
|
||||
element.value = typeof value === "number" ? value : "";
|
||||
}
|
||||
break;
|
||||
case 'select':
|
||||
if (value === "" || value === null) // A blank string or null value will select the caption
|
||||
value = undefined;
|
||||
var selection = -1;
|
||||
for (var i = 0, n = element.options.length, optionValue; i < n; ++i) {
|
||||
optionValue = ko.selectExtensions.readValue(element.options[i]);
|
||||
// Include special check to handle selecting a caption with a blank string value
|
||||
if (optionValue == value || (optionValue === "" && value === undefined)) {
|
||||
selection = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allowUnset || selection >= 0 || (value === undefined && element.size > 1)) {
|
||||
element.selectedIndex = selection;
|
||||
if (ko.utils.ieVersion === 6) {
|
||||
// Workaround for IE6 bug: It won't reliably apply values to SELECT nodes during the same execution thread
|
||||
// right after you've changed the set of OPTION nodes on it. So for that node type, we'll schedule a second thread
|
||||
// to apply the value as well.
|
||||
ko.utils.setTimeout(function () {
|
||||
element.selectedIndex = selection;
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ((value === null) || (value === undefined))
|
||||
value = "";
|
||||
element.value = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
ko.exportSymbol('selectExtensions', ko.selectExtensions);
|
||||
ko.exportSymbol('selectExtensions.readValue', ko.selectExtensions.readValue);
|
||||
ko.exportSymbol('selectExtensions.writeValue', ko.selectExtensions.writeValue);
|
||||
Loading…
Add table
Add a link
Reference in a new issue