Skip to content

Instantly share code, notes, and snippets.

@abernier
Created February 12, 2012 16:36
Show Gist options
  • Save abernier/1809547 to your computer and use it in GitHub Desktop.
Save abernier/1809547 to your computer and use it in GitHub Desktop.
RequireJSUserScript
//
// A module that can greet (depends on speech)
//
define(['speech'], function (speech) {
return {
hi: function () {speech.say('hi!');}
}
});
// ==UserScript==
// @id requirejsuserscript
// @name RequireJSUserScript
// @author Antoine BERNIER (abernier)
// @version 0.0.1
// @description UserScript with requireJS
// ==/UserScript==
(function (d, cb) {
//
// RequireJS over here!
//
if (typeof window.requirejs === 'undefined') {
var s;
s = d.createElement('script');
s.src = 'https://raw.github.com/jrburke/requirejs/master/require.js';
s.onload = function () {
var s;
s = d.createElement('script');
s.textContent = '(' + cb.toString() + ')(requirejs);';
d.body.appendChild(s);
}
d.body.appendChild(s);
} else {
cb(requirejs)
}
}(document, function (require) {
require.config({
baseUrl: "https://raw.github.com/gist/1809547"
});
require(['index']);
}));
//
// Main
//
require(['greetings'], function(greetings) {
greetings.hi();
});
//
// A module that can speak
//
define({
say: function () {return console.log.apply(console, arguments);}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment