* Implementation for `attachShadowDoc` function. Attaches the shadow doc and * configures ampdoc for it. * @param {!Element} hostElement * @param {!Document} doc * @param {string} url * @param {!{[key: string]: string}=} opt_initParams * @return {!./runtime.ShadowDoc}
(hostElement, doc, url, opt_initParams)
| 217 | * @return {!./runtime.ShadowDoc} |
| 218 | */ |
| 219 | attachShadowDoc(hostElement, doc, url, opt_initParams) { |
| 220 | user().assertString(url); |
| 221 | dev().fine(TAG, 'Attach shadow doc:', doc); |
| 222 | // TODO(dvoytenko, #9490): once stable, port full document case to emulated |
| 223 | // stream. |
| 224 | return this.attachShadowDoc_( |
| 225 | hostElement, |
| 226 | url, |
| 227 | opt_initParams, |
| 228 | (amp, shadowRoot, ampdoc) => { |
| 229 | // Install extensions. |
| 230 | this.mergeShadowHead_(ampdoc, shadowRoot, doc); |
| 231 | |
| 232 | // Append body. |
| 233 | if (doc.body) { |
| 234 | const body = importShadowBody(shadowRoot, doc.body, /* deep */ true); |
| 235 | body.classList.add('amp-shadow'); |
| 236 | ampdoc.setBody(body); |
| 237 | } |
| 238 | |
| 239 | // TODO(dvoytenko): find a better and more stable way to make content |
| 240 | // visible. E.g. integrate with dynamic classes. In shadow case |
| 241 | // specifically, we have to wait for stubbing to complete, which may |
| 242 | // take awhile due to importNode. |
| 243 | setTimeout(() => { |
| 244 | ampdoc.signals().signal(CommonSignals_Enum.RENDER_START); |
| 245 | setStyle(hostElement, 'visibility', 'visible'); |
| 246 | }, 50); |
| 247 | |
| 248 | return Promise.resolve(); |
| 249 | } |
| 250 | ); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Implementation for `attachShadowDocAsStream` function. Attaches the shadow |
no test coverage detected