dist/tko.binding.if.js
function makeWithIfBinding(isWith, isNot, isElse, makeContextCallback) {
      return {
          init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {

              var didDisplayOnLastUpdate,
                  hasElse = detectElse(element),
                  completesElseChain = observable(),
                  ifElseNodes,
                  precedingConditional;

              set(element, "conditional", {
                  elseChainSatisfied: completesElseChain,
              });

              if (isElse) {
                  precedingConditional = getPrecedingConditional(element);
              }

              computed(function() {
                  var rawValue = valueAccessor(),
                      dataValue = unwrap(rawValue),
                      shouldDisplayIf = !isNot !== !dataValue || (isElse && rawValue === undefined), // equivalent to (isNot ? !dataValue : !!dataValue) || isElse && rawValue === undefined
                      isFirstRender = !ifElseNodes,
                      needsRefresh = isFirstRender || isWith || (shouldDisplayIf !== didDisplayOnLastUpdate);

                  if (precedingConditional && precedingConditional.elseChainSatisfied()) {
                      needsRefresh = shouldDisplayIf !== false;
                      shouldDisplayIf = false;
                      completesElseChain(true);
                  } else {
                      completesElseChain(shouldDisplayIf);
                  }

                  if (!needsRefresh) { return; }

                  if (isFirstRender && (getDependenciesCount() || hasElse)) {
                      ifElseNodes = cloneIfElseNodes(element, hasElse);
                  }

                  if (shouldDisplayIf) {
                      if (!isFirstRender || hasElse) {
                          setDomNodeChildren(element, cloneNodes(ifElseNodes.ifNodes));
                      }
                  } else if (ifElseNodes) {
                      setDomNodeChildren(element, cloneNodes(ifElseNodes.elseNodes));
                  } else {
                      emptyNode(element);
                  }

                  applyBindingsToDescendants(makeContextCallback ? makeContextCallback(bindingContext, rawValue) : bindingContext, element);

                  didDisplayOnLastUpdate = shouldDisplayIf;
              }, null, { disposeWhenNodeIsRemoved: element });

              return { 'controlsDescendantBindings': true };
          },
          allowVirtualElements: true,
          bindingRewriteValidator: false
      };
  }
function makeWithIfBinding(isWith, isNot, isElse, makeContextCallback) {
      return {
          init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {

              var didDisplayOnLastUpdate,
                  hasElse = detectElse(element),
                  completesElseChain = observable(),
                  ifElseNodes,
                  precedingConditional;

              set(element, "conditional", {
                  elseChainSatisfied: completesElseChain,
              });

              if (isElse) {
                  precedingConditional = getPrecedingConditional(element);
              }

              computed(function() {
                  var rawValue = valueAccessor(),
                      dataValue = unwrap(rawValue),
                      shouldDisplayIf = !isNot !== !dataValue || (isElse && rawValue === undefined), // equivalent to (isNot ? !dataValue : !!dataValue) || isElse && rawValue === undefined
                      isFirstRender = !ifElseNodes,
                      needsRefresh = isFirstRender || isWith || (shouldDisplayIf !== didDisplayOnLastUpdate);

                  if (precedingConditional && precedingConditional.elseChainSatisfied()) {
                      needsRefresh = shouldDisplayIf !== false;
                      shouldDisplayIf = false;
                      completesElseChain(true);
                  } else {
                      completesElseChain(shouldDisplayIf);
                  }

                  if (!needsRefresh) { return; }

                  if (isFirstRender && (getDependenciesCount() || hasElse)) {
                      ifElseNodes = cloneIfElseNodes(element, hasElse);
                  }

                  if (shouldDisplayIf) {
                      if (!isFirstRender || hasElse) {
                          setDomNodeChildren(element, cloneNodes(ifElseNodes.ifNodes));
                      }
                  } else if (ifElseNodes) {
                      setDomNodeChildren(element, cloneNodes(ifElseNodes.elseNodes));
                  } else {
                      emptyNode(element);
                  }

                  applyBindingsToDescendants(makeContextCallback ? makeContextCallback(bindingContext, rawValue) : bindingContext, element);

                  didDisplayOnLastUpdate = shouldDisplayIf;
              }, null, { disposeWhenNodeIsRemoved: element });

              return { 'controlsDescendantBindings': true };
          },
          allowVirtualElements: true,
          bindingRewriteValidator: false
      };
  }
function makeWithIfBinding ( isWith , isNot , isElse , makeContextCallback ) { return { init : function ( element , valueAccessor , allBindings , viewModel , bindingContext ) { var didDisplayOnLastUpdate , hasElse = detectElse ( element ) , completesElseChain = observable ( ) , ifElseNodes , precedingConditional ; set ( element , "conditional" , { elseChainSatisfied : completesElseChain , } ) ; if ( isElse ) { precedingConditional = getPrecedingConditional ( element ) ; } computed ( function ( ) { var rawValue = valueAccessor ( ) , dataValue = unwrap ( rawValue ) , shouldDisplayIf = ! isNot !== ! dataValue || ( isElse && rawValue === undefined ) , // equivalent to (isNot ? !dataValue : !!dataValue) || isElse && rawValue === undefined isFirstRender = ! ifElseNodes , needsRefresh = isFirstRender || isWith || ( shouldDisplayIf !== didDisplayOnLastUpdate ) ; if ( precedingConditional && precedingConditional . elseChainSatisfied ( ) ) { needsRefresh = shouldDisplayIf !== false ; shouldDisplayIf = false ; completesElseChain ( true ) ; } else { completesElseChain ( shouldDisplayIf ) ; } if ( ! needsRefresh ) { return ; } if ( isFirstRender && ( getDependenciesCount ( ) || hasElse ) ) { ifElseNodes = cloneIfElseNodes ( element , hasElse ) ; } if ( shouldDisplayIf ) { if ( ! isFirstRender || hasElse ) { setDomNodeChildren ( element , cloneNodes ( ifElseNodes . ifNodes ) ) ; } } else if ( ifElseNodes ) { setDomNodeChildren ( element , cloneNodes ( ifElseNodes . elseNodes ) ) ; } else { emptyNode ( element ) ; } applyBindingsToDescendants ( makeContextCallback ? makeContextCallback ( bindingContext , rawValue ) : bindingContext , element ) ; didDisplayOnLastUpdate = shouldDisplayIf ; } , null , { disposeWhenNodeIsRemoved : element } ) ; return { 'controlsDescendantBindings' : true } ; } , allowVirtualElements : true , bindingRewriteValidator : false } ; }
Create a DOMbinding that controls DOM nodes presence

Covers e.g.

1. DOM Nodes contents

<div data-bind='if: x'>
<!-- else --> ... an optional "if"
</div>

2. Virtual elements

<!-- ko if: x -->
<!-- else -->
<!-- /ko -->

3. Else binding
<div data-bind='if: x'></div>
<div data-bind='else'></div>
Create a DOMbinding that controls DOM nodes presence