diff --git a/plugins/tiddlywiki/browser-storage/config/SaveFilter.tid b/plugins/tiddlywiki/browser-storage/config/SaveFilter.tid new file mode 100644 index 000000000..fa97f5963 --- /dev/null +++ b/plugins/tiddlywiki/browser-storage/config/SaveFilter.tid @@ -0,0 +1,2 @@ +title: $:/config/BrowserStorage/SaveFilter +text: [is[tiddler]] diff --git a/plugins/tiddlywiki/browser-storage/plugin.info b/plugins/tiddlywiki/browser-storage/plugin.info index 23b22b983..6c3ecaf21 100644 --- a/plugins/tiddlywiki/browser-storage/plugin.info +++ b/plugins/tiddlywiki/browser-storage/plugin.info @@ -3,5 +3,5 @@ "description": "Local storage in the browser", "author": "Jeremy Ruston ", "core-version": ">=5.0.0", - "list": "readme" + "list": "readme settings" } diff --git a/plugins/tiddlywiki/browser-storage/settings.tid b/plugins/tiddlywiki/browser-storage/settings.tid new file mode 100644 index 000000000..6379d15fe --- /dev/null +++ b/plugins/tiddlywiki/browser-storage/settings.tid @@ -0,0 +1,6 @@ +title: $:/plugins/tiddlywiki/browser-storage/settings + +This filter determines which tiddlers will be saved to local storage. By default, it contains `[is[tiddler]]` meaning that it will attempt to save all tiddlers. Other useful values include `[prefix[$:/state/]]` to just save state tiddlers, thus preserving selected tabs, and the open/closed status of table of contents entries. + +<$link to="$:/config/BrowserStorage/SaveFilter">Browser Storage Save Filter: <$edit-text tiddler="$:/config/BrowserStorage/SaveFilter" default="" tag="input" size="50"/> + diff --git a/plugins/tiddlywiki/browser-storage/startup.js b/plugins/tiddlywiki/browser-storage/startup.js index ba77a284b..6589b1757 100644 --- a/plugins/tiddlywiki/browser-storage/startup.js +++ b/plugins/tiddlywiki/browser-storage/startup.js @@ -18,7 +18,10 @@ exports.platforms = ["browser"]; exports.after = ["load-modules"]; exports.synchronous = true; +var SAVE_FILTER_TITLE = "$:/config/BrowserStorage/SaveFilter" + exports.startup = function() { + var self = this; // Compute our prefix for local storage keys var url = window.location.protocol === "file:" ? window.location.pathname : "", prefix = "tw5#" + url + "#"; @@ -26,9 +29,27 @@ exports.startup = function() { var logger = new $tw.utils.Logger("browser-storage",{ colour: "cyan" }); + // Function to compile the filter + var filterFn, + compileFilter = function() { + filterFn = $tw.wiki.compileFilter($tw.wiki.getTiddlerText(SAVE_FILTER_TITLE)); + } + compileFilter(); // Track tiddler changes $tw.wiki.addEventListener("change",function(changes) { - $tw.utils.each(changes,function(change,title) { + // Recompile the filter if it has changed + if(changes[SAVE_FILTER_TITLE]) { + compileFilter(); + } + // Filter the changes + var filteredChanges = filterFn.call($tw.wiki,function(iterator) { + $tw.utils.each(changes,function(change,title) { + var tiddler = $tw.wiki.getTiddler(title); + iterator(tiddler,title); + }); + }); +console.log("Filtered changes",filteredChanges) + $tw.utils.each(filteredChanges,function(title) { // Get the tiddler var tiddler = $tw.wiki.getTiddler(title); if(tiddler) {