From 8e6647b6154fe8bfb9fa051369c84a0f0ce8ee06 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 6 Aug 2012 22:34:16 +0100 Subject: [PATCH] Initial tranche of the plugin implementation This first commit adds some of the code needed for the plugin mechanism, but it isn't all fully operational yet. I'm merging the branch so that I can get some other pre-requisites done quickly on the main branch, and then plan to return to this branch. --- core/boot.js | 53 ++++++++++- core/plugins/TemporaryTestPlugin.tid | 9 ++ core/plugins/zoomigator/plugin.tiddlywiki | 11 +++ .../zoomigator/zoomigator.js} | 28 +++--- core/templates/PageTemplate.tid | 2 +- .../tiddlers/mechanisms/PluginMechanism.tid | 93 +++++++++++++++++++ 6 files changed, 179 insertions(+), 17 deletions(-) create mode 100644 core/plugins/TemporaryTestPlugin.tid create mode 100644 core/plugins/zoomigator/plugin.tiddlywiki rename core/{modules/macros/zoomer.js => plugins/zoomigator/zoomigator.js} (84%) create mode 100644 tw5.com/tiddlers/mechanisms/PluginMechanism.tid 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 }}} -<> +<>