* @param {!../../../src/service/ampdoc-impl.AmpDoc} ampdoc
(ampdoc)
| 229 | * @param {!../../../src/service/ampdoc-impl.AmpDoc} ampdoc |
| 230 | */ |
| 231 | constructor(ampdoc) { |
| 232 | /** @private {!../../../src/service/ampdoc-impl.AmpDoc} */ |
| 233 | this.ampdoc_ = ampdoc; |
| 234 | |
| 235 | /** @private {!JsonObject} */ |
| 236 | this.macros_ = {}; |
| 237 | |
| 238 | /** @const @private {!./linker-reader.LinkerReader} */ |
| 239 | this.linkerReader_ = linkerReaderServiceFor(this.ampdoc_.win); |
| 240 | |
| 241 | /** @const @private {!Promise<SessionManager>} */ |
| 242 | this.sessionManagerPromise_ = sessionServicePromiseForDoc(this.ampdoc_); |
| 243 | |
| 244 | this.register_('$DEFAULT', defaultMacro); |
| 245 | this.register_('$SUBSTR', substrMacro); |
| 246 | this.register_('$TRIM', (value) => value.trim()); |
| 247 | this.register_('$TOLOWERCASE', (value) => value.toLowerCase()); |
| 248 | this.register_('$TOUPPERCASE', (value) => value.toUpperCase()); |
| 249 | this.register_('$NOT', (value) => String(!value)); |
| 250 | this.register_('$BASE64', (value) => base64UrlEncodeFromString(value)); |
| 251 | this.register_('$HASH', this.hashMacro_.bind(this)); |
| 252 | this.register_('$IF', (value, thenValue, elseValue) => |
| 253 | stringToBool(value) ? thenValue : elseValue |
| 254 | ); |
| 255 | this.register_('$REPLACE', replaceMacro); |
| 256 | this.register_('$MATCH', matchMacro); |
| 257 | this.register_('$CALC', calcMacro); |
| 258 | this.register_( |
| 259 | '$EQUALS', |
| 260 | (firstValue, secValue) => firstValue === secValue |
| 261 | ); |
| 262 | this.register_('LINKER_PARAM', (name, id) => |
| 263 | this.linkerReader_.get(name, id) |
| 264 | ); |
| 265 | |
| 266 | // Returns the IANA timezone code |
| 267 | this.register_('TIMEZONE_CODE', () => { |
| 268 | let tzCode = ''; |
| 269 | if ( |
| 270 | 'Intl' in this.ampdoc_.win && |
| 271 | 'DateTimeFormat' in this.ampdoc_.win.Intl |
| 272 | ) { |
| 273 | // It could be undefined (i.e. IE11) |
| 274 | tzCode = new this.ampdoc_.win.Intl.DateTimeFormat().resolvedOptions() |
| 275 | .timeZone; |
| 276 | } |
| 277 | |
| 278 | return tzCode; |
| 279 | }); |
| 280 | |
| 281 | // Returns a promise resolving to viewport.getScrollTop. |
| 282 | this.register_('SCROLL_TOP', () => |
| 283 | Math.round(Services.viewportForDoc(this.ampdoc_).getScrollTop()) |
| 284 | ); |
| 285 | |
| 286 | // Returns a promise resolving to viewport.getScrollLeft. |
| 287 | this.register_('SCROLL_LEFT', () => |
| 288 | Math.round(Services.viewportForDoc(this.ampdoc_).getScrollLeft()) |
nothing calls this directly
no test coverage detected