Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Provide local CSS when external CDN fails #363

Closed
wants to merge 1 commit into from

Conversation

ryanjohara
Copy link
Contributor

Fixes #352

Signed-off-by: Ryan O'Hara oharar@email.chop.edu

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling f98b8f8 on ryanjohara:issue-239 into 1588a48 on cbmi:master.

var local_bootstrap = document.createElement('link');
local_bootstrap.setAttribute('rel', 'stylesheet');
local_bootstrap.setAttribute('type', 'text/css');
local_bootstrap.setAttribute('href', '/static/stylesheets/css/' + cssStyles[cs]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be chained like this:

var local_bootstrap = document.createElement('link');
    .setAttribute('rel', 'stylesheet');
    .setAttribute('type', 'text/css');
    .setAttribute('href', '/static/stylesheets/css/' + cssStyles[cs]);

@ryanjohara ryanjohara force-pushed the issue-239 branch 2 times, most recently from e55401e to b3b997a Compare September 10, 2014 15:02
Fixes chop-dbhi#352

Signed-off-by: Ryan O'Hara <oharar@email.chop.edu>
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 10a273b on ryanjohara:issue-239 into 1588a48 on cbmi:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 10a273b on ryanjohara:issue-239 into 1588a48 on cbmi:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 10a273b on ryanjohara:issue-239 into 1588a48 on cbmi:master.


}

var cssStyles = ['bootstrap.css', 'bootstrap-responsive.css', 'font-awesome.css'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the cssLoaded method can be removed and this code should be simplified into:

var requiredCSS = ['bootstrap.css', 'bootstrap-responsive.css', 'font-awesome.css'],
    loadedCSS = document.styleSheets,
    isLoaded;

for (var i = 0; i < requiredCSS.length; i++) {
    isLoaded = _.some(loadedCSS, function(sheet) { 
        return sheet['href'].indexOf(requiredCSS[i]) >= 0; 
    });

    if (isLoaded) continue;

    var localLink = document.createElement('link');
        .setAttribute('rel', 'stylesheet');
        .setAttribute('type', 'text/css');
        .setAttribute('href', '/static/stylesheets/css/' + requiredCSS[i]);
    document.getElementsByTagName('head')[0].appendChild(localLink);
}

@ryanjohara
Copy link
Contributor Author

The original fix is actually broken. The test I used must not have been comprehensive. I was also unable to get the .setAttribute chaining to work - ugh. I'm going to close this PR and look into another solution.

@ryanjohara ryanjohara closed this Sep 10, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add fallback code for libraries loaded via CDN
3 participants