Skip to content

Instantly share code, notes, and snippets.

@derek
Last active December 18, 2015 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derek/5860448 to your computer and use it in GitHub Desktop.
Save derek/5860448 to your computer and use it in GitHub Desktop.
reqYUIre.js - An experiment loading and using AMD'ish modules with YUI
<!DOCTYPE html>
<html>
<head>
<script src='http://yui.yahooapis.com/3.10.2/build/yui/yui-min.js'></script>
<script src='reqyuire.js'></script>
</head>
<body>
<script>
require.config({
paths: {
jquery: 'http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js',
underscore: 'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js'
}
});
define('foo', ['jquery', 'underscore'], function () {
console.log('foo loaded');
});
define('bar', function () {
console.log('bar loaded');
});
require(['foo', 'bar', 'scrollview'], function (Y) {
console.log('YUI version: ', YUI().version);
console.log('jQuery version: ', $().jquery);
console.log('YUI ScrollView exists? ', Boolean(Y.ScrollView));
console.log('Underscore exists? ', Boolean(_));
});
</script>
</body>
</html>
;(function () {
var paths;
var require = function (dependents, callback) {
var Y = YUI({
modules: paths
});
var args = dependents.concat([callback]);
Y.use.apply(Y, args);
};
require.config = function (config) {
if (config.paths) {
paths = config.paths;
}
};
var define = function (name, deps, callback) {
if (callback === undefined) {
callback = deps;
}
YUI.add(name, callback, '', {requires:deps});
};
window.require = require;
window.define = define;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment