vendor: 7,307 bytes, lines 1-227
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.6 6 */ 7/*jslint browser: true */ 8/*global XDomainRequest, MutationObserver, window */ 9(function () { 10 "use strict"; 11 if (typeof window !== "undefined" && 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( 38 "orientationchange", 39 debouncedCheck, 40 false, 41 ); 42 } catch (ignore) {} 43 }; 44 } else { 45 document.documentElement.addEventListener( 46 "DOMSubtreeModified", 47 debouncedCheck, 48 false, 49 ); 50 unobserveChanges = function () { 51 document.documentElement.removeEventListener( 52 "DOMSubtreeModified", 53 debouncedCheck, 54 false, 55 ); 56 window.removeEventListener("resize", debouncedCheck, false); 57 window.removeEventListener( 58 "orientationchange", 59 debouncedCheck, 60 false, 61 ); 62 }; 63 } 64 }; 65 var createRequest = function (url) { 66 // In IE 9, cross origin requests can only be sent using XDomainRequest. 67 // XDomainRequest would fail if CORS headers are not set. 68 // Therefore, XDomainRequest should only be used with cross origin requests. 69 function getOrigin(loc) { 70 var a; 71 if (loc.protocol !== undefined) { 72 a = loc; 73 } else { 74 a = document.createElement("a"); 75 a.href = loc; 76 } 77 return a.protocol.replace(/:/g, "") + a.host; 78 } 79 var Request; 80 var origin; 81 var origin2; 82 if (window.XMLHttpRequest) { 83 Request = new XMLHttpRequest(); 84 origin = getOrigin(location); 85 origin2 = getOrigin(url); 86 if ( 87 Request.withCredentials === undefined && 88 origin2 !== "" && 89 origin2 !== origin 90 ) { 91 Request = XDomainRequest || undefined; 92 } else { 93 Request = XMLHttpRequest; 94 } 95 } 96 return Request; 97 }; 98 var xlinkNS = "http://www.w3.org/1999/xlink"; 99 checkUseElems = function () { 100 var base; 101 var bcr; 102 var fallback = ""; // optional fallback URL in case no base path to SVG file was given and no symbol definition was found. 103 var hash; 104 var href; 105 var i; 106 var inProgressCount = 0; 107 var isHidden; 108 var Request; 109 var url; 110 var uses; 111 var xhr; 112 function observeIfDone() { 113 // If done with making changes, start watching for chagnes in DOM again 114 inProgressCount -= 1; 115 if (inProgressCount === 0) { 116 // if all xhrs were resolved 117 unobserveChanges(); // make sure to remove old handlers 118 observeChanges(); // watch for changes to DOM 119 } 120 } 121 function attrUpdateFunc(spec) { 122 return function () { 123 if (cache[spec.base] !== true) { 124 spec.useEl.setAttributeNS(xlinkNS, "xlink:href", "#" + spec.hash); 125 if (spec.useEl.hasAttribute("href")) { 126 spec.useEl.setAttribute("href", "#" + spec.hash); 127 } 128 } 129 }; 130 } 131 function onloadFunc(xhr) { 132 return function () { 133 var body = document.body; 134 var x = document.createElement("x"); 135 var svg; 136 xhr.onload = null; 137 x.innerHTML = xhr.responseText; 138 svg = x.getElementsByTagName("svg")[0]; 139 if (svg) { 140 svg.setAttribute("aria-hidden", "true"); 141 svg.style.position = "absolute"; 142 svg.style.width = 0; 143 svg.style.height = 0; 144 svg.style.overflow = "hidden"; 145 body.insertBefore(svg, body.firstChild); 146 } 147 observeIfDone(); 148 }; 149 } 150 function onErrorTimeout(xhr) { 151 return function () { 152 xhr.onerror = null; 153 xhr.ontimeout = null; 154 observeIfDone(); 155 }; 156 } 157 unobserveChanges(); // stop watching for changes to DOM 158 // find all use elements 159 uses = document.getElementsByTagName("use"); 160 for (i = 0; i < uses.length; i += 1) { 161 try { 162 bcr = uses[i].getBoundingClientRect(); 163 } catch (ignore) { 164 // failed to get bounding rectangle of the use element 165 bcr = false; 166 } 167 href = 168 uses[i].getAttribute("href") || 169 uses[i].getAttributeNS(xlinkNS, "href") || 170 uses[i].getAttribute("xlink:href"); 171 if (href && href.split) { 172 url = href.split("#"); 173 } else { 174 url = ["", ""]; 175 } 176 base = url[0]; 177 hash = url[1]; 178 isHidden = 179 bcr && 180 bcr.left === 0 && 181 bcr.right === 0 && 182 bcr.top === 0 && 183 bcr.bottom === 0; 184 if (bcr && bcr.width === 0 && bcr.height === 0 && !isHidden) { 185 // the use element is empty 186 // if there is a reference to an external SVG, try to fetch it 187 // use the optional fallback URL if there is no reference to an external SVG 188 if ( 189 fallback && 190 !base.length && 191 hash && 192 !document.getElementById(hash) 193 ) { 194 base = fallback; 195 } 196 if (uses[i].hasAttribute("href")) { 197 uses[i].setAttributeNS(xlinkNS, "xlink:href", href); 198 } 199 if (base.length) { 200 // schedule updating xlink:href 201 xhr = cache[base]; 202 if (xhr !== true) { 203 // true signifies that prepending the SVG was not required 204 setTimeout( 205 attrUpdateFunc({ 206 useEl: uses[i], 207 base: base, 208 hash: hash, 209 }), 210 0, 211 ); 212 } 213 if (xhr === undefined) { 214 Request = createRequest(base); 215 if (Request !== undefined) { 216 xhr = new Request(); 217 cache[base] = xhr; 218 xhr.onload = onloadFunc(xhr); 219 xhr.onerror = onErrorTimeout(xhr); 220 xhr.ontimeout = onErrorTimeout(xhr); 221 xhr.open("GET", base); 222 xhr.send(); 223 inProgressCount += 1; 224 } 225 } 226 } 227 } else {
228 if (!isHidden) { 229 if (cache[base] === undefined) { 230 // remember this URL if the use element was not empty and no request was sent 231 cache[base] = true; 232 } else if (cache[base].onload) { 233 // if it turns out that prepending the SVG is not necessary, 234 // abort the in-progress xhr. 235 cache[base].abort(); 236 delete cache[base].onload; 237 cache[base] = true; 238 } 239 } else if (base.length && cache[base]) { 240 setTimeout( 241 attrUpdateFunc({ 242 useEl: uses[i], 243 base: base, 244 hash: hash, 245 }), 246 0, 247 ); 248 } 249 } 250 } 251 uses = ""; 252 inProgressCount += 1; 253 observeIfDone(); 254 }; 255 var winLoad; 256 winLoad = function () { 257 window.removeEventListener("load", winLoad, false); // to prevent memory leaks 258 tid = setTimeout(checkUseElems, 0); 259 }; 260 if (document.readyState !== "complete") { 261 // The load event fires when all resources have finished loading, which allows detecting whether SVG use elements are empty. 262 window.addEventListener("load", winLoad, false); 263 } else { 264 // No need to add a listener if the document is already loaded, initialize immediately. 265 winLoad(); 266 } 267 } 268})();
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.