Created
February 1, 2014 08:05
-
-
Save ashmind/8749472 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://gist.github.com/ashmind/8749472 | |
// jQuery plugin to load JS files from GitHub. | |
// NOT FOR PRODUCTION, use something like Bower instead. | |
// This is for quick iteration sites like CodePen or JSFiddle. | |
(function($) { | |
// this API requires blob SHA. get the SHA by requesting | |
// https://api.github.com/repos/:owner/:repo/contents/:path | |
$.loadScriptsFromGitHub = function(scripts, success) { | |
loadNextScript(scripts.slice(0), success || function() {}) | |
} | |
function loadNextScript(scripts, allSuccess) { | |
var script = scripts.pop(); | |
if (!script) { | |
allSuccess(); | |
return; | |
} | |
var fullUrl = 'https://api.github.com/repos/' | |
+ script.owner + '/' + script.repo | |
+ '/git/blobs/' + script.sha; | |
$.ajax(fullUrl, { | |
headers: { | |
Accept: 'application/vnd.github.v3.raw' | |
}, | |
success: function(scriptBody) { | |
eval.call(window, scriptBody); | |
loadNextScript(scripts, allSuccess); | |
} | |
}); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment