davatron5000/Lettering.js — Issue #28: Function to filter which elements will be "lettered"
Author: icalvo
Created: 2012-03-06 09:40:00+00:00
State: open

This would help optimize performance. For example, let's say I want to style the first word and first letter of every paragraph. Currently there's no other way apart from:

```javascript
("p").lettering('words').children('span').lettering();
```

And then styling p .word1 and p .char1. That, of course, would create a pretty huge DOM if you have an amount of text in the page.

By adding an optional function parameter we can limit which caracters/lines/words are "lettered". The function should be passed the original text, the current caracter/line/word and its index in the sequence, and return a boolean saying whether you want it to be spanned or not.

```javascript
function onlyfirst(phrase, element, index) {
return (index == 0);
}

("p").lettering('words', onlyfirst).children('span').lettering(onlyfirst);
```
This would convert:

```html

Lorem ipsum...

```

Into:

```html

Lorem

ipsum...

```

This would allow also for automatic kerning correction of given letters or even letter groups along whole texts, and probably lots of other uses that now are forbidden due to the DOM growing excessively if you apply lettering to the entire page.

I know that your codebase is absolutely minimal but I think that this single addition is fairly simple and would add immense flexibility.