Skip to content

Instantly share code, notes, and snippets.

@Zoramite
Created November 16, 2011 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Zoramite/1371054 to your computer and use it in GitHub Desktop.
Save Zoramite/1371054 to your computer and use it in GitHub Desktop.
jQuery plugin definition with optional support for RequireJS
<!doctype html>
<html lang="en">
<head>
<title>Test Execute Order</title>
</head>
<body>
<script src="//requirejs.org/docs/release/1.0.1/minified/require.js"></script>
<script>
require.config({
paths: {
'jquery': '//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min'
}
});
</script>
<script>
require(['scripts/test1'], function(){
console.log('In index1.')
});
</script>
</body>
<!doctype html>
<html lang="en">
<head>
<title>Test Execute Order</title>
</head>
<body>
<script src="//requirejs.org/docs/release/1.0.1/minified/require.js"></script>
<script>
require.config({
paths: {
'jquery': '//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min'
}
});
</script>
<script>
require(['scripts/test2'], function(){
console.log('In index2.')
});
</script>
</body>
(function(factory) {
if (typeof exports === 'object') {
// Node/CommonJS
factory();
} else if (typeof define === 'function' && define.amd) {
// AMD
define('test', [], factory);
} else {
// Browser globals
factory();
}
}(function() {
console.log('In test1.');
}));
(function(factory) {
if (typeof exports === 'object') {
// Node/CommonJS
factory(require('jquery'));
} else if (typeof define === 'function' && define.amd) {
// AMD
define('test', [ 'jquery' ], factory);
} else {
// Browser globals
factory(jQuery);
}
}(function($) {
console.log('In test2.')
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment