1148 posts
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
fillerspace says

So here’s my problem. I have Cufon font replacement which works fine. When the page loads, Cufon works as expected:

Cufon.replace('a.prettyFont', { fontFamily: 'First Font', hover: true }); 

All links with the prettyFont class are replaced, with hover functionality enabled. The problem comes when I replace the Cufon font after page load using this code:

$.getScript('newfont.js', function() {
    Cufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: true });
    Cufon.refresh();
});

The new font shows up, but when I hover over any of the Cufon elements, it changes back to the old font. It seems that the hover option binds to the mouseover or mouseenter event to switch to the hover version of the original font, but it doesn’t change when you change the font. I was able to work around it using jQuery clone (cycle through each element Cufon replaced, swap out all HTML inside each element for just the text(), and then use jQuery replaceWith() to swap each item for its clone(). But that seems a little roundabout.

Is there an easier or more efficient way?

140 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
weblusive says

I am not sure, but try using jquery’s live() function. There are always issues with this cufon font dynamic replacement methods, hope this will be of little help.

2043 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Provided great feedback to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+9 more
revaxarts says
Try
Cufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: 'true' });
1148 posts
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
fillerspace says

Try
Cufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: 'true' });

That’s the same as the code I’m using…it replaces the font, but the hover state is still the old font.

2043 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Provided great feedback to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+9 more
revaxarts says


Try
Cufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: 'true' });
That’s the same as the code I’m using…it replaces the font, but the hover state is still the old font.

Did you noticed the apostrophe around true ?

1148 posts
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
fillerspace says



Try
Cufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: 'true' });
That’s the same as the code I’m using…it replaces the font, but the hover state is still the old font.
Did you noticed the apostrophe around true ?

Ah…I missed that. I tried it with the single quotes, and it is still the same. I guess I’ll have to stick with the jQuery clone hack:

$.getScript('newfont.js', function() {
    $('a.prettyFont').each(function() {
        $(this).html($(this).text());
        var clone = $(this).clone();
        $(this).replaceWith(clone);
    });
    Cufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: true });
    Cufon.refresh();
});
by
by
by
by
by
by