1/** 2 * icons.js | éé¦å±å¾æ 弿¥å è½½ 3 * 4 * æå¡ç«¯ icon() 对éé¦å± SVG 徿 è¾åº <svg class="icon" data-icon="ns:key"> å ä½ç¬¦ï¼ 5 * æ¬èæ¬æå½åç©ºé´æåæå»ºæçæç js/icons/{ns}.jsonï¼æååå使¿æ¢ä¸ºå®æ´å è SVGï¼ 6 * æç» DOM ä¸å ¨éå èä¸è´ï¼ç°æ CSS é©åï¼æç´¢ä¸æãè忏åãchat çè²çï¼ä¸åå½±åã 7 * é¦å±å ³é®å¾æ ï¼æç´¢ãèåãleftbar/rightbarãarrow-leftï¼ç±æ¨¡æ¿å èï¼ä¸ç»è¿æ¬èæ¬ã 8 */ 9(function () { 10 'use strict'; 11 12 const nodes = Array.prototype.slice.call(document.querySelectorAll('svg.icon[data-icon]')); 13 if (nodes.length === 0) { 14 return; 15 } 16 17 const groups = {}; 18 nodes.forEach((node) => { 19 const key = node.getAttribute('data-icon'); 20 const idx = key.indexOf(':'); 21 if (idx < 1) { 22 return; 23 } 24 const ns = key.slice(0, idx); 25 if (!groups[ns]) { 26 groups[ns] = []; 27 } 28 groups[ns].push(node); 29 }); 30 31 const script = document.currentScript; 32 const version = (script && script.getAttribute('data-version')) || ''; 33 const root = (typeof ctx !== 'undefined' && ctx.root) || '/'; 34 35 Object.keys(groups).forEach((ns) => { 36 const url = root + 'js/icons/' + ns + '.json' + (version ? '?v=' + version : ''); 37 fetch(url) 38 .then((res) => { 39 if (!res.ok) { 40 throw new Error('HTTP ' + res.status); 41 } 42 return res.json(); 43 }) 44 .then((data) => { 45 const set = data && data[ns]; 46 groups[ns].forEach((node) => { 47 const key = node.getAttribute('data-icon'); 48 const svg = set && set[key]; 49 if (typeof svg === 'string' && svg.length > 0) { 50 node.outerHTML = svg; 51 } else { 52 console.warn('[stellar] icon not found: ' + key); 53 } 54 }); 55 }) 56 .catch((err) => { 57 console.warn('[stellar] icons load failed: ' + ns, err); 58 }); 59 }); 60})();
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.