3

I'm having a lot of JavaScript on my page and I'm using typekit. In order to make my page work correctly (grid and stuff) I'm using the new typekit font events.

It's simply a try and catch statement that checks if fonts get loaded or not. However somehow I'm not getting it. I'm calling the setGrid() function if typekit fonts are loaded, but e.g. iPad or iPhone doesn't support that yet and so my page doesn't get properly shown when I don't call the setGrid() function.

Anyway, I want to call the function in the error statement as well, so if the page is called on the iPhone, the page works without webfonts as well.

try {
 Typekit.load({
  loading: function() { },
  active: function() { setGrid(); },
  inactive: function() { }
 })
} catch(e) {
 alert('error'); //works
 setGrid(); //doesn't get called
}

However, the alert works, the setGrid() function doesn't get called. Any ideas?

edit: the function looks like that:

var setGrid = function () {
 $('#header, #footer').fadeIn(500);
 return $("#grid").vgrid({
  easeing: "easeOutQuint",
  time: 800,
  delay: 60
 });
};
matt
  • 42,713
  • 103
  • 264
  • 397

3 Answers3

3

Try making it "real" function, like this:

function setGrid() {
  $('#header, #footer').fadeIn(500);
  return $("#grid").vgrid({
    easeing: "easeOutQuint",
    time: 800,
    delay: 60
  });
};
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
2

The function does get called, but it just doesn't work as you expected causing you to think that it isn't getting called. You can see that it is getting called by adding an alert as the first line of setGrid.

jsfiddle link

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
  • Yep. Perhaps he is confused by the fact that the execution stops at the alert until after then alert is closed. _Then_ it continues, running `setGrid()` after. – Alex Wayne Nov 20 '10 at 20:58
  • no I'm not confused by the alert, i set the alert just to show that the alert() gets called but my function doesn't work. i edited my post! – matt Nov 21 '10 at 08:10
1

Can you:

  • try/catch around setGrid, too
  • alert after setGrid to confirm it's getting through setGrid
icyrock.com
  • 27,952
  • 4
  • 66
  • 85
  • well the alert after the setGrid() doesn't get called! if i set it before the setGrid() call the alert() does work! – matt Nov 21 '10 at 07:55