Skip to content

Instantly share code, notes, and snippets.

@matori
Last active February 18, 2016 09: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 matori/785c6e33d4f8415dad66 to your computer and use it in GitHub Desktop.
Save matori/785c6e33d4f8415dad66 to your computer and use it in GitHub Desktop.
Lettering text mixin for Jade
.fakeBreak::after {
white-space: pre;
content: "\000a";
}
mixin lettering(element, text, labelId)
-
labelId = labelId || (function() {
var date = new Date();
var time = date.getTime();
var ret = Math.floor(Math.random() * time).toString().slice(0, 10);
return "lettering-label-" + ret;
})();
#{element}(aria-labelledby="#{labelId}")&attributes(attributes).lettering
span.visuallyHidden(id="#{labelId}")= text
span(aria-hidden="true").lettering-inner
if typeof text === "string"
each v, i in text.split("")
span.lettering-letter(class="is-letter-#{i + 1}")= v
else if Array.isArray(text)
each v, i in text
each w, j in v
span.lettering-letter(class="is-letter-#{j + 1}")= w
if i + 1 < text.length
span.fakeBreak
/* http://snook.ca/archives/html_and_css/hiding-content-for-accessibility */
.visuallyHidden {
position: absolute;
margin: -1px;
padding: 0;
border: 0;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment