Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
*.pid
node_modules
pids
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = ('at', require('./lib/yabble'))
38 changes: 27 additions & 11 deletions lib/yabble.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
_timeoutLength = 20000,
_mainProgram;



var head = document.getElementsByTagName('head')[0];

Expand Down Expand Up @@ -130,7 +131,10 @@

// Takes a module's ID and resolves a URI according to the module root path
var resolveModuleUri = function(moduleId) {
if (moduleId.charAt(0) != '.') {
if (/^http(s?):\/\//.test(moduleId)) {
return moduleId+'.js';
}
else if (moduleId.charAt(0) != '.') {
return _moduleRoot+moduleId+'.js';
}
else {
Expand Down Expand Up @@ -183,17 +187,17 @@
// relative require()s
var createRequireFunc = function(refPath) {
var require = function(relModuleId) {
var moduleId = resolveModuleId(relModuleId, refPath),
module = getModule(moduleId);
var moduleId = resolveModuleId(relModuleId, refPath);
var module = getModule(moduleId);

if (!module) {
throw "Module not loaded";
}
else if (module.error) {
/*else if (module.error) {
throw "Error loading module";
}
}*/

if (!module.exports) {
if (!module.exports && !module.error) {
module.exports = {};
var moduleDir = moduleId.substring(0, moduleId.lastIndexOf('/')+1),
injects = module.injects,
Expand All @@ -207,7 +211,7 @@
args.push(module.exports);
}
else if (injects[i] == 'module') {
args.push(module.module);
args.push(module);
}
}

Expand Down Expand Up @@ -398,6 +402,8 @@
fireCallbacks();
}
}

// head.removeChild(scriptEl);
};

if (useStandard) {
Expand Down Expand Up @@ -453,9 +459,17 @@
// Set the uri which forms the conceptual module namespace root
Yabble.setModuleRoot = function(path) {
if (!(/^http(s?):\/\//.test(path))) {
var href = window.location.href;
href = href.substr(0, href.lastIndexOf('/')+1);
path = combinePaths(path, href);
var href = location.protocol+'//'+location.host;
if (path.charAt(0) !== '/') {
href += location.pathname;
path = combinePaths(
path,
href
);
}
else {
path = href+path;
}
}

if (path.length && path.charAt(path.length-1) != '/') {
Expand Down Expand Up @@ -558,9 +572,11 @@
};

Yabble.reset();

Yabble._modules = _modules;

// Export to the require global
window.require = Yabble;
})(function(code) {
return (window.eval || eval)(code, null);
});
});
17 changes: 17 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
This is a small node.js server, so that you can test Yabble on your OS without using the file:/// protocol.
You need to
- install node.js (nodejs.org)
- install node package manager (npmjs.org)
- Type: npm install connect
- Type: node server.js ROOTDIR &
- Go to http://localhost:3000/index.html
*/

var connect = require('connect')

dir = process.argv[2]

connect(
connect.static(dir)
).listen(3000)