-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load fa svg files & make faIconExists efficient
- Loading branch information
Showing
2 changed files
with
54 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
var faIconExists = (faType, name, returnIcon, iconStyle) => { | ||
const tempElement = document.createElement(`i`); | ||
|
||
tempElement.classList.add(`${faType}`); | ||
tempElement.classList.add(`fa-${name}`); | ||
|
||
tempElement.style.display = `none`; | ||
tempElement.style.position = `absolute` | ||
|
||
document.body.appendChild(tempElement); | ||
|
||
const exists = window.getComputedStyle(tempElement, '::before').getPropertyValue('content') != `none`; | ||
|
||
tempElement.remove(); | ||
|
||
if(returnIcon && exists) { | ||
tempElement.style.display = ``; | ||
tempElement.style.position = ``; | ||
|
||
if(iconStyle) for(const key of Object.keys(iconStyle)) { | ||
tempElement.style[key] = iconStyle[key]; | ||
} | ||
|
||
return tempElement; | ||
} else return exists; | ||
if(faType && typeof faType == `string`) { | ||
const exists = scripts.misc.fa[faType]?.querySelector(`glyph[glyph-name="${name}"]`) ? true : false; | ||
|
||
if(exists && returnIcon) { | ||
const tempElement = document.createElement(`i`); | ||
console.log(`objToDOM: icon2 (${faType} / ${name})`) | ||
tempElement.className = `${faType} fa-${name}`; | ||
|
||
if(iconStyle) for(const key of Object.keys(iconStyle)) { | ||
tempElement.style[key] = iconStyle[key]; | ||
} | ||
|
||
return tempElement; | ||
} else return exists; | ||
} else { | ||
const fallbacks = Array.isArray(faType) && faType || [`fas`, `far`, `fab`] | ||
|
||
const found = fallbacks.map(f => faIconExists(f, name, returnIcon, iconStyle)); | ||
|
||
console.log(`objToDOM: icon3 (${faType} / ${name})`, found) | ||
|
||
return found.find(Boolean); | ||
} | ||
} |