PageSourceSearch

https://earsc-portal.eu/includes/js/meta.js

js earsc-portal.eu collected 2026-09-28 23:57:32 UTC 3,205 bytes, 92 lines download raw bytes

1/**
2 * confluence/meta is used to access dynamic metadata passed from the
3 * server to JavaScript via the page HTML.
4 *
5 * @since 3.6
6 * @module confluence/meta
7 */
8define('confluence/meta', ['confluence/api/type-helpers'], function(TypeHelpers) {
9    'use strict';
10
11    // A backing map to use if the user sets data.
12    var overrides = {};
13
14    return {
15        /**
16         * Sets metadata with a key and value, for use when the state of the page changes after
17         * loading from the server
18         * @param {String} key
19         * @param {String|boolean} value
20         */
21        set: function(key, value) {
22            overrides[key] = value;
23        },
24
25        /**
26         * Returns a value given a key. If no entry exists with the key, undefined is returned.
27         * If the string value is "true" or "false" the respective boolean value is returned.
28         * If the type is defined in an override, the return value will respect/have the overridden type.
29         *
30         * The function doesn't implement any caching. Note that <meta> tags are mutable, e.g. the comment editor relies on it.
31         *
32         * @method get
33         * @param {String} key
34         * @return {String|boolean}
35         */
36        get: function(key) {
37            if (typeof overrides[key] !== 'undefined') {
38                return overrides[key];
39            }
40
41            // First query <head> where all meta tags should live
42            var metaEl = document.head.querySelector('meta[name="ajs-' + key + '"]');
43            if (!metaEl) {
44                // Second pass queries all DOM including <body> (if it already exists)
45                metaEl = document.querySelector('meta[name="ajs-' + key + '"]');
46                if (!metaEl) {
47                    return undefined;
48                }
49            }
50
51            var value = metaEl.getAttribute('content');
52            return TypeHelpers.asBooleanOrString(value);
53        },
54
55        /**
56         * Returns true if the value for the provided key is equal to "true", else returns false.
57         *
58         * @method getBoolean
59         * @param {String} key
60         * @return {boolean}
61         */
62        getBoolean: function(key) {
63            return this.get(key) === true;
64        },
65
66        /**
67         * Returns a number if the value for the provided key can be converted to one.
68         * Good for retrieving content ids to check truthiness (e.g. '0' is truthy but 0 is falsy).
69         *
70         * @method getNumber
71         * @param {String} key
72         * @return {number}
73         */
74        getNumber: function(key) {
75            return +this.get(key);
76        },
77
78        /**
79         * Mainly for use when debugging, returns all Data pairs in a map for eyeballing.
80         * @return {object}
81         */
82        getAllAsMap: function() {
83            var map = {};
84            document.querySelectorAll('meta[name^="ajs-"]').forEach(function(meta) {
85                map[meta.getAttribute('name').substring(4)] = meta.getAttribute('content');
86            });
87            return Object.assign(map, overrides);
88        }
89    };
90});
91
92require('confluence/module-exporter').exportModuleAsGlobal('confluence/meta', 'AJS.Meta');

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.