Last active
October 1, 2016 16:34
-
-
Save lucamug/559928a374b9d103719152abe4d36cf7 to your computer and use it in GitHub Desktop.
Minimum Font Size Checker http://coding-and-design.blogspot.de/2016/10/minimum-font-size-checker.html
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
var 凸 = (function(凸) { | |
"use strict"; | |
var W = window, | |
D = document, | |
minFontSize, | |
floatMinFontSize, | |
newColor, | |
walkDOM = function (node, func) { | |
if (node.nodeType === 1) { | |
func(node); | |
} | |
node = node.firstChild; | |
while(node) { | |
walkDOM(node,func); | |
node = node.nextSibling; | |
} | |
}, | |
markElement = function(node) { | |
var min = minFontSize || "14px"; | |
var fontSize; | |
if (! node.getAttribute("sfc-originalStyle")) { | |
fontSize = W.getComputedStyle(node, null).getPropertyValue("font-size"); | |
if (parseFloat(fontSize) < floatMinFontSize) { | |
node.setAttribute("sfc-originalStyle", node.getAttribute("style")); | |
} | |
} | |
}, | |
resetElement = function(node) { | |
if (node.getAttribute("sfc-originalStyle")) { | |
if (node.getAttribute("sfc-originalStyle") === "null") { | |
node.removeAttribute("style"); | |
} else { | |
node.setAttribute("style", node.getAttribute("sfc-originalStyle")); | |
} | |
node.removeAttribute("sfc-originalStyle"); | |
} | |
}, | |
activateElement = function(node) { | |
if (node.getAttribute("sfc-originalStyle")) { | |
node.style.fontSize = minFontSize; | |
node.style.color = newColor; | |
} | |
}; | |
凸.SmallFontChecker = { | |
highlight: function(size, color) { | |
minFontSize = size || "14px"; | |
floatMinFontSize = parseFloat(minFontSize); | |
newColor = color || "rgba(200, 0, 255, 1)"; | |
walkDOM(D.body, markElement); | |
walkDOM(D.body, activateElement); | |
}, | |
reset: function() { | |
walkDOM(D.body, resetElement); | |
}, | |
}; | |
return 凸; | |
}(凸 || {})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Documentation here: http://coding-and-design.blogspot.de/2016/10/minimum-font-size-checker.html