Created
June 28, 2011 22:30
-
-
Save ttepasse/1052411 to your computer and use it in GitHub Desktop.
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
// A weird mixture between functional and imperative. | |
// I like putting some lambdas into their own functions, for some | |
// degree of self-documenting and readability later on. | |
// ... | |
var nodes, fontnames, firstpick, | |
result = false; | |
function isEditableTextnode(node) { | |
return isEditable(node) && node.nodeType == Node.TEXT_NODE; | |
} | |
// original parameter order makes currying unusable | |
function node2fontname(node) { | |
return getEffectiveValue(node, "fontname"); | |
} | |
var nodes = collectAllEffectivelyContainedNodes(getActiveRange(), isEditableTextnode); | |
// Pattern matching for the poor ... | |
if (nodes.length <= 1) { | |
return result; | |
} else { | |
fontnames = nodes.map(node2fontname); | |
firstpick = fontnames.shift(); | |
result = fontnames.some(function (nextpick) { | |
// some is short-circuiting. Should be. | |
return nextpick !== firstpick; | |
}); | |
} | |
return result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment