views:

752

answers:

1

Hi everybody,

I'm using Cufon to load some nice fonts with javascript. And, as I have many tags, I use the following instruction to replace all the tags:

Cufon.replace('*', { fontFamily: 'MyFont' });

But, I recently decided to exclude some tag classes from the replacement. Is there an instruction like:

Cufon.exclude('TheClassToExclude');

?

Thank you very much,

Regards.

+1  A: 

Using * as a selector is a pretty bad idea. For one, it's going to take forever to load the page and run the script, as Cufon blocks the browser while it does the drawing. Secondly, your text won't be visibly selectable, depending on the browser. (At this time, FF3.6 doesn't show selections on Cufon text)

But to answer your question, you can tell cufon to set on certain classes, just add the classes to the elements you want drawn by Cufon, rather than the other way around.

Cufon.replace('h2.cufon', { fontFamily: 'MyFont' });

Edit:

Just discovered that if you're using a Javascript library like jQuery, you can use a different selector to exclude elements.

Cufon.replace('h2:not(.nocufon)', { fontFamily: 'MyFont' });

This would replace all of the H2 elements with the Cufon text, except those with the nocufon class.

S Pangborn
I would say that that's a pretty bad idea could be understatement of the day. I agree with you completely, doing cufon (or anything like it) on all of your text is an absolutely horrible idea.
Charles Boyung
Quite true. Note that I've added another way to accomplish what you described, OP.
S Pangborn