mirror of
https://github.com/Mibew/topcoat_icons.git
synced 2025-03-22 21:51:32 +03:00
43 lines
1.5 KiB
JavaScript
Executable File
43 lines
1.5 KiB
JavaScript
Executable File
var IcomaticUtils = (function() {
|
|
return {
|
|
fallbacks: [{ from: 'laptop', 'to': '' },{ from: 'phone', 'to': '' }],
|
|
substitute: function(el) {
|
|
var curr = el.firstChild;
|
|
var next, alt;
|
|
var content;
|
|
while (curr) {
|
|
next = curr.nextSibling;
|
|
if (curr.nodeType === Node.TEXT_NODE) {
|
|
content = curr.nodeValue;
|
|
for (var i = 0; i < IcomaticUtils.fallbacks.length; i++) {
|
|
content = content.replace( IcomaticUtils.fallbacks[i].from, function(match) {
|
|
alt = document.createElement('span');
|
|
alt.setAttribute('class', 'icomatic-alt');
|
|
alt.innerHTML = match;
|
|
el.insertBefore(alt, curr);
|
|
return IcomaticUtils.fallbacks[i].to;
|
|
});
|
|
}
|
|
alt = document.createTextNode(content);
|
|
el.replaceChild(alt, curr);
|
|
}
|
|
curr = next;
|
|
}
|
|
},
|
|
run: function(force) {
|
|
force = typeof force !== 'undefined' ? force : false;
|
|
var s = getComputedStyle(document.body);
|
|
if (s.hasOwnProperty('webkitFontFeatureSettings')
|
|
|| s.hasOwnProperty('mozFontFeatureSettings')
|
|
|| s.hasOwnProperty('msFontFeatureSettings')
|
|
|| s.hasOwnProperty('oFontFeatureSettings')
|
|
|| s.hasOwnProperty('fontFeatureSettings'))
|
|
if (!force)
|
|
return;
|
|
var els = document.querySelectorAll('.icomatic');
|
|
for (var i = 0; i < els.length; i++)
|
|
IcomaticUtils.substitute(els[i]);
|
|
}
|
|
} // end of object
|
|
} // end of fn
|
|
)() |