I am new to RequireJS, so this might be a stupid question!
I am using require-jquery.
I want to load the DataJS library as a module. It is a standalone library and does not depend on jQuery.
This is what my HTML file start.htm looks like:
<html>
<head>
</head>
<body>
<script type="text/javascript" src="Scripts/Loader.js"></script>
</body>
</html>
This is what the Loader.js file looks like:
(function (window, undefined) {
var script = document.createElement('script');
script.async = true;
script.src = "scripts/require-jquery.js";
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(script, entry);
script.onload = script.onreadystatechange = function () {
var rdyState = script.readyState;
if (!rdyState || /complete|loaded/.test(script.readyState)) {
require([
"jquery",
"scripts/datajs-1.1.0"
],
function (jQueryHandle, odata) {
alert(odata);
});
script.onload = null;
script.onreadystatechange = null;
}
};
})(window);
This is my file structure:
Project
|
|----- start.htm
|
|----- Scripts
|
|----- datajs-1.1.0.js
|
|----- require-jquery.js
|
|----- loader.js
I think that the datajs library supports AMD, because this is what the library looks like:
(function (window, undefined) {
var datajs = window.datajs || {};
var odata = window.OData || {};
// AMD support
if (typeof define === 'function' && define.amd) {
define('datajs', datajs);
define('OData', odata);
} else {
window.datajs = datajs;
window.OData = odata;
}
/* -------------------- */
})(this);
What am I doing wrong?