MCPcopy Create free account
hub / github.com/ampproject/amphtml / constructor

Method constructor

extensions/amp-analytics/0.1/variables.js:231–299  ·  view source on GitHub ↗

* @param {!../../../src/service/ampdoc-impl.AmpDoc} ampdoc

(ampdoc)

Source from the content-addressed store, hash-verified

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())

Callers

nothing calls this directly

Calls 11

register_Method · 0.95
linkerReaderServiceForFunction · 0.90
stringToBoolFunction · 0.85
experimentBranchesMacroFunction · 0.85
getMetaByNameMethod · 0.80
StringFunction · 0.50
getMethod · 0.45
getScrollTopMethod · 0.45
getScrollLeftMethod · 0.45

Tested by

no test coverage detected