PageSourceSearch

https://asset.kompas.com/data/2017/inside/js/svgxuse-inside.js?v=1

js kompas.com collected 2026-09-27 20:54:36 UTC 10,035 bytes, 228 lines download raw bytes

vendor: 6,201 bytes, lines 1-146
1/*!
2 * @copyright Copyright (c) 2017 IcoMoon.io
3 * @license   Licensed under MIT license
4 *            See https://github.com/Keyamoon/svgxuse
5 * @version   1.2.2
6 */
7/*jslint browser: true */
8/*global XDomainRequest, MutationObserver, window */
9(function () {
10    "use strict";
11    if (window && window.addEventListener) {
12        var cache = Object.create(null); // holds xhr objects to prevent multiple requests
13        var checkUseElems;
14        var tid; // timeout id
15        var debouncedCheck = function () {
16            clearTimeout(tid);
17            tid = setTimeout(checkUseElems, 100);
18        };
19        var unobserveChanges = function () {
20            return;
21        };
22        var observeChanges = function () {
23            var observer;
24            window.addEventListener("resize", debouncedCheck, false);
25            window.addEventListener("orientationchange", debouncedCheck, false);
26            if (window.MutationObserver) {
27                observer = new MutationObserver(debouncedCheck);
28                observer.observe(document.documentElement, {
29                    childList: true,
30                    subtree: true,
31                    attributes: true
32                });
33                unobserveChanges = function () {
34                    try {
35                        observer.disconnect();
36                        window.removeEventListener("resize", debouncedCheck, false);
37                        window.removeEventListener("orientationchange", debouncedCheck, false);
38                    } catch (ignore) {}
39                };
40            } else {
41                document.documentElement.addEventListener("DOMSubtreeModified", debouncedCheck, false);
42                unobserveChanges = function () {
43                    document.documentElement.removeEventListener("DOMSubtreeModified", debouncedCheck, false);
44                    window.removeEventListener("resize", debouncedCheck, false);
45                    window.removeEventListener("orientationchange", debouncedCheck, false);
46                };
47            }
48        };
49        var createRequest = function (url) {
50            // In IE 9, cross origin requests can only be sent using XDomainRequest.
51            // XDomainRequest would fail if CORS headers are not set.
52            // Therefore, XDomainRequest should only be used with cross origin requests.
53            function getOrigin(loc) {
54                var a;
55                if (loc.protocol !== undefined) {
56                    a = loc;
57                } else {
58                    a = document.createElement("a");
59                    a.href = loc;
60                }
61                return a.protocol.replace(/:/g, "") + a.host;
62            }
63            var Request;
64            var origin;
65            var origin2;
66            if (window.XMLHttpRequest) {
67                Request = new XMLHttpRequest();
68                origin = getOrigin(location);
69                origin2 = getOrigin(url);
70                if (Request.withCredentials === undefined && origin2 !== "" && origin2 !== origin) {
71                    Request = XDomainRequest || undefined;
72                } else {
73                    Request = XMLHttpRequest;
74                }
75            }
76            return Request;
77        };
78        var xlinkNS = "http://www.w3.org/1999/xlink";
79        checkUseElems = function () {
80            var base;
81            var bcr;
82            var fallback =  "http://assets.kompas.com/data/2017/inside/images/symbol-inside.svg"; // optional fallback URL in case no base path to SVG file was given and no symbol definition was found.
83            var hash;
84            var href;
85            var i;
86            var inProgressCount = 0;
87            var isHidden;
88            var isXlink = false;
89            var Request;
90            var url;
91            var uses;
92            var xhr;
93            function observeIfDone() {
94                // If done with making changes, start watching for chagnes in DOM again
95                inProgressCount -= 1;
96                if (inProgressCount === 0) { // if all xhrs were resolved
97                    unobserveChanges(); // make sure to remove old handlers
98                    observeChanges(); // watch for changes to DOM
99                }
100            }
101            function attrUpdateFunc(spec) {
102                return function () {
103                    if (cache[spec.base] !== true) {
104                        if (spec.isXlink) {
105                            spec.useEl.setAttributeNS(xlinkNS, "xlink:href", "#" + spec.hash);
106                        } else {
107                            spec.useEl.setAttribute("href", "#" + spec.hash);
108                        }
109                    }
110                };
111            }
112            function onloadFunc(xhr) {
113                return function () {
114                    var body = document.body;
115                    var x = document.createElement("x");
116                    var svg;
117                    xhr.onload = null;
118                    x.innerHTML = xhr.responseText;
119                    svg = x.getElementsByTagName("svg")[0];
120                    if (svg) {
121                        svg.setAttribute("aria-hidden", "true");
122                        svg.style.position = "absolute";
123                        svg.style.width = 0;
124                        svg.style.height = 0;
125                        svg.style.overflow = "hidden";
126                        body.insertBefore(svg, body.firstChild);
127                    }
128                    observeIfDone();
129                };
130            }
131            function onErrorTimeout(xhr) {
132                return function () {
133                    xhr.onerror = null;
134                    xhr.ontimeout = null;
135                    observeIfDone();
136                };
137            }
138            unobserveChanges(); // stop watching for changes to DOM
139            // find all use elements
140            uses = document.getElementsByTagName("use");
141            for (i = 0; i < uses.length; i += 1) {
142                try {
143                    bcr = uses[i].getBoundingClientRect();
144                } catch (ignore) {
145                    // failed to get bounding rectangle of the use element
146                    bcr = false;
147                }
148                href = uses[i].getAttribute("href");
149                if (!href) {
150                    href = uses[i].getAttributeNS(xlinkNS, "href");
151                    isXlink = true;
152                } else {
153                    isXlink = false;
154                }
155                if (href && href.split) {
156                    url = href.split("#");
157                } else {
158                    url = ["", ""];
159                }
160                base = url[0];
161                hash = url[1];
162                isHidden = bcr && bcr.left === 0 && bcr.right === 0 && bcr.top === 0 && bcr.bottom === 0;
163                if (bcr && bcr.width === 0 && bcr.height === 0 && !isHidden) {
164                    // the use element is empty
165                    // if there is a reference to an external SVG, try to fetch it
166                    // use the optional fallback URL if there is no reference to an external SVG
167                    if (fallback && !base.length && hash && !document.getElementById(hash)) {
168                        base = fallback;
169                    }
170                    if (base.length) {
171                        // schedule updating xlink:href
172                        xhr = cache[base];
173                        if (xhr !== true) {
174                            // true signifies that prepending the SVG was not required
175                            setTimeout(attrUpdateFunc({
176                                useEl: uses[i],
177                                base: base,
178                                hash: hash,
179                                isXlink: isXlink
180                            }), 0);
181                        }
182                        if (xhr === undefined) {
183                            Request = createRequest(base);
184                            if (Request !== undefined) {
185                                xhr = new Request();
186                                cache[base] = xhr;
187                                xhr.onload = onloadFunc(xhr);
188                                xhr.onerror = onErrorTimeout(xhr);
189                                xhr.ontimeout = onErrorTimeout(xhr);
190                                xhr.open("GET", base);
191                                xhr.send();
192                                inProgressCount += 1;
193                            }
194                        }
195                    }
196                } else {
197                    if (!isHidden) {
198                        if (cache[base] === undefined) {
199                            // remember this URL if the use element was not empty and no request was sent
200                            cache[base] = true;
201                        } else if (cache[base].onload) {
202                            // if it turns out that prepending the SVG is not necessary,
203                            // abort the in-progress xhr.
204                            cache[base].abort();
205                            delete cache[base].onload;
206                            cache[base] = true;
207                        }
208                    } else if (base.length && cache[base]) {
209                        setTimeout(attrUpdateFunc({
210                            useEl: uses[i],
211                            base: base,
212                            hash: hash,
213                            isXlink: isXlink
214                        }), 0);
215                    }
216                }
217            }
218            uses = "";
219            inProgressCount += 1;
220            observeIfDone();
221        };
222        // The load event fires when all resources have finished loading, which allows detecting whether SVG use elements are empty.
223        window.addEventListener("load", function winLoad() {
224            window.removeEventListener("load", winLoad, false); // to prevent memory leaks
225            tid = setTimeout(checkUseElems, 0);
226        }, false);
227    }
228}());

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.