Last active
May 11, 2018 18:31
-
-
Save devonwaldon/0defc300631f73dadc7ed678a44758ae to your computer and use it in GitHub Desktop.
Fix the case of a string throughout the DOM to deal with CSS 'transform: uppercase'.
This file contains hidden or 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
function getNodesThatContain(text) { | |
var textNodes = $('#page').find(':not(iframe, script)') | |
.contents().filter( | |
function () { | |
return (this.nodeType == 3 && this.textContent.indexOf(text) > -1); | |
}); | |
return textNodes.parent(); | |
} | |
function forceTextNodeCase(proper_text) { | |
var nodes = getNodesThatContain(proper_text).each(function () { | |
this.childNodes.forEach(function (node) { | |
if (node.nodeType === 3) { // text node found, do the replacement | |
var wrappers = node.data.split(proper_text); | |
var index = 1; | |
wrappers.forEach(function (textOnly) { | |
node.parentNode.insertBefore(document.createTextNode(textOnly), node); | |
if (index !== wrappers.length) { | |
var temp = document.createElement('span'); | |
temp.setAttribute('style', 'text-transform:none!important;'); | |
temp.innerHTML = proper_text; | |
node.parentNode.insertBefore(temp, node); | |
} | |
index ++; | |
}); | |
node.parentNode.removeChild(node); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment