mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-11-01 18:08:49 +03:00
Dropped more unused knockoutjs code
This commit is contained in:
parent
b79d9de1a0
commit
1d57a62ddd
14 changed files with 408 additions and 635 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue