2012-04-30 11:23:03 +00:00
|
|
|
/*\
|
2012-05-03 20:47:16 +00:00
|
|
|
title: $:/core/bootprefix.js
|
2012-04-30 11:23:03 +00:00
|
|
|
type: application/javascript
|
|
|
|
|
|
|
|
This file sets up the globals that need to be available when JavaScript modules are executed in the browser. The overall sequence is:
|
|
|
|
|
|
|
|
# BootPrefix.js
|
|
|
|
# <module definitions>
|
|
|
|
# Boot.js
|
|
|
|
|
|
|
|
See Boot.js for further details of the boot process.
|
|
|
|
|
2012-11-12 22:15:52 +00:00
|
|
|
\*/
|
2012-04-30 11:23:03 +00:00
|
|
|
|
|
|
|
// Set up $tw global for the browser
|
2012-11-15 10:40:03 +00:00
|
|
|
if(typeof(window) === "undefined") {
|
|
|
|
global.$tw = global.$tw || {}; // No `browser` member for the server
|
|
|
|
} else {
|
|
|
|
window.$tw = window.$tw || {browser: {}};
|
2012-04-30 11:23:03 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 10:40:03 +00:00
|
|
|
/*
|
|
|
|
Information about each module is kept in an object with these members:
|
|
|
|
moduleType: type of module
|
|
|
|
definition: object, function or string defining the module; see below
|
|
|
|
exports: exports of the module, filled in after execution
|
|
|
|
|
|
|
|
The `definition` can be of several types:
|
|
|
|
|
|
|
|
* An object can be used to directly specify the exports of the module
|
|
|
|
* A function with the arguments `module,require,exports` that returns `exports`
|
|
|
|
* A string function body with the same arguments
|
|
|
|
|
|
|
|
Each moduleInfo object is stored in two hashmaps: $tw.modules.titles and $tw.modules.types. The first is indexed by title and the second is indexed by type and then title
|
|
|
|
*/
|
|
|
|
$tw.modules = {
|
|
|
|
titles: {}, // hashmap by module name of moduleInfo
|
|
|
|
types: {} // hashmap by module type and then name of moduleInfo
|
|
|
|
};
|
2012-04-30 11:23:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Define a JavaScript tiddler module for later execution
|
|
|
|
moduleName: name of module being defined
|
|
|
|
moduleType: type of module
|
2012-11-15 10:40:03 +00:00
|
|
|
definition: module definition; see discussion above
|
2012-04-30 11:23:03 +00:00
|
|
|
*/
|
2012-11-15 10:40:03 +00:00
|
|
|
$tw.modules.define = function(moduleName,moduleType,definition) {
|
|
|
|
// Create the moduleInfo
|
|
|
|
var moduleInfo = {
|
|
|
|
moduleType: moduleType,
|
|
|
|
definition: definition,
|
|
|
|
exports: undefined
|
|
|
|
};
|
|
|
|
// Store the module in the titles hashmap
|
2012-11-14 11:23:43 +00:00
|
|
|
if(Object.prototype.hasOwnProperty.call($tw.modules.titles,moduleName)) {
|
|
|
|
console.log("Warning: Redefined module - " + moduleName);
|
|
|
|
}
|
2012-11-15 10:40:03 +00:00
|
|
|
$tw.modules.titles[moduleName] = moduleInfo;
|
|
|
|
// Store the module in the types hashmap
|
|
|
|
if(!Object.prototype.hasOwnProperty.call($tw.modules.types,moduleType)) {
|
|
|
|
$tw.modules.types[moduleType] = {};
|
|
|
|
}
|
|
|
|
if(Object.prototype.hasOwnProperty.call($tw.modules.types[moduleType],moduleName)) {
|
|
|
|
console.log("Warning: Redefined module - " + moduleName);
|
|
|
|
}
|
|
|
|
$tw.modules.types[moduleType][moduleName] = moduleInfo;
|
2012-04-30 11:23:03 +00:00
|
|
|
};
|
2012-10-12 18:01:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Define a tiddler
|
|
|
|
*/
|
|
|
|
$tw.preloadTiddlers = $tw.preloadTiddlers || [];
|
|
|
|
|
|
|
|
$tw.preloadTiddler = function(fields) {
|
|
|
|
$tw.preloadTiddlers.push(fields);
|
|
|
|
};
|
|
|
|
|