( element, id, extension, opt_element )
| 81 | * @return {!Promise<?Object>} |
| 82 | */ |
| 83 | export function getElementServiceIfAvailableForDoc( |
| 84 | element, |
| 85 | id, |
| 86 | extension, |
| 87 | opt_element |
| 88 | ) { |
| 89 | const s = getServicePromiseOrNullForDoc(element, id); |
| 90 | if (s) { |
| 91 | return /** @type {!Promise<?Object>} */ (s); |
| 92 | } |
| 93 | const ampdoc = getAmpdoc(element); |
| 94 | return ampdoc |
| 95 | .whenExtensionsKnown() |
| 96 | .then(() => { |
| 97 | const version = ampdoc.getExtensionVersion(extension); |
| 98 | if (!version) { |
| 99 | return null; |
| 100 | } |
| 101 | const extensions = getService(ampdoc.win, 'extensions'); |
| 102 | return extensions.waitForExtension(extension, version); |
| 103 | }) |
| 104 | .then((ext) => { |
| 105 | if (!ext) { |
| 106 | return null; |
| 107 | } |
| 108 | // If this service is provided by an element, then we can't depend on |
| 109 | // the service (they may not use the element). |
| 110 | if (opt_element) { |
| 111 | return getServicePromiseOrNullForDoc(element, id); |
| 112 | } |
| 113 | return getServicePromiseForDoc(element, id); |
| 114 | }); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Returns a promise for service for the given id in the embed scope of |
no test coverage detected