function moveNodesAfterSibling(sibling, nodes) {
    if (nodes.length > 0 && isPresent(DOM.parentElement(sibling))) {
        for (var i = 0; i < nodes.length; i++) {
            DOM.insertBefore(sibling, nodes[i]);
        }
        DOM.insertBefore(nodes[nodes.length - 1], sibling);
    }
}
 processElement(parent, current, control) {
     var attrs = current.attrs();
     var templateBindings = attrs.get('template');
     var hasTemplateBinding = isPresent(templateBindings);
     // look for template shortcuts such as *ng-if="condition" and treat them as template="if
     // condition"
     MapWrapper.forEach(attrs, (attrValue, attrName) => {
         if (StringWrapper.startsWith(attrName, '*')) {
             var key = StringWrapper.substring(attrName, 1); // remove the star
             if (hasTemplateBinding) {
                 // 2nd template binding detected
                 throw new BaseException(`Only one template directive per element is allowed: ` +
                     `${templateBindings} and ${key} cannot be used simultaneously ` +
                     `in ${current.elementDescription}`);
             }
             else {
                 templateBindings = (attrValue.length == 0) ? key : key + ' ' + attrValue;
                 hasTemplateBinding = true;
             }
         }
     });
     if (isPresent(parent)) {
         if (DOM.isTemplateElement(current.element)) {
             if (!current.isViewRoot) {
                 var viewRoot = new CompileElement(DOM.createTemplate(''));
                 viewRoot.inheritedProtoView = current.bindElement().bindNestedProtoView(viewRoot.element);
                 // viewRoot doesn't appear in the original template, so we associate
                 // the current element description to get a more meaningful message in case of error
                 viewRoot.elementDescription = current.elementDescription;
                 viewRoot.isViewRoot = true;
                 this._moveChildNodes(DOM.content(current.element), DOM.content(viewRoot.element));
                 control.addChild(viewRoot);
             }
         }
         if (hasTemplateBinding) {
             var anchor = new CompileElement(DOM.createTemplate(''));
             anchor.inheritedProtoView = current.inheritedProtoView;
             anchor.inheritedElementBinder = current.inheritedElementBinder;
             anchor.distanceToInheritedBinder = current.distanceToInheritedBinder;
             // newParent doesn't appear in the original template, so we associate
             // the current element description to get a more meaningful message in case of error
             anchor.elementDescription = current.elementDescription;
             var viewRoot = new CompileElement(DOM.createTemplate(''));
             viewRoot.inheritedProtoView = anchor.bindElement().bindNestedProtoView(viewRoot.element);
             // viewRoot doesn't appear in the original template, so we associate
             // the current element description to get a more meaningful message in case of error
             viewRoot.elementDescription = current.elementDescription;
             viewRoot.isViewRoot = true;
             current.inheritedProtoView = viewRoot.inheritedProtoView;
             current.inheritedElementBinder = null;
             current.distanceToInheritedBinder = 0;
             this._parseTemplateBindings(templateBindings, anchor);
             DOM.insertBefore(current.element, anchor.element);
             control.addParent(anchor);
             DOM.appendChild(DOM.content(viewRoot.element), current.element);
             control.addParent(viewRoot);
         }
     }
 }
 ViewSplitter.prototype.processElement = function (parent, current, control) {
     var attrs = current.attrs();
     var templateBindings = attrs.get('template');
     var hasTemplateBinding = lang_1.isPresent(templateBindings);
     // look for template shortcuts such as *ng-if="condition" and treat them as template="if
     // condition"
     collection_1.MapWrapper.forEach(attrs, function (attrValue, attrName) {
         if (lang_1.StringWrapper.startsWith(attrName, '*')) {
             var key = lang_1.StringWrapper.substring(attrName, 1); // remove the star
             if (hasTemplateBinding) {
                 // 2nd template binding detected
                 throw new lang_1.BaseException("Only one template directive per element is allowed: " +
                     (templateBindings + " and " + key + " cannot be used simultaneously ") +
                     ("in " + current.elementDescription));
             }
             else {
                 templateBindings = (attrValue.length == 0) ? key : key + ' ' + attrValue;
                 hasTemplateBinding = true;
             }
         }
     });
     if (lang_1.isPresent(parent)) {
         if (dom_adapter_1.DOM.isTemplateElement(current.element)) {
             if (!current.isViewRoot) {
                 var viewRoot = new compile_element_1.CompileElement(dom_adapter_1.DOM.createTemplate(''));
                 viewRoot.inheritedProtoView = current.bindElement().bindNestedProtoView(viewRoot.element);
                 // viewRoot doesn't appear in the original template, so we associate
                 // the current element description to get a more meaningful message in case of error
                 viewRoot.elementDescription = current.elementDescription;
                 viewRoot.isViewRoot = true;
                 this._moveChildNodes(dom_adapter_1.DOM.content(current.element), dom_adapter_1.DOM.content(viewRoot.element));
                 control.addChild(viewRoot);
             }
         }
         if (hasTemplateBinding) {
             var anchor = new compile_element_1.CompileElement(dom_adapter_1.DOM.createTemplate(''));
             anchor.inheritedProtoView = current.inheritedProtoView;
             anchor.inheritedElementBinder = current.inheritedElementBinder;
             anchor.distanceToInheritedBinder = current.distanceToInheritedBinder;
             // newParent doesn't appear in the original template, so we associate
             // the current element description to get a more meaningful message in case of error
             anchor.elementDescription = current.elementDescription;
             var viewRoot = new compile_element_1.CompileElement(dom_adapter_1.DOM.createTemplate(''));
             viewRoot.inheritedProtoView = anchor.bindElement().bindNestedProtoView(viewRoot.element);
             // viewRoot doesn't appear in the original template, so we associate
             // the current element description to get a more meaningful message in case of error
             viewRoot.elementDescription = current.elementDescription;
             viewRoot.isViewRoot = true;
             current.inheritedProtoView = viewRoot.inheritedProtoView;
             current.inheritedElementBinder = null;
             current.distanceToInheritedBinder = 0;
             this._parseTemplateBindings(templateBindings, anchor);
             dom_adapter_1.DOM.insertBefore(current.element, anchor.element);
             control.addParent(anchor);
             dom_adapter_1.DOM.appendChild(dom_adapter_1.DOM.content(viewRoot.element), current.element);
             control.addParent(viewRoot);
         }
     }
 };
 ShadowDomCompileStep.prototype._processContentElement = function (current) {
     if (this._shadowDomStrategy.hasNativeContentElement()) {
         return;
     }
     var attrs = current.attrs();
     var selector = collection_1.MapWrapper.get(attrs, 'select');
     selector = lang_1.isPresent(selector) ? selector : '';
     var contentStart = dom_adapter_1.DOM.createScriptTag('type', 'ng/contentStart');
     if (lang_1.assertionsEnabled()) {
         dom_adapter_1.DOM.setAttribute(contentStart, 'select', selector);
     }
     var contentEnd = dom_adapter_1.DOM.createScriptTag('type', 'ng/contentEnd');
     dom_adapter_1.DOM.insertBefore(current.element, contentStart);
     dom_adapter_1.DOM.insertBefore(current.element, contentEnd);
     dom_adapter_1.DOM.remove(current.element);
     current.element = contentStart;
     current.bindElement().setContentTagSelector(selector);
 };
  _processContentElement(current) {
    if (this._shadowDomStrategy.hasNativeContentElement()) {
      return;
    }
    var attrs = current.attrs();
    var selector = MapWrapper.get(attrs, 'select');
    selector = isPresent(selector) ? selector : '';

    var contentStart = DOM.createScriptTag('type', 'ng/contentStart');
    if (assertionsEnabled()) {
      DOM.setAttribute(contentStart, 'select', selector);
    }
    var contentEnd = DOM.createScriptTag('type', 'ng/contentEnd');
    DOM.insertBefore(current.element, contentStart);
    DOM.insertBefore(current.element, contentEnd);
    DOM.remove(current.element);

    current.element = contentStart;
    current.bindElement().setContentTagSelector(selector);
  }
