2012-05-31 3 views
0
Radiant::loadCSS = (fn, scope) -> 
    head = document.getElementsByTagName("head")[0] 
    link = document.createElement("link") 
    link.setAttribute "href", "/" + ri.context + "/css/" + @obj + ".css" 
    link.setAttribute "rel", "stylesheet" 
    link.setAttribute "type", "text/css" 
    sheet = undefined 
    cssRules = undefined 
    if "sheet" of link 
    sheet = "sheet" 
    cssRules = "cssRules" 
    else 
    sheet = "styleSheet" 
    cssRules = "rules" 
    timeout_id = setInterval(-> 
    try 
     if link[sheet] and link[sheet][cssRules].length 
     clearInterval timeout_id 
     clearTimeout timeout_id 
     fn.call scope or window, true, link #LINE THAT ERRORS OUT!!! 
    #finally 
    , 10) 
    timeout_id = setTimeout(-> 
    clearInterval timeout_id 
    clearTimeout timeout_id 
    head.removeChild link 
    fn.call scope or window, false, link 
    , 15000) 
    head.appendChild link 
    link 

Так выше мой перевод функции рваного здесь: Dynamically loading css file using javascript with callback without jQueryкофе-сценарий попытаться поймать неудачу в IE8

Когда я это имел в прямом JavaScript он работал большим, но версия кофе дает мне проблемы в ie8 'fn' is null or not an object

Вот тонированное Javascript для этого раздела:

timeout_id = setInterval(function() { 
    try { 
    if (link[sheet] && link[sheet][cssRules].length) { 
     clearInterval(timeout_id); 
     clearTimeout(timeout_id); 
     return fn.call(scope || window, true, link); //ERROR LINE!!! 
    } 
    } catch (_error) {} 
}, 10); 

Во всяком случае я новичок в try и catch и просто не понимаю, что здесь происходит. Спасибо заранее всем!

ответ

1

Я думаю, что это связано не только с попыткой/уловкой, но и с этим по какой-либо причине, fn не определяется при выполнении обратного вызова (как говорит ошибка). Вы уверены, что fn передано в loadCSS в тех случаях, когда вы получите сообщение об ошибке?

+0

oh duh. На этот раз я не прошел функцию обратного вызова. – Fresheyeball

Смежные вопросы