Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add public/receiver.js from transporter until i can figure out how to…

… reference it properly
  • Loading branch information...
commit 7043ad50aabcec83328466d71e954f0e15c6d967 1 parent 1e804e7
@deanlandolt authored
Showing with 68 additions and 1 deletion.
  1. +67 −0 public/receiver.js
  2. +1 −1  templates/Page.template
View
67 public/receiver.js
@@ -0,0 +1,67 @@
+/** A very lightweight implementation of CommonJS Asynchronous Module Definition
+ * (require.def) and
+ * require.ensure. This can only receive modules, it will not proactively attempt to load
+ * any modules, so you must leave the default transporter setting of
+ * resolveDeps on (true) to use this module receiver.
+ */
+(function(){
+ var factories = {},
+ modules = {};
+ function req(id){
+ var module = modules[id];
+ if(module){
+ return module;
+ }
+ if(!factories[id]){
+ throw new Error("Module " + id + " not found");
+ }
+ var factory = factories[id];
+ var args = factory.deps || (factory.length ? ["require", "exports", "module"] : []);
+ var exports = modules[id] = {};
+ for(var i = 0; i < args.length; i++){
+ var arg = args[i];
+ switch(arg){
+ case "require": arg = function(relativeId){
+ if(relativeId.charAt(0) === '.'){
+ relativeId = id.substring(0, id.lastIndexOf('/') + 1) + relativeId;
+ while(lastId !== relativeId){
+ var lastId = relativeId;
+ relativeId = relativeId.replace(/\/[^\/]*\/\.\.\//,'/');
+ }
+ relativeId = relativeId.replace(/\/\.\//g,'/');
+ }
+ return req(relativeId);
+ }; break;
+ case "exports": arg = exports; break;
+ case "module": var module = arg = {exports: exports}; break;
+ default: arg = req(arg);
+ }
+ args[i] = arg;
+ }
+
+ exports = factory.apply(this, args);
+ if(module && module.exports != modules[id]){
+ exports = module.exports;
+ }
+ if(exports){
+ return modules[id] = exports;
+ }
+ return modules[id];
+ }
+ define = function(id, deps, factory){
+ if(typeof deps == "function"){
+ factories[id] = deps;
+ }else{
+ (factories[id] = factory).deps = deps;
+ }
+ };
+
+ require = {
+ ensure: function(modules, callback){
+ for(var i = 0; i < modules.length; i++){
+ modules = req(modules[i]);
+ }
+ callback(req);
+ }
+ };
+})();
View
2  templates/Page.template
@@ -2,7 +2,7 @@
<title>{{pageName}}</title>
<link rel="stylesheet" href="/css/common.css" />
<link rel="stylesheet" href="/css/wikiContent.css" />
- <script src="/lib/transporter/receiver.js"></script>
+ <script src="/receiver.js"></script>
<script src="/lib/monitor.js"></script>
<body>
<div id="headerContainer"><span class="pageName">{{pageName}}<span></div>
Please sign in to comment.
Something went wrong with that request. Please try again.