Dropped more unused knockoutjs code

This commit is contained in:
djmaze 2020-10-29 11:15:04 +01:00
parent b79d9de1a0
commit 1d57a62ddd
14 changed files with 408 additions and 635 deletions

View file

@ -1,4 +1,11 @@
var classesWrittenByBindingKey = '__ko__cssValue';
var classesWrittenByBindingKey = '__ko__cssValue',
toggleClasses = (node, classNames, force) => {
if (classNames) {
classNames.split(/\s+/).forEach(className =>
node.classList.toggle(className, force)
);
}
};
ko.bindingHandlers['css'] = {
'update': (element, valueAccessor) => {
@ -6,13 +13,13 @@ ko.bindingHandlers['css'] = {
if (value !== null && typeof value == "object") {
ko.utils.objectForEach(value, (className, shouldHaveClass) => {
shouldHaveClass = ko.utils.unwrapObservable(shouldHaveClass);
ko.utils.toggleDomNodeCssClass(element, className, shouldHaveClass);
toggleClasses(element, className, !!shouldHaveClass);
});
} else {
value = ko.utils.stringTrim(value);
ko.utils.toggleDomNodeCssClass(element, element[classesWrittenByBindingKey], false);
toggleClasses(element, element[classesWrittenByBindingKey], false);
element[classesWrittenByBindingKey] = value;
ko.utils.toggleDomNodeCssClass(element, value, true);
toggleClasses(element, value, true);
}
}
};

View file

@ -4,7 +4,8 @@ ko.bindingHandlers['foreach'] = {
makeTemplateValueAccessor: valueAccessor => {
return () => {
var modelValue = valueAccessor(),
unwrappedValue = ko.utils.peekObservable(modelValue); // Unwrap without setting a dependency here
// Unwrap without setting a dependency here
unwrappedValue = ko.isObservable(modelValue) ? modelValue.peek() : modelValue;
// If unwrappedValue is the array, pass in the wrapped value on its own
// The value will be unwrapped and tracked within the template binding

View file

@ -1,7 +1,7 @@
var captionPlaceholder = {};
ko.bindingHandlers['options'] = {
'init': element => {
if (ko.utils.tagNameLower(element) !== "select")
if (!element.matches("SELECT"))
throw new Error("options binding applies only to SELECT elements");
// Remove all existing <option>s.

View file

@ -1,7 +1,7 @@
ko.bindingHandlers['value'] = {
'init': (element, valueAccessor, allBindings) => {
var tagName = ko.utils.tagNameLower(element),
isInputElement = tagName == "input";
var isSelectElement = element.matches("SELECT"),
isInputElement = element.matches("INPUT");
// If the value binding is placed on a radio/checkbox, then just pass through to checkedValue and quit
if (isInputElement && (element.type == "checkbox" || element.type == "radio")) {
@ -79,7 +79,7 @@ ko.bindingHandlers['value'] = {
var valueHasChanged = newValue !== elementValue;
if (valueHasChanged || elementValue === undefined) {
if (tagName === "select") {
if (isSelectElement) {
var allowUnset = allBindings.get('valueAllowUnset');
ko.selectExtensions.writeValue(element, newValue, allowUnset);
if (!allowUnset && newValue !== ko.selectExtensions.readValue(element)) {
@ -94,7 +94,7 @@ ko.bindingHandlers['value'] = {
};
}
if (tagName === "select") {
if (isSelectElement) {
var updateFromModelComputed;
ko.bindingEvent.subscribe(element, ko.bindingEvent.childrenComplete, () => {
if (!updateFromModelComputed) {