Created
September 17, 2013 22:36
-
-
Save forivall/6601639 to your computer and use it in GitHub Desktop.
Requirejs bootstrap for userscripts
This file contains 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
;(function (body) { | |
var el = document.createElement('script'); | |
el.textContent = ';(' + body + ')();'; | |
document.body.appendChild(el); | |
return el; | |
})(function() { | |
(function(body) { | |
if (typeof 'require' !== 'undefined' && require !== null) { | |
var el = document.createElement('script'); | |
el.addEventListener('load', body); | |
el.setAttribute('src', '//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.8/require.min.js'); | |
} else { | |
body(); | |
} | |
})(function() { | |
// <-- | |
var usRequire = require.config({ | |
context: 'myUserscript', | |
"paths": { | |
"jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min" | |
} | |
}); | |
usRequire(['jquery'], function($) { | |
$.noop(); | |
}) | |
// --> | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment