* Start resolving any macros that may exist in the linker configuration * and register the callback with the navigation service. Since macro * resolution is asynchronous the callback may be looking for these values * before they are ready. * init() is asynchronouse and non blocking. *
()
| 69 | * @return {!Promise} |
| 70 | */ |
| 71 | init() { |
| 72 | if (!isObject(this.config_)) { |
| 73 | return Promise.resolve(); |
| 74 | } |
| 75 | |
| 76 | this.highestAvailableDomain_ = getHighestAvailableDomain(this.ampdoc_.win); |
| 77 | |
| 78 | this.config_ = this.processConfig_( |
| 79 | /** @type {!JsonObject} */ (this.config_) |
| 80 | ); |
| 81 | // Each linker config has it's own set of macros to resolve. |
| 82 | const allLinkerPromises = Object.keys(this.config_).map((name) => { |
| 83 | const ids = this.config_[name]['ids']; |
| 84 | // Keys for linker data. |
| 85 | const keys = Object.keys(ids); |
| 86 | // Expand the value of each key value pair (if necessary). |
| 87 | const valuePromises = keys.map((key) => { |
| 88 | const expansionOptions = new ExpansionOptions( |
| 89 | this.vars_, |
| 90 | /* opt_iterations */ undefined, |
| 91 | /* opt_noencode */ true |
| 92 | ); |
| 93 | return this.expandTemplateWithUrlParams_(ids[key], expansionOptions); |
| 94 | }); |
| 95 | |
| 96 | return Promise.all(valuePromises).then((values) => { |
| 97 | // Rejoin each key with its expanded value. |
| 98 | const expandedIds = {}; |
| 99 | values.forEach((value, i) => { |
| 100 | // Omit pair if value resolves to empty. |
| 101 | if (value) { |
| 102 | expandedIds[keys[i]] = value; |
| 103 | } |
| 104 | }); |
| 105 | this.resolvedIds_[name] = expandedIds; |
| 106 | return expandedIds; |
| 107 | }); |
| 108 | }); |
| 109 | |
| 110 | if (allLinkerPromises.length) { |
| 111 | const navigation = Services.navigationForDoc(this.ampdoc_); |
| 112 | navigation.registerAnchorMutator((element, event) => { |
| 113 | if (!element.href || event.type !== 'click') { |
| 114 | return; |
| 115 | } |
| 116 | element.href = this.applyLinkers_(element.href); |
| 117 | }, Priority_Enum.ANALYTICS_LINKER); |
| 118 | navigation.registerNavigateToMutator( |
| 119 | (url) => this.applyLinkers_(url), |
| 120 | Priority_Enum.ANALYTICS_LINKER |
| 121 | ); |
| 122 | } |
| 123 | |
| 124 | this.enableFormSupport_(); |
| 125 | |
| 126 | return Promise.all(allLinkerPromises); |
| 127 | } |
| 128 |
nothing calls this directly
no test coverage detected