diff --git a/core/boot.js b/core/boot.js index d7085b390..2e43c54a6 100644 --- a/core/boot.js +++ b/core/boot.js @@ -241,8 +241,27 @@ $tw.modules.registerTypedModule = function(name,moduleType,moduleExports) { Register all the module tiddlers that have a module type */ $tw.modules.registerTypedModules = function() { - for(var title in $tw.wiki.tiddlers) { - var tiddler = $tw.wiki.getTiddler(title); + var title, tiddler; + // Execute and register any modules from plugins + for(title in $tw.wiki.pluginTiddlers) { + tiddler = $tw.wiki.getTiddler(title); + if(!(title in $tw.wiki.tiddlers)) { + if(tiddler.fields.type === "application/javascript" && tiddler.fields["module-type"] !== undefined) { + // Execute the module + var source = [ + "(function(module,exports,require) {", + tiddler.fields.text, + "})" + ]; + $tw.modules.define(tiddler.fields.text,tiddler.fields["module-type"],window.eval(source.join(""))); + // Register the module + $tw.modules.registerTypedModule(title,tiddler.fields["module-type"],$tw.modules.execute(title)); + } + } + } + // Register any modules in ordinary tiddlers + for(title in $tw.wiki.tiddlers) { + tiddler = $tw.wiki.getTiddler(title); if(tiddler.fields.type === "application/javascript" && tiddler.fields["module-type"] !== undefined) { $tw.modules.registerTypedModule(title,tiddler.fields["module-type"],$tw.modules.execute(title)); } @@ -370,10 +389,37 @@ $tw.Wiki.prototype.addTiddlers = function(tiddlers,isShadow) { } }; +/* +Install tiddlers contained in plugin tiddlers +*/ +$tw.Wiki.prototype.installPlugins = function() { + this.plugins = {}; // Hashmap of plugin information by title + this.pluginTiddlers = {}; // Hashmap of constituent tiddlers from plugins by title + // Collect up all the plugin tiddlers + for(var title in this.tiddlers) { + var tiddler = this.tiddlers[title]; + if(tiddler.fields.type === "application/x-tiddlywiki-plugin") { + // Save the plugin information + var pluginInfo = this.plugins[title] = JSON.parse(tiddler.fields.text); + // Extract the constituent tiddlers + for(var t=0; t=5.0.0", + "source": "http://tiddlywiki.com/core/plugins/zoomigator" + } +} diff --git a/core/modules/macros/zoomer.js b/core/plugins/zoomigator/zoomigator.js similarity index 84% rename from core/modules/macros/zoomer.js rename to core/plugins/zoomigator/zoomigator.js index cbdc95652..a8fae4355 100644 --- a/core/modules/macros/zoomer.js +++ b/core/plugins/zoomigator/zoomigator.js @@ -1,5 +1,5 @@ /*\ -title: $:/core/modules/macros/zoomer.js +title: $:/core/plugins/zoomigator/zoomigator.js type: application/javascript module-type: macro @@ -13,22 +13,22 @@ Zooming navigator macro "use strict"; exports.info = { - name: "zoomer", + name: "zoomigator", params: { } }; -exports.startZoomer = function(x,y) { - this.inZoomer = true; +exports.startZoomigator = function(x,y) { + this.inZoomigator = true; this.startX = x; this.startY = y; - $tw.utils.addClass(document.body,"in-zoomer"); + $tw.utils.addClass(document.body,"in-zoomigator"); }; /* Zoom the body element given a touch/mouse position in screen coordinates */ -exports.hoverZoomer = function(x,y) { +exports.hoverZoomigator = function(x,y) { // Put the transform origin at the top in the middle document.body.style[$tw.browser.transformorigin] = "50% 0"; // Some shortcuts @@ -68,37 +68,37 @@ exports.hoverZoomer = function(x,y) { document.body.style[$tw.browser.transform] = transform; }; -exports.stopZoomer = function() { +exports.stopZoomigator = function() { var newScrollY = this.yFactor * (this.bodyHeight - this.windowHeight); - this.inZoomer = false; + this.inZoomigator = false; window.scrollTo(0,newScrollY); document.body.style[$tw.browser.transform] = "translateY(" + newScrollY * this.xFactor + "px) " + "scale(" + this.scale + ") " + "translateY(" + ((this.windowHeight / this.scale) - this.bodyHeight) * this.yFactor * this.xFactor + "px)"; - $tw.utils.removeClass(document.body,"in-zoomer"); + $tw.utils.removeClass(document.body,"in-zoomigator"); document.body.style[$tw.browser.transform] = "translateY(0) scale(1) translateY(0)"; }; exports.handleEvent = function(event) { switch(event.type) { case "touchstart": - this.startZoomer(event.touches[0].clientX,event.touches[0].clientY); - this.hoverZoomer(event.touches[0].clientX,event.touches[0].clientY); + this.startZoomigator(event.touches[0].clientX,event.touches[0].clientY); + this.hoverZoomigator(event.touches[0].clientX,event.touches[0].clientY); event.preventDefault(); return false; case "touchmove": - this.hoverZoomer(event.touches[0].clientX,event.touches[0].clientY); + this.hoverZoomigator(event.touches[0].clientX,event.touches[0].clientY); event.preventDefault(); return false; case "touchend": - this.stopZoomer(); + this.stopZoomigator(); event.preventDefault(); return false; } }; exports.executeMacro = function() { - this.inZoomer = false; + this.inZoomigator = false; var attributes = { style: { "position": "absolute", diff --git a/core/templates/PageTemplate.tid b/core/templates/PageTemplate.tid index 58034c537..3adc2d491 100644 --- a/core/templates/PageTemplate.tid +++ b/core/templates/PageTemplate.tid @@ -11,7 +11,7 @@ title: $:/templates/PageTemplate }}} -<> +<>