Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ttepasse
Created June 28, 2011 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttepasse/1052411 to your computer and use it in GitHub Desktop.
Save ttepasse/1052411 to your computer and use it in GitHub Desktop.
// 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