mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-26 08:56:52 +00:00
Merge branch 'master' into parameterised-transclusions
This commit is contained in:
commit
66cf779abb
@ -359,14 +359,14 @@ node $TW5_BUILD_TIDDLYWIKI \
|
|||||||
|
|
||||||
# Delete any existing static content
|
# Delete any existing static content
|
||||||
|
|
||||||
rm $TW5_BUILD_OUTPUT/languages/de-AT/static/*
|
rm -rf $TW5_BUILD_OUTPUT/languages/de-AT/static/*
|
||||||
rm $TW5_BUILD_OUTPUT/languages/de-DE/static/*
|
rm -rf $TW5_BUILD_OUTPUT/languages/de-DE/static/*
|
||||||
rm $TW5_BUILD_OUTPUT/languages/es-ES/static/*
|
rm -rf $TW5_BUILD_OUTPUT/languages/es-ES/static/*
|
||||||
rm $TW5_BUILD_OUTPUT/languages/fr-FR/static/*
|
rm -rf $TW5_BUILD_OUTPUT/languages/fr-FR/static/*
|
||||||
rm $TW5_BUILD_OUTPUT/languages/ja-JP/static/*
|
rm -rf $TW5_BUILD_OUTPUT/languages/ja-JP/static/*
|
||||||
rm $TW5_BUILD_OUTPUT/languages/ko-KR/static/*
|
rm -rf $TW5_BUILD_OUTPUT/languages/ko-KR/static/*
|
||||||
rm $TW5_BUILD_OUTPUT/languages/zh-Hans/static/*
|
rm -rf $TW5_BUILD_OUTPUT/languages/zh-Hans/static/*
|
||||||
rm $TW5_BUILD_OUTPUT/languages/zh-Hant/static/*
|
rm -rf $TW5_BUILD_OUTPUT/languages/zh-Hant/static/*
|
||||||
|
|
||||||
# /languages/de-AT/index.html Demo wiki with de-AT language
|
# /languages/de-AT/index.html Demo wiki with de-AT language
|
||||||
# /languages/de-AT/empty.html Empty wiki with de-AT language
|
# /languages/de-AT/empty.html Empty wiki with de-AT language
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
{
|
{
|
||||||
"description": "Deutsche Basis Edition",
|
"description": "Deutsche Basis Edition",
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"tiddlywiki/browser-sniff"],
|
"tiddlywiki/browser-sniff",
|
||||||
|
"tiddlywiki/internals"
|
||||||
|
],
|
||||||
"themes": [
|
"themes": [
|
||||||
"tiddlywiki/vanilla",
|
"tiddlywiki/vanilla",
|
||||||
"tiddlywiki/snowwhite",
|
"tiddlywiki/snowwhite",
|
||||||
@ -9,8 +11,7 @@
|
|||||||
"tiddlywiki/seamless",
|
"tiddlywiki/seamless",
|
||||||
"tiddlywiki/centralised",
|
"tiddlywiki/centralised",
|
||||||
"tiddlywiki/tight",
|
"tiddlywiki/tight",
|
||||||
"tiddlywiki/readonly",
|
"tiddlywiki/readonly"
|
||||||
"tiddlywiki/internals"
|
|
||||||
],
|
],
|
||||||
"languages": [
|
"languages": [
|
||||||
"de-AT",
|
"de-AT",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"description": "Spanish (Spain) edition",
|
"description": "Spanish (Spain) edition",
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
"tiddlywiki/internals"
|
||||||
],
|
],
|
||||||
"themes": [
|
"themes": [
|
||||||
"tiddlywiki/vanilla",
|
"tiddlywiki/vanilla",
|
||||||
@ -9,8 +10,7 @@
|
|||||||
"tiddlywiki/seamless",
|
"tiddlywiki/seamless",
|
||||||
"tiddlywiki/centralised",
|
"tiddlywiki/centralised",
|
||||||
"tiddlywiki/tight",
|
"tiddlywiki/tight",
|
||||||
"tiddlywiki/readonly",
|
"tiddlywiki/readonly"
|
||||||
"tiddlywiki/internals"
|
|
||||||
],
|
],
|
||||||
"languages": [
|
"languages": [
|
||||||
"es-ES"
|
"es-ES"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"description": "French (France) edition",
|
"description": "French (France) edition",
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
"tiddlywiki/internals"
|
||||||
],
|
],
|
||||||
"themes": [
|
"themes": [
|
||||||
"tiddlywiki/vanilla",
|
"tiddlywiki/vanilla",
|
||||||
@ -9,8 +10,7 @@
|
|||||||
"tiddlywiki/seamless",
|
"tiddlywiki/seamless",
|
||||||
"tiddlywiki/centralised",
|
"tiddlywiki/centralised",
|
||||||
"tiddlywiki/tight",
|
"tiddlywiki/tight",
|
||||||
"tiddlywiki/readonly",
|
"tiddlywiki/readonly"
|
||||||
"tiddlywiki/internals"
|
|
||||||
],
|
],
|
||||||
"languages": [
|
"languages": [
|
||||||
"fr-FR"
|
"fr-FR"
|
||||||
|
@ -49,9 +49,6 @@
|
|||||||
],
|
],
|
||||||
"build": {
|
"build": {
|
||||||
"index": [
|
"index": [
|
||||||
"--savetiddlers","[tag[external-image]]","images",
|
|
||||||
"--setfield","[tag[external-image]]","_canonical_uri","$:/core/templates/canonical-uri-external-image","text/plain",
|
|
||||||
"--setfield","[tag[external-image]]","text","","text/plain",
|
|
||||||
"--rendertiddler","$:/core/save/all","index.html","text/plain"],
|
"--rendertiddler","$:/core/save/all","index.html","text/plain"],
|
||||||
"favicon": [
|
"favicon": [
|
||||||
"--savetiddler","$:/favicon.ico","favicon.ico",
|
"--savetiddler","$:/favicon.ico","favicon.ico",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"description": "Japanese (Japan) edition",
|
"description": "Japanese (Japan) edition",
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
"tiddlywiki/internals"
|
||||||
],
|
],
|
||||||
"themes": [
|
"themes": [
|
||||||
"tiddlywiki/vanilla",
|
"tiddlywiki/vanilla",
|
||||||
@ -9,8 +10,7 @@
|
|||||||
"tiddlywiki/seamless",
|
"tiddlywiki/seamless",
|
||||||
"tiddlywiki/centralised",
|
"tiddlywiki/centralised",
|
||||||
"tiddlywiki/tight",
|
"tiddlywiki/tight",
|
||||||
"tiddlywiki/readonly",
|
"tiddlywiki/readonly"
|
||||||
"tiddlywiki/internals"
|
|
||||||
],
|
],
|
||||||
"languages": [
|
"languages": [
|
||||||
"ja-JP"
|
"ja-JP"
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
caption: genesis
|
caption: genesis
|
||||||
created: 20221101100729587
|
created: 20221101100729587
|
||||||
modified: 20221230213912929
|
modified: 20230115101800345
|
||||||
tags: Widgets
|
tags: Widgets
|
||||||
title: GenesisWidget
|
title: GenesisWidget
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
|
|
||||||
! Introduction
|
! Introduction
|
||||||
|
|
||||||
<<.from-version "5.2.4">> The <<.wlink GenesisWidget>> widget allows the dynamic construction of another widget, where the name and attributes of the new widget can be dynamically determined, without needing to be known in advance.
|
<<.from-version "5.2.4">> The <<.wid genesis>> widget allows the dynamic construction of another widget, where the name and attributes of the new widget can be dynamically determined, without needing to be known in advance.
|
||||||
|
|
||||||
! Content and Attributes
|
! Content and Attributes
|
||||||
|
|
||||||
The content of the <<.wlink GenesisWidget>> widget is used as the content of the dynamically created widget.
|
The content of the <<.wid genesis>> widget is used as the content of the dynamically created widget.
|
||||||
|
|
||||||
|!Attribute |!Description |
|
|!Attribute |!Description |
|
||||||
|$type |The type of widget or element to create (an initial `$` indicates a widget, otherwise an HTML element will be created) |
|
|$type |The type of widget or element to create (an initial `$` indicates a widget, otherwise an HTML element will be created) |
|
||||||
|$names |An optional filter evaluating to the names of a list of attributes to be applied to the widget |
|
|$names |An optional filter evaluating to the names of a list of attributes to be applied to the widget |
|
||||||
|$values |An optional filter evaluating to the values corresponding to the list of names specified in `$names` |
|
|$values |An optional filter evaluating to the values corresponding to the list of names specified in <<.attr $names>> |
|
||||||
|//{other attributes starting with $}// |Other attributes starting with a single dollar sign are reserved for future use |
|
|//{other attributes starting with $}// |Other attributes starting with a single dollar sign are reserved for future use |
|
||||||
|//{attributes starting with $$}// |Attributes starting with two dollar signs are applied as attributes to the output widget, but with the attribute name changed to use a single dollar sign |
|
|//{attributes starting with $$}// |Attributes starting with two dollar signs are applied as attributes to the output widget, but with the attribute name changed to use a single dollar sign |
|
||||||
|//{attributes not starting with $}// |Any other attributes that do not start with a dollar are applied as attributes to the output widget |
|
|//{attributes not starting with $}// |Any other attributes that do not start with a dollar are applied as attributes to the output widget |
|
||||||
@ -27,10 +27,10 @@ Note that attributes explicitly specified take precedence over attributes with t
|
|||||||
|
|
||||||
! Examples
|
! Examples
|
||||||
|
|
||||||
<$macrocall $name='wikitext-example-without-html'
|
<$macrocall $name="wikitext-example"
|
||||||
src='<$genesis $type="div" class="tc-thing" label="Squeak">Mouse</$genesis>'/>
|
src="""<$genesis $type="div" class="tc-thing" label="Squeak">Mouse</$genesis>"""/>
|
||||||
|
|
||||||
<$macrocall $name='wikitext-example-without-html'
|
<$macrocall $name="wikitext-example"
|
||||||
src="""\define my-banner(mode:"inline",caption)
|
src="""\define my-banner(mode:"inline",caption)
|
||||||
<$genesis $type={{{ [<__mode__>match[inline]then[span]else[div]] }}} class="tc-mybanner">
|
<$genesis $type={{{ [<__mode__>match[inline]then[span]else[div]] }}} class="tc-mybanner">
|
||||||
<<__caption__>>
|
<<__caption__>>
|
||||||
@ -41,3 +41,11 @@ src="""\define my-banner(mode:"inline",caption)
|
|||||||
|
|
||||||
<<my-banner mode:"block" caption:"I'm in a DIV">>
|
<<my-banner mode:"block" caption:"I'm in a DIV">>
|
||||||
"""/>
|
"""/>
|
||||||
|
|
||||||
|
! Important
|
||||||
|
|
||||||
|
<$macrocall $name=".warning" _="""
|
||||||
|
In the following example the widget attribute named `one` is absent from the HTML output, since HTML attributes with the prefix `on` are removed for security reasons. See [[HTML in WikiText]] "Security" for more details.
|
||||||
|
|
||||||
|
<<wikitext-example '<$genesis $type="my-element" $names="one two" $values="1 2">Test Genesis Widget</$genesis>'>>
|
||||||
|
"""/>
|
@ -1,6 +1,6 @@
|
|||||||
caption: HTML
|
caption: HTML
|
||||||
created: 20131205160816081
|
created: 20131205160816081
|
||||||
modified: 20220123174919252
|
modified: 20230115100934146
|
||||||
tags: WikiText
|
tags: WikiText
|
||||||
title: HTML in WikiText
|
title: HTML in WikiText
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -31,7 +31,14 @@ some text <!-- inline comment -->
|
|||||||
|
|
||||||
! Important
|
! Important
|
||||||
|
|
||||||
<<.tip """[[Widgets share the same syntax as HTML tags|Widgets in WikiText]], and so the following information applies to them, too.""">>
|
!! Security
|
||||||
|
|
||||||
|
<<.warning """Every HTML attribute prefixed with `on` is removed from rendered HTML content for security reasons. eg: `onclick="some evil code"` would be executed, if no sanitation is active. In ~TiddlyWiki It's important to remove every attribute prefixed with `on` so future extensions to the HTML spec will be secure by default. This can lead to some inconvenience since custom attributes like eg: `one` are removed too. """>>
|
||||||
|
|
||||||
|
!! Widgets
|
||||||
|
|
||||||
|
<<.tip """[[Widgets share the same syntax as HTML tags|Widgets in WikiText]]<br>and so the following information applies to them, too.""">>
|
||||||
|
|
||||||
|
|
||||||
! Block mode versus Inline mode
|
! Block mode versus Inline mode
|
||||||
|
|
||||||
|
@ -104,5 +104,3 @@ TagManager/Tag/Heading: タグ
|
|||||||
Tiddler/DateFormat: YYYY年MM月DD日(ddd) 0hh:0mm
|
Tiddler/DateFormat: YYYY年MM月DD日(ddd) 0hh:0mm
|
||||||
UnsavedChangesWarning: 保存していない編集内容があります。
|
UnsavedChangesWarning: 保存していない編集内容があります。
|
||||||
Yes: はい
|
Yes: はい
|
||||||
$:/SiteSubtitle: 非線形パーソナルウェブノートブック
|
|
||||||
$:/SiteTitle: 私の ~TiddlyWiki
|
|
||||||
|
@ -8,8 +8,6 @@ Basics/AnimDuration/Prompt: Długość animacji
|
|||||||
Basics/AutoFocus/Prompt: Domyślne wybrane pole do edycji przy tworzeniu nowego tiddlera
|
Basics/AutoFocus/Prompt: Domyślne wybrane pole do edycji przy tworzeniu nowego tiddlera
|
||||||
Basics/Caption: Podstawowe
|
Basics/Caption: Podstawowe
|
||||||
Basics/DefaultTiddlers/BottomHint: Tiddlery, które mają spację w nazie otocz [[podwójnymi nawiasami kwadratowymi]]. Możesz też ustawić, by zawsze widzieć {{ostatnio otwarte tiddlery||$:/snippets/retain-story-ordering-button}}
|
Basics/DefaultTiddlers/BottomHint: Tiddlery, które mają spację w nazie otocz [[podwójnymi nawiasami kwadratowymi]]. Możesz też ustawić, by zawsze widzieć {{ostatnio otwarte tiddlery||$:/snippets/retain-story-ordering-button}}
|
||||||
Basics/DefaultTiddlers/BottomHint: Use [[double square brackets]] for titles with spaces. Or you can choose to <$button set="$:/DefaultTiddlers" setTo="[list[$:/StoryList]]">retain story ordering</$button>
|
|
||||||
Basics/DefaultTiddlers/BottomHint: Use [[double square brackets]] for titles with spaces. Or you can choose to {{retain story ordering||$:/snippets/retain-story-ordering-button}}
|
|
||||||
Basics/DefaultTiddlers/Prompt: Domyślnie otwarte tiddlery
|
Basics/DefaultTiddlers/Prompt: Domyślnie otwarte tiddlery
|
||||||
Basics/DefaultTiddlers/TopHint: Wybierz które tiddlery mają być widoczne przy uruchomieniu
|
Basics/DefaultTiddlers/TopHint: Wybierz które tiddlery mają być widoczne przy uruchomieniu
|
||||||
Basics/Language/Prompt: Cześć! Wybrany język to:
|
Basics/Language/Prompt: Cześć! Wybrany język to:
|
||||||
|
@ -14,7 +14,6 @@ $tw = window.$tw || Object.create(null);
|
|||||||
$tw.hooks = $tw.hooks || { names: {}};
|
$tw.hooks = $tw.hooks || { names: {}};
|
||||||
$tw.boot = $tw.boot || {};
|
$tw.boot = $tw.boot || {};
|
||||||
$tw.boot.preloadDirty = $tw.boot.preloadDirty || [];
|
$tw.boot.preloadDirty = $tw.boot.preloadDirty || [];
|
||||||
|
|
||||||
// Hook the point in the startup process when the tiddlers have been loaded but plugins not unpacked
|
// Hook the point in the startup process when the tiddlers have been loaded but plugins not unpacked
|
||||||
var hookName = "th-boot-tiddlers-loaded";
|
var hookName = "th-boot-tiddlers-loaded";
|
||||||
if(Object.prototype.hasOwnProperty.call($tw.hooks.names,hookName)) {
|
if(Object.prototype.hasOwnProperty.call($tw.hooks.names,hookName)) {
|
||||||
|
@ -19,19 +19,29 @@ exports.after = ["startup"];
|
|||||||
exports.synchronous = true;
|
exports.synchronous = true;
|
||||||
|
|
||||||
var ENABLED_TITLE = "$:/config/BrowserStorage/Enabled",
|
var ENABLED_TITLE = "$:/config/BrowserStorage/Enabled",
|
||||||
SAVE_FILTER_TITLE = "$:/config/BrowserStorage/SaveFilter",
|
SAVE_FILTER_TITLE = "$:/config/BrowserStorage/SaveFilter";
|
||||||
QUOTA_EXCEEDED_ALERT_TITLE = "$:/config/BrowserStorage/QuotaExceededAlert",
|
|
||||||
DEFAULT_QUOTA_EXCEEDED_ALERT_PREFIX = "Quota exceeded attempting to store `",
|
var BrowserStorageUtil = require("$:/plugins/tiddlywiki/browser-storage/util.js").BrowserStorageUtil;
|
||||||
DEFAULT_QUOTA_EXCEEDED_ALERT_SUFFIX = "` in browser local storage";
|
|
||||||
|
|
||||||
exports.startup = function() {
|
exports.startup = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
// If not exists, add ENABLED tiddler with default value "yes"
|
||||||
|
if(!$tw.wiki.getTiddler(ENABLED_TITLE)) {
|
||||||
|
$tw.wiki.addTiddler({title: ENABLED_TITLE, text: "yes"});
|
||||||
|
}
|
||||||
// Compute our prefix for local storage keys
|
// Compute our prefix for local storage keys
|
||||||
var prefix = "tw5#" + window.location.pathname + "#";
|
var prefix = "tw5#" + window.location.pathname + "#";
|
||||||
// Make a logger
|
// Make a logger
|
||||||
var logger = new $tw.utils.Logger("browser-storage",{
|
var logger = new $tw.utils.Logger("browser-storage",{
|
||||||
colour: "cyan"
|
colour: "cyan"
|
||||||
});
|
});
|
||||||
|
// Add browserStorage object to $tw
|
||||||
|
$tw.browserStorage = new BrowserStorageUtil($tw.wiki,{
|
||||||
|
enabledTitle: ENABLED_TITLE,
|
||||||
|
prefix: prefix,
|
||||||
|
logger: logger
|
||||||
|
});
|
||||||
// Function to compile the filter
|
// Function to compile the filter
|
||||||
var filterFn,
|
var filterFn,
|
||||||
compileFilter = function() {
|
compileFilter = function() {
|
||||||
@ -41,7 +51,7 @@ exports.startup = function() {
|
|||||||
// Listen for tm-clear-browser-storage messages
|
// Listen for tm-clear-browser-storage messages
|
||||||
$tw.rootWidget.addEventListener("tm-clear-browser-storage",function(event) {
|
$tw.rootWidget.addEventListener("tm-clear-browser-storage",function(event) {
|
||||||
$tw.wiki.addTiddler({title: ENABLED_TITLE, text: "no"});
|
$tw.wiki.addTiddler({title: ENABLED_TITLE, text: "no"});
|
||||||
clearLocalStorage();
|
$tw.browserStorage.clearLocalStorage();
|
||||||
});
|
});
|
||||||
// Track tiddler changes
|
// Track tiddler changes
|
||||||
$tw.wiki.addEventListener("change",function(changes) {
|
$tw.wiki.addEventListener("change",function(changes) {
|
||||||
@ -67,65 +77,9 @@ exports.startup = function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Save the tiddler
|
// Save the tiddler
|
||||||
saveTiddlerToLocalStorage(title,{
|
$tw.browserStorage.saveTiddlerToLocalStorage(title);
|
||||||
logger: logger,
|
|
||||||
prefix: prefix
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function saveTiddlerToLocalStorage(title,options) {
|
|
||||||
options = options || {};
|
|
||||||
// Get the tiddler
|
|
||||||
var tiddler = $tw.wiki.getTiddler(title);
|
|
||||||
if(tiddler) {
|
|
||||||
console.log("browser-storage: Saving",title);
|
|
||||||
// Get the JSON of the tiddler
|
|
||||||
var json = JSON.stringify(tiddler.getFieldStrings());
|
|
||||||
// Try to save it to local storage
|
|
||||||
try {
|
|
||||||
window.localStorage.setItem(options.prefix + title,json);
|
|
||||||
} catch(e) {
|
|
||||||
if(e.name === "QuotaExceededError") {
|
|
||||||
// Complain if we failed
|
|
||||||
var msg = $tw.wiki.getTiddlerText(QUOTA_EXCEEDED_ALERT_TITLE,DEFAULT_QUOTA_EXCEEDED_ALERT_PREFIX + title + DEFAULT_QUOTA_EXCEEDED_ALERT_SUFFIX);
|
|
||||||
if(options.logger) {
|
|
||||||
options.logger.alert(msg);
|
|
||||||
}
|
|
||||||
// No point in keeping old values around for this tiddler
|
|
||||||
window.localStorage.removeItem(options.prefix + title);
|
|
||||||
} else {
|
|
||||||
console.log("Browser-storage error:",e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// In local storage, use the special value of empty string to mark the tiddler as deleted
|
|
||||||
// On future page loads, if the tiddler is already gone from startup then the blank entry
|
|
||||||
// will be removed from localstorage. Otherwise, the tiddler will be deleted.
|
|
||||||
console.log("browser-storage: Blanking",title);
|
|
||||||
try {
|
|
||||||
window.localStorage.setItem(options.prefix + title, "");
|
|
||||||
} catch(e) {
|
|
||||||
console.log("Browser-storage error:",e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearLocalStorage() {
|
|
||||||
var url = window.location.pathname,
|
|
||||||
log = [];
|
|
||||||
// Step through each browser storage item
|
|
||||||
if(window.localStorage) {
|
|
||||||
for(var index=window.localStorage.length - 1; index>=0; index--) {
|
|
||||||
var key = window.localStorage.key(index),
|
|
||||||
parts = key.split("#");
|
|
||||||
// Delete it if it is ours
|
|
||||||
if(parts[0] === "tw5" && parts[1] === url) {
|
|
||||||
window.localStorage.removeItem(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
106
plugins/tiddlywiki/browser-storage/util.js
Normal file
106
plugins/tiddlywiki/browser-storage/util.js
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/plugins/tiddlywiki/browser-storage/util.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: library
|
||||||
|
|
||||||
|
Utility methods for browser-storage plugin
|
||||||
|
|
||||||
|
\*/
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function BrowserStorageUtil(wiki,options) {
|
||||||
|
this.options = options || {};
|
||||||
|
this.wiki = wiki;
|
||||||
|
this.cachedTiddlers = [];
|
||||||
|
this.QUOTA_EXCEEDED_ALERT_TITLE = "$:/config/BrowserStorage/QuotaExceededAlert";
|
||||||
|
this.DEFAULT_QUOTA_EXCEEDED_ALERT_PREFIX = "Quota exceeded attempting to store `";
|
||||||
|
this.DEFAULT_QUOTA_EXCEEDED_ALERT_SUFFIX = "` in browser local storage";
|
||||||
|
}
|
||||||
|
|
||||||
|
BrowserStorageUtil.prototype.isEnabled = function() {
|
||||||
|
return $tw.wiki.getTiddlerText(this.options.enabledTitle) === "yes";
|
||||||
|
};
|
||||||
|
|
||||||
|
BrowserStorageUtil.prototype.cachePreloadTiddlers = function() {
|
||||||
|
var self = this;
|
||||||
|
$tw.utils.each($tw.boot.preloadDirty, function(item){
|
||||||
|
var tiddler = $tw.wiki.getTiddler(item);
|
||||||
|
self.cachedTiddlers.push(tiddler);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
BrowserStorageUtil.prototype.addCachedTiddlers = function() {
|
||||||
|
var self = this;
|
||||||
|
if(this.cachedTiddlers.length > 0) {
|
||||||
|
$tw.utils.each(this.cachedTiddlers, function(item){
|
||||||
|
$tw.wiki.addTiddler(item);
|
||||||
|
});
|
||||||
|
this.cachedTiddlers.length = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BrowserStorageUtil.prototype.removeTiddlerFromLocalStorage = function(title) {
|
||||||
|
console.log("browser-storage: Removing", title);
|
||||||
|
window.localStorage.removeItem(this.options.prefix + title);
|
||||||
|
};
|
||||||
|
|
||||||
|
BrowserStorageUtil.prototype.saveTiddlerToLocalStorage = function(title) {
|
||||||
|
// Get the tiddler
|
||||||
|
var tiddler = $tw.wiki.getTiddler(title);
|
||||||
|
if(tiddler) {
|
||||||
|
console.log("browser-storage: Saving",title);
|
||||||
|
// Get the JSON of the tiddler
|
||||||
|
var json = JSON.stringify(tiddler.getFieldStrings());
|
||||||
|
// Try to save it to local storage
|
||||||
|
try {
|
||||||
|
window.localStorage.setItem(this.options.prefix + title,json);
|
||||||
|
} catch(e) {
|
||||||
|
if(e.name === "QuotaExceededError") {
|
||||||
|
// Complain if we failed
|
||||||
|
var msg = $tw.wiki.getTiddlerText(this.QUOTA_EXCEEDED_ALERT_TITLE,this.DEFAULT_QUOTA_EXCEEDED_ALERT_PREFIX + title + this.DEFAULT_QUOTA_EXCEEDED_ALERT_SUFFIX);
|
||||||
|
if(this.options.logger) {
|
||||||
|
this.options.logger.alert(msg);
|
||||||
|
}
|
||||||
|
// No point in keeping old values around for this tiddler
|
||||||
|
window.localStorage.removeItem(this.options.prefix + title);
|
||||||
|
} else {
|
||||||
|
console.log("Browser-storage error:",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// In local storage, use the special value of empty string to mark the tiddler as deleted
|
||||||
|
// On future page loads, if the tiddler is already gone from startup then the blank entry
|
||||||
|
// will be removed from localstorage. Otherwise, the tiddler will be deleted.
|
||||||
|
console.log("browser-storage: Blanking",title);
|
||||||
|
try {
|
||||||
|
window.localStorage.setItem(this.options.prefix + title, "");
|
||||||
|
} catch(e) {
|
||||||
|
console.log("Browser-storage error:",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BrowserStorageUtil.prototype.clearLocalStorage = function() {
|
||||||
|
var url = window.location.pathname,
|
||||||
|
log = [];
|
||||||
|
// Step through each browser storage item
|
||||||
|
if(window.localStorage) {
|
||||||
|
for(var index=window.localStorage.length - 1; index>=0; index--) {
|
||||||
|
var key = window.localStorage.key(index),
|
||||||
|
parts = key.split("#");
|
||||||
|
// Delete it if it is ours
|
||||||
|
if(parts[0] === "tw5" && parts[1] === url) {
|
||||||
|
window.localStorage.removeItem(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.BrowserStorageUtil = BrowserStorageUtil;
|
||||||
|
|
||||||
|
})();
|
@ -76,6 +76,10 @@ TiddlyWebAdaptor.prototype.getStatus = function(callback) {
|
|||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
//If Browser-Storage plugin is present, cache pre-loaded tiddlers and add back after sync from server completes
|
||||||
|
if($tw.browserStorage && $tw.browserStorage.isEnabled()) {
|
||||||
|
$tw.browserStorage.cachePreloadTiddlers();
|
||||||
|
}
|
||||||
// Decode the status JSON
|
// Decode the status JSON
|
||||||
var json = null;
|
var json = null;
|
||||||
try {
|
try {
|
||||||
@ -188,6 +192,10 @@ TiddlyWebAdaptor.prototype.getSkinnyTiddlers = function(callback) {
|
|||||||
}
|
}
|
||||||
// Invoke the callback with the skinny tiddlers
|
// Invoke the callback with the skinny tiddlers
|
||||||
callback(null,tiddlers);
|
callback(null,tiddlers);
|
||||||
|
// If Browswer Storage tiddlers were cached on reloading the wiki, add them after sync from server completes in the above callback.
|
||||||
|
if($tw.browserStorage && $tw.browserStorage.isEnabled()) {
|
||||||
|
$tw.browserStorage.addCachedTiddlers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -211,6 +219,10 @@ TiddlyWebAdaptor.prototype.saveTiddler = function(tiddler,callback,options) {
|
|||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
//If Browser-Storage plugin is present, remove tiddler from local storage after successful sync to the server
|
||||||
|
if($tw.browserStorage && $tw.browserStorage.isEnabled()) {
|
||||||
|
$tw.browserStorage.removeTiddlerFromLocalStorage(tiddler.fields.title)
|
||||||
|
}
|
||||||
// Save the details of the new revision of the tiddler
|
// Save the details of the new revision of the tiddler
|
||||||
var etag = request.getResponseHeader("Etag");
|
var etag = request.getResponseHeader("Etag");
|
||||||
if(!etag) {
|
if(!etag) {
|
||||||
|
Loading…
Reference in New Issue
Block a user