Skip to content

Instantly share code, notes, and snippets.

@mjschranz
Created May 17, 2012 19:47
Show Gist options
  • Select an option

  • Save mjschranz/2721194 to your computer and use it in GitHub Desktop.

Select an option

Save mjschranz/2721194 to your computer and use it in GitHub Desktop.

Revisions

  1. mjschranz created this gist May 17, 2012.
    30 changes: 30 additions & 0 deletions CSS Loader
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    var scriptElement,
    interval;

    checkFn = checkFn || function(){
    return !!scriptElement;
    };

    function runCheckFn() {
    interval = setInterval(function(){
    if( checkFn() ){
    clearInterval( interval );
    if( callback ){
    callback();
    }
    }
    }, CSS_POLL_INTERVAL );
    }

    url = fixUrl( url );

    if( !checkFn() ){
    scriptElement = document.createElement( "link" );
    scriptElement.rel = "stylesheet";
    scriptElement.onload = runCheckFn;
    scriptElement.href = url;
    document.head.appendChild( scriptElement );
    }
    else if( callback ){
    callback();
    }