Example #6
0
function _insertStyleElement(host, styleEl) {
  if (isBlank(_lastInsertedStyleEl)) {
    var firstChild = DOM.firstChild(host);
    if (isPresent(firstChild)) {
      DOM.insertBefore(firstChild, styleEl);
    } else {
      DOM.appendChild(host, styleEl);
    }
  } else {
    DOM.insertAfter(_lastInsertedStyleEl, styleEl);
  }
  _lastInsertedStyleEl = styleEl;
}
function projectMatchingNodes(selector, contentElement, nodes) {
    var remaining = [];
    dom_adapter_1.DOM.insertBefore(contentElement, dom_adapter_1.DOM.createComment('['));
    for (var i = 0; i < nodes.length; i++) {
        var node = nodes[i];
        var matches = false;
        if (isWildcard(selector)) {
            matches = true;
        }
        else if (dom_adapter_1.DOM.isElementNode(node) && dom_adapter_1.DOM.elementMatches(node, selector)) {
            matches = true;
        }
        if (matches) {
            dom_adapter_1.DOM.insertBefore(contentElement, node);
        }
        else {
            remaining.push(node);
        }
    }
    dom_adapter_1.DOM.insertBefore(contentElement, dom_adapter_1.DOM.createComment(']'));
    dom_adapter_1.DOM.remove(contentElement);
    return remaining;
}
Example #8
0
function insertStyleElement(host, styleEl) {
    if (lang_1.isBlank(_lastInsertedStyleEl)) {
        var firstChild = dom_adapter_1.DOM.firstChild(host);
        if (lang_1.isPresent(firstChild)) {
            dom_adapter_1.DOM.insertBefore(firstChild, styleEl);
        }
        else {
            dom_adapter_1.DOM.appendChild(host, styleEl);
        }
    }
    else {
        dom_adapter_1.DOM.insertAfter(_lastInsertedStyleEl, styleEl);
    }
    _lastInsertedStyleEl = styleEl;
}
 nodes.forEach(function (node) {
     if (lang_1.isBlank(lastInsertedNode)) {
         var firstChild = dom_adapter_1.DOM.firstChild(parentNode);
         if (lang_1.isPresent(firstChild)) {
             dom_adapter_1.DOM.insertBefore(firstChild, node);
         }
         else {
             dom_adapter_1.DOM.appendChild(parentNode, node);
         }
     }
     else {
         dom_adapter_1.DOM.insertAfter(lastInsertedNode, node);
     }
     lastInsertedNode = node;
 });
function appendComponentNodesToHost(hostProtoView, binderIdx, componentRootNodes, useNativeShadowRoot) {
    var hostElement = hostProtoView.boundElements[binderIdx];
    if (useNativeShadowRoot) {
        var shadowRootWrapper = dom_adapter_1.DOM.createElement(util_1.NG_SHADOW_ROOT_ELEMENT_NAME);
        for (var i = 0; i < componentRootNodes.length; i++) {
            dom_adapter_1.DOM.appendChild(shadowRootWrapper, componentRootNodes[i]);
        }
        var firstChild = dom_adapter_1.DOM.firstChild(hostElement);
        if (lang_1.isPresent(firstChild)) {
            dom_adapter_1.DOM.insertBefore(firstChild, shadowRootWrapper);
        }
        else {
            dom_adapter_1.DOM.appendChild(hostElement, shadowRootWrapper);
        }
    }
    else {
        dom_adapter_1.DOM.clearNodes(hostElement);
        for (var i = 0; i < componentRootNodes.length; i++) {
            dom_adapter_1.DOM.appendChild(hostElement, componentRootNodes[i]);
        }
    }
}
 ViewSplitter.prototype._addParentElement = function (currentElement, newParentElement) {
     dom_adapter_1.DOM.insertBefore(currentElement, newParentElement);
     dom_adapter_1.DOM.appendChild(newParentElement, currentElement);
 };