diff --git a/boot/boot.js b/boot/boot.js index 00bfde4e8..a43d5ffdd 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -674,7 +674,7 @@ Apply a callback to each module of a particular type */ $tw.modules.forEachModuleOfType = function(moduleType,callback) { var modules = $tw.modules.types[moduleType]; - $tw.utils.each(modules,function(element,title,object) { + $tw.utils.each(modules,function(element,title) { callback(title,$tw.modules.execute(title)); }); }; @@ -795,20 +795,63 @@ $tw.modules.define("$:/boot/tiddlerfields/list","tiddlerfield",{ Construct a wiki store object */ $tw.Wiki = function() { - this.tiddlers = {}; + var self = this, + tiddlers = {}; // Hashmap of tiddlers this.pluginTiddlers = []; // Array of tiddlers containing registered plugins, ordered by priority this.pluginInfo = {}; // Hashmap of parsed plugin content this.shadowTiddlers = {}; // Hashmap by title of {source:, tiddler:} + // Methods that need access to the private members + this.addTiddler = function(tiddler) { + if(!(tiddler instanceof $tw.Tiddler)) { + tiddler = new $tw.Tiddler(tiddler); + } + // Get the title + var title = tiddler.fields.title; + // Save the tiddler + if(title) { + tiddlers[title] = tiddler; + this.clearCache(title); + this.clearGlobalCache(); + this.enqueueTiddlerEvent(title); + } + }; + this.getTiddler = function(title) { + var t = tiddlers[title]; + if(t instanceof $tw.Tiddler) { + return t; + } else if(title !== undefined && $tw.utils.hop(self.shadowTiddlers,title)) { + return self.shadowTiddlers[title].tiddler; + } else { + return undefined; + } + }; + this.getAllTitles = function() { + var results = {}; + for(var title in tiddlers) { + results[title] = true; + } + return results; + }; + this.each = function(callback) { + for(var title in tiddlers) { + callback(tiddlers[title],title); + } + }; + this.tiddlerExists = function(title) { + return !!$tw.utils.hop(tiddlers,title); + }; + this.deleteTiddler = function(title) { + delete tiddlers[title]; + this.clearCache(title); + this.clearGlobalCache(); + this.enqueueTiddlerEvent(title,true); + }; }; -$tw.Wiki.prototype.addTiddler = function(tiddler) { - if(!(tiddler instanceof $tw.Tiddler)) { - tiddler = new $tw.Tiddler(tiddler); - } - if(tiddler.fields.title) { - this.tiddlers[tiddler.fields.title] = tiddler; - } -}; +// Dummy methods that will be filled in after boot +$tw.Wiki.prototype.clearCache = +$tw.Wiki.prototype.clearGlobalCache = +$tw.Wiki.prototype.enqueueTiddlerEvent = function() {}; $tw.Wiki.prototype.addTiddlers = function(tiddlers) { for(var t=0; t