Last active
February 18, 2016 09:30
-
-
Save matori/785c6e33d4f8415dad66 to your computer and use it in GitHub Desktop.
Lettering text mixin for Jade
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
.fakeBreak::after { | |
white-space: pre; | |
content: "\000a"; | |
} |
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
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment