mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 22:47:03 +03:00
Bugfix: put back the knockout bindings if/ifnot as they are in use
This commit is contained in:
parent
ba7ed497b2
commit
92836117ee
7 changed files with 206 additions and 145 deletions
72
vendors/knockout/src/binding/defaultBindings/ifIfnot.js
vendored
Normal file
72
vendors/knockout/src/binding/defaultBindings/ifIfnot.js
vendored
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
(() => {
|
||||
|
||||
// Makes a binding like with or if
|
||||
function makeIfBinding(bindingKey, isNot) {
|
||||
ko.bindingHandlers[bindingKey] = {
|
||||
'init': (element, valueAccessor, allBindings, viewModel, bindingContext) => {
|
||||
var didDisplayOnLastUpdate, savedNodes, contextOptions = {}, completeOnRender, needAsyncContext, renderOnEveryChange;
|
||||
|
||||
completeOnRender = allBindings.get("completeOn") == "render";
|
||||
needAsyncContext = completeOnRender || allBindings['has'](ko.bindingEvent.descendantsComplete);
|
||||
|
||||
ko.computed(() => {
|
||||
var value = ko.utils.unwrapObservable(valueAccessor()),
|
||||
shouldDisplay = !isNot !== !value, // equivalent to isNot ? !value : !!value,
|
||||
isInitial = !savedNodes,
|
||||
childContext;
|
||||
|
||||
if (!renderOnEveryChange && shouldDisplay === didDisplayOnLastUpdate) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (needAsyncContext) {
|
||||
bindingContext = ko.bindingEvent.startPossiblyAsyncContentBinding(element, bindingContext);
|
||||
}
|
||||
|
||||
if (shouldDisplay) {
|
||||
if (renderOnEveryChange) {
|
||||
contextOptions['dataDependency'] = ko.computedContext.computed();
|
||||
}
|
||||
|
||||
if (ko.computedContext.getDependenciesCount()) {
|
||||
childContext = bindingContext['extend'](null, contextOptions);
|
||||
} else {
|
||||
childContext = bindingContext;
|
||||
}
|
||||
}
|
||||
|
||||
// Save a copy of the inner nodes on the initial update, but only if we have dependencies.
|
||||
if (isInitial && ko.computedContext.getDependenciesCount()) {
|
||||
savedNodes = ko.utils.cloneNodes(ko.virtualElements.childNodes(element), true /* shouldCleanNodes */);
|
||||
}
|
||||
|
||||
if (shouldDisplay) {
|
||||
if (!isInitial) {
|
||||
ko.virtualElements.setDomNodeChildren(element, ko.utils.cloneNodes(savedNodes));
|
||||
}
|
||||
|
||||
ko.applyBindingsToDescendants(childContext, element);
|
||||
} else {
|
||||
ko.virtualElements.emptyNode(element);
|
||||
|
||||
if (!completeOnRender) {
|
||||
ko.bindingEvent.notify(element, ko.bindingEvent.childrenComplete);
|
||||
}
|
||||
}
|
||||
|
||||
didDisplayOnLastUpdate = shouldDisplay;
|
||||
|
||||
}, null, { disposeWhenNodeIsRemoved: element });
|
||||
|
||||
return { 'controlsDescendantBindings': true };
|
||||
}
|
||||
};
|
||||
ko.expressionRewriting.bindingRewriteValidators[bindingKey] = false; // Can't rewrite control flow bindings
|
||||
ko.virtualElements.allowedBindings[bindingKey] = true;
|
||||
}
|
||||
|
||||
// Construct the actual binding handlers
|
||||
makeIfBinding('if');
|
||||
makeIfBinding('ifnot', true);
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue