/
shadow_dom_compile_step.js
56 lines (56 loc) · 2.95 KB
/
shadow_dom_compile_step.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var lang_1 = require('angular2/src/facade/lang');
var collection_1 = require('angular2/src/facade/collection');
var dom_adapter_1 = require('angular2/src/dom/dom_adapter');
var ShadowDomCompileStep = (function () {
function ShadowDomCompileStep(_shadowDomStrategy, _template, _subTaskPromises) {
this._shadowDomStrategy = _shadowDomStrategy;
this._template = _template;
this._subTaskPromises = _subTaskPromises;
}
ShadowDomCompileStep.prototype.process = function (parent, current, control) {
var tagName = dom_adapter_1.DOM.tagName(current.element).toUpperCase();
if (tagName == 'STYLE') {
this._processStyleElement(current, control);
}
else if (tagName == 'CONTENT') {
this._processContentElement(current);
}
else {
var componentId = current.isBound() ? current.inheritedElementBinder.componentId : null;
this._shadowDomStrategy.processElement(this._template.componentId, componentId, current.element);
}
};
ShadowDomCompileStep.prototype._processStyleElement = function (current, control) {
var stylePromise = this._shadowDomStrategy.processStyleElement(this._template.componentId, this._template.templateAbsUrl, current.element);
if (lang_1.isPresent(stylePromise) && lang_1.isPromise(stylePromise)) {
collection_1.ListWrapper.push(this._subTaskPromises, stylePromise);
}
// Style elements should not be further processed by the compiler, as they can not contain
// bindings. Skipping further compiler steps allow speeding up the compilation process.
control.ignoreCurrentElement();
};
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 : '';
// The content tag should be replaced by a pair of marker tags (start & end).
// The end marker creation is delayed to keep the number of elements constant.
// Creating the end marker here would invalidate the parent's textNodeIndices for the subsequent
// text nodes
var contentStart = dom_adapter_1.DOM.createScriptTag('type', 'ng/contentStart');
if (lang_1.assertionsEnabled()) {
dom_adapter_1.DOM.setAttribute(contentStart, 'select', selector);
}
dom_adapter_1.DOM.insertBefore(current.element, contentStart);
dom_adapter_1.DOM.remove(current.element);
current.element = contentStart;
current.bindElement().setContentTagSelector(selector);
};
return ShadowDomCompileStep;
})();
exports.ShadowDomCompileStep = ShadowDomCompileStep;
exports.__esModule = true;
//# sourceMappingURL=shadow_dom_compile_step.js.map