mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-02-19 16:39:50 +00:00
Compare commits
15 Commits
eslint-fix
...
tm-save-do
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fb1f81eea | ||
|
|
41c7948c02 | ||
|
|
9aa65564d4 | ||
|
|
ed53a8d580 | ||
|
|
42b79213dd | ||
|
|
6e1b58fca7 | ||
|
|
925d3b0b4c | ||
|
|
4eed4cbaa5 | ||
|
|
fd21908896 | ||
|
|
f36b9f248c | ||
|
|
c9ce9b192d | ||
|
|
2c271077aa | ||
|
|
377be1e4d4 | ||
|
|
9fb763f991 | ||
|
|
407cd050aa |
@@ -15,40 +15,40 @@ var fs = require("fs"),
|
||||
{ optimize } = require("svgo"),
|
||||
config = {
|
||||
plugins: [
|
||||
"cleanupAttrs",
|
||||
"removeDoctype",
|
||||
"removeXMLProcInst",
|
||||
"removeComments",
|
||||
"removeMetadata",
|
||||
"removeTitle",
|
||||
"removeDesc",
|
||||
"removeUselessDefs",
|
||||
"removeEditorsNSData",
|
||||
"removeEmptyAttrs",
|
||||
"removeHiddenElems",
|
||||
"removeEmptyText",
|
||||
"removeEmptyContainers",
|
||||
'cleanupAttrs',
|
||||
'removeDoctype',
|
||||
'removeXMLProcInst',
|
||||
'removeComments',
|
||||
'removeMetadata',
|
||||
'removeTitle',
|
||||
'removeDesc',
|
||||
'removeUselessDefs',
|
||||
'removeEditorsNSData',
|
||||
'removeEmptyAttrs',
|
||||
'removeHiddenElems',
|
||||
'removeEmptyText',
|
||||
'removeEmptyContainers',
|
||||
// 'removeViewBox',
|
||||
"cleanupEnableBackground",
|
||||
"convertStyleToAttrs",
|
||||
"convertColors",
|
||||
"convertPathData",
|
||||
"convertTransform",
|
||||
"removeUnknownsAndDefaults",
|
||||
"removeNonInheritableGroupAttrs",
|
||||
"removeUselessStrokeAndFill",
|
||||
"removeUnusedNS",
|
||||
"cleanupIDs",
|
||||
"cleanupNumericValues",
|
||||
"moveElemsAttrsToGroup",
|
||||
"moveGroupAttrsToElems",
|
||||
"collapseGroups",
|
||||
'cleanupEnableBackground',
|
||||
'convertStyleToAttrs',
|
||||
'convertColors',
|
||||
'convertPathData',
|
||||
'convertTransform',
|
||||
'removeUnknownsAndDefaults',
|
||||
'removeNonInheritableGroupAttrs',
|
||||
'removeUselessStrokeAndFill',
|
||||
'removeUnusedNS',
|
||||
'cleanupIDs',
|
||||
'cleanupNumericValues',
|
||||
'moveElemsAttrsToGroup',
|
||||
'moveGroupAttrsToElems',
|
||||
'collapseGroups',
|
||||
// 'removeRasterImages',
|
||||
"mergePaths",
|
||||
"convertShapeToPath",
|
||||
"sortAttrs",
|
||||
'mergePaths',
|
||||
'convertShapeToPath',
|
||||
'sortAttrs',
|
||||
//'removeDimensions',
|
||||
{name: "removeAttrs", params: { attrs: "(stroke|fill)" } }
|
||||
{name: 'removeAttrs', params: { attrs: '(stroke|fill)' } }
|
||||
]
|
||||
};
|
||||
|
||||
@@ -72,7 +72,7 @@ files.forEach(function(filename) {
|
||||
var newSVG = header.join("\n") + "\n\n" + result.data.replace("<<now "DD">>","<<now \"DD\">>");
|
||||
fs.writeFileSync(filepath,newSVG);
|
||||
} else {
|
||||
console.log("Error " + err + " with " + filename);
|
||||
console.log("Error " + err + " with " + filename)
|
||||
process.exit();
|
||||
};
|
||||
}
|
||||
|
||||
54
boot/boot.js
54
boot/boot.js
@@ -37,7 +37,7 @@ if($tw.node) {
|
||||
$tw.boot.log = function(str) {
|
||||
$tw.boot.logMessages = $tw.boot.logMessages || [];
|
||||
$tw.boot.logMessages.push(str);
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Check if an object has a property
|
||||
@@ -47,7 +47,7 @@ $tw.utils.hop = function(object,property) {
|
||||
};
|
||||
|
||||
/** @deprecated Use Array.isArray instead */
|
||||
$tw.utils.isArray = (value) => Array.isArray(value);
|
||||
$tw.utils.isArray = value => Array.isArray(value);
|
||||
|
||||
/*
|
||||
Check if an array is equal by value and by reference.
|
||||
@@ -127,7 +127,7 @@ $tw.utils.pushTop = function(array,value) {
|
||||
};
|
||||
|
||||
/** @deprecated Use instanceof Date instead */
|
||||
$tw.utils.isDate = (value) => value instanceof Date;
|
||||
$tw.utils.isDate = value => value instanceof Date;
|
||||
|
||||
/** @deprecated Use array iterative methods instead */
|
||||
$tw.utils.each = function(object,callback) {
|
||||
@@ -138,7 +138,7 @@ $tw.utils.each = function(object,callback) {
|
||||
return next !== false;
|
||||
});
|
||||
} else {
|
||||
Object.entries(object).every((entry) => {
|
||||
Object.entries(object).every(entry => {
|
||||
const next = callback(entry[1], entry[0], object);
|
||||
return next !== false;
|
||||
});
|
||||
@@ -565,7 +565,7 @@ using a lowercase extension only.
|
||||
*/
|
||||
$tw.utils.getFileExtensionInfo = function(ext) {
|
||||
return ext ? $tw.config.fileExtensionInfo[ext.toLowerCase()] : null;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Given an extension, get the correct encoding for that file.
|
||||
@@ -588,7 +588,7 @@ var globalCheck =[
|
||||
" delete Object.prototype.__temp__;",
|
||||
" }",
|
||||
" delete Object.prototype.__temp__;",
|
||||
].join("\n");
|
||||
].join('\n');
|
||||
|
||||
/*
|
||||
Run code globally with specified context variables in scope
|
||||
@@ -616,7 +616,7 @@ $tw.utils.evalGlobal = function(code,context,filename,sandbox,allowGlobals) {
|
||||
fn = Function("return " + code + "\n\n//# sourceURL=" + filename)(); // See https://github.com/TiddlyWiki/TiddlyWiki5/issues/6839
|
||||
} else {
|
||||
if(sandbox){
|
||||
fn = vm.runInContext(code,sandbox,filename);
|
||||
fn = vm.runInContext(code,sandbox,filename)
|
||||
} else {
|
||||
fn = vm.runInThisContext(code,filename);
|
||||
}
|
||||
@@ -773,7 +773,7 @@ $tw.utils.PasswordPrompt.prototype.removePrompt = function(promptInfo) {
|
||||
promptInfo.form.parentNode.removeChild(promptInfo.form);
|
||||
this.setWrapperDisplay();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Crypto helper object for encrypted content. It maintains the password text in a closure, and provides methods to change
|
||||
@@ -812,7 +812,7 @@ $tw.utils.Crypto = function() {
|
||||
};
|
||||
this.hasPassword = function() {
|
||||
return !!currentPassword;
|
||||
};
|
||||
}
|
||||
this.encrypt = function(text,password) {
|
||||
// set default ks:256 -- see: http://bitwiseshiftleft.github.io/sjcl/doc/convenience.js.html
|
||||
return callSjcl("encrypt",text,password,{v:1,iter:10000,ks:256,ts:64,mode:"ccm",adata:"",cipher:"aes"});
|
||||
@@ -830,7 +830,7 @@ Execute the module named 'moduleName'. The name can optionally be relative to th
|
||||
$tw.modules.execute = function(moduleName,moduleRoot) {
|
||||
var name = moduleName;
|
||||
if(moduleName.charAt(0) === ".") {
|
||||
name = $tw.utils.resolvePath(moduleName,moduleRoot);
|
||||
name = $tw.utils.resolvePath(moduleName,moduleRoot)
|
||||
}
|
||||
if(!$tw.modules.titles[name]) {
|
||||
if($tw.modules.titles[name + ".js"]) {
|
||||
@@ -1201,7 +1201,7 @@ $tw.Wiki = function(options) {
|
||||
shadow: this.isShadowTiddler(title),
|
||||
exists: this.tiddlerExists(title)
|
||||
}
|
||||
};
|
||||
}
|
||||
// Save the new tiddler
|
||||
tiddlers[title] = tiddler;
|
||||
// Check we've got the title
|
||||
@@ -1211,7 +1211,7 @@ $tw.Wiki = function(options) {
|
||||
tiddler: tiddler,
|
||||
shadow: this.isShadowTiddler(title),
|
||||
exists: this.tiddlerExists(title)
|
||||
};
|
||||
}
|
||||
// Update indexes
|
||||
this.clearCache(title);
|
||||
this.clearGlobalCache();
|
||||
@@ -1236,7 +1236,7 @@ $tw.Wiki = function(options) {
|
||||
shadow: this.isShadowTiddler(title),
|
||||
exists: this.tiddlerExists(title)
|
||||
}
|
||||
};
|
||||
}
|
||||
// Delete the tiddler
|
||||
delete tiddlers[title];
|
||||
// Delete it from the list of titles
|
||||
@@ -1251,7 +1251,7 @@ $tw.Wiki = function(options) {
|
||||
tiddler: this.getTiddler(title),
|
||||
shadow: this.isShadowTiddler(title),
|
||||
exists: this.tiddlerExists(title)
|
||||
};
|
||||
}
|
||||
// Update indexes
|
||||
this.clearCache(title);
|
||||
this.clearGlobalCache();
|
||||
@@ -1459,11 +1459,11 @@ $tw.Wiki = function(options) {
|
||||
pluginTiddlers.sort(function(a, b) {
|
||||
var priorityA = "plugin-priority" in a.fields ? a.fields["plugin-priority"] : 1;
|
||||
var priorityB = "plugin-priority" in b.fields ? b.fields["plugin-priority"] : 1;
|
||||
if(priorityA !== priorityB) {
|
||||
if (priorityA !== priorityB) {
|
||||
return priorityA - priorityB;
|
||||
} else if(a.fields.title < b.fields.title) {
|
||||
} else if (a.fields.title < b.fields.title) {
|
||||
return -1;
|
||||
} else if(a.fields.title === b.fields.title) {
|
||||
} else if (a.fields.title === b.fields.title) {
|
||||
return 0;
|
||||
} else {
|
||||
return +1;
|
||||
@@ -1570,7 +1570,7 @@ $tw.Wiki.prototype.processSafeMode = function() {
|
||||
// Assemble a report tiddler
|
||||
var titleReportTiddler = "TiddlyWiki Safe Mode",
|
||||
report = [];
|
||||
report.push("TiddlyWiki has been started in [[safe mode|https://tiddlywiki.com/static/SafeMode.html]]. All plugins are temporarily disabled. Most customisations have been disabled by renaming the following tiddlers:");
|
||||
report.push("TiddlyWiki has been started in [[safe mode|https://tiddlywiki.com/static/SafeMode.html]]. All plugins are temporarily disabled. Most customisations have been disabled by renaming the following tiddlers:")
|
||||
// Delete the overrides
|
||||
overrides.forEach(function(title) {
|
||||
var tiddler = self.getTiddler(title),
|
||||
@@ -1579,7 +1579,7 @@ $tw.Wiki.prototype.processSafeMode = function() {
|
||||
self.addTiddler(new $tw.Tiddler(tiddler, {title: newTitle}));
|
||||
report.push("* [[" + title + "|" + newTitle + "]]");
|
||||
});
|
||||
report.push();
|
||||
report.push()
|
||||
this.addTiddler(new $tw.Tiddler({title: titleReportTiddler, text: report.join("\n\n")}));
|
||||
// Set $:/DefaultTiddlers to point to our report
|
||||
this.addTiddler(new $tw.Tiddler({title: "$:/DefaultTiddlers", text: "[[" + titleReportTiddler + "]]"}));
|
||||
@@ -2013,7 +2013,7 @@ $tw.loadTiddlersFromSpecification = function(filepath,excludeRegExp) {
|
||||
value = $tw.utils.stringifyList(path.relative(rootPath, filename).split(path.sep).slice(0, -1));
|
||||
break;
|
||||
case "filepath":
|
||||
value = path.relative(rootPath, filename).split(path.sep).join("/");
|
||||
value = path.relative(rootPath, filename).split(path.sep).join('/');
|
||||
break;
|
||||
case "filename":
|
||||
value = path.basename(filename);
|
||||
@@ -2066,7 +2066,7 @@ $tw.loadTiddlersFromSpecification = function(filepath,excludeRegExp) {
|
||||
}
|
||||
});
|
||||
return arrayOfFiles;
|
||||
};
|
||||
}
|
||||
// Process the listed tiddlers
|
||||
$tw.utils.each(filesInfo.tiddlers,function(tidInfo) {
|
||||
if(tidInfo.prefix && tidInfo.suffix) {
|
||||
@@ -2175,7 +2175,7 @@ Returns the path of the plugin folder
|
||||
$tw.findLibraryItem = function(name,paths) {
|
||||
var pathIndex = 0;
|
||||
do {
|
||||
var pluginPath = path.resolve(paths[pathIndex],"./" + name);
|
||||
var pluginPath = path.resolve(paths[pathIndex],"./" + name)
|
||||
if(fs.existsSync(pluginPath) && fs.statSync(pluginPath).isDirectory()) {
|
||||
return pluginPath;
|
||||
}
|
||||
@@ -2534,7 +2534,7 @@ $tw.boot.initStartup = function(options) {
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
$tw.boot.loadStartup = function(options){
|
||||
@@ -2551,7 +2551,7 @@ $tw.boot.loadStartup = function(options){
|
||||
}
|
||||
// Give hooks a chance to modify the store
|
||||
$tw.hooks.invokeHook("th-boot-tiddlers-loaded");
|
||||
};
|
||||
}
|
||||
$tw.boot.execStartup = function(options){
|
||||
// Unpack plugin tiddlers
|
||||
$tw.wiki.readPluginInfo();
|
||||
@@ -2581,7 +2581,7 @@ $tw.boot.execStartup = function(options){
|
||||
$tw.boot.disabledStartupModules = $tw.boot.disabledStartupModules || [];
|
||||
// Repeatedly execute the next eligible task
|
||||
$tw.boot.executeNextStartupTask(options.callback);
|
||||
};
|
||||
}
|
||||
/*
|
||||
Startup TiddlyWiki
|
||||
*/
|
||||
@@ -2600,7 +2600,7 @@ $tw.addUnloadTask = function(task) {
|
||||
if($tw.unloadTasks.indexOf(task) === -1) {
|
||||
$tw.unloadTasks.push(task);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Execute the remaining eligible startup tasks
|
||||
@@ -2647,7 +2647,7 @@ $tw.boot.executeNextStartupTask = function(callback) {
|
||||
}
|
||||
taskIndex++;
|
||||
}
|
||||
if(typeof callback === "function") {
|
||||
if(typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -103,7 +103,7 @@ Commander.prototype.executeNextCommand = function() {
|
||||
c = new command.Command(params,this);
|
||||
err = c.execute();
|
||||
if(err && typeof err.then === "function") {
|
||||
err.then((e) => { e ? this.callback(e) : this.executeNextCommand(); });
|
||||
err.then(e => { e ? this.callback(e) : this.executeNextCommand(); });
|
||||
} else if(err) {
|
||||
this.callback(err);
|
||||
} else {
|
||||
@@ -120,7 +120,7 @@ Commander.prototype.executeNextCommand = function() {
|
||||
});
|
||||
err = c.execute();
|
||||
if(err && typeof err.then === "function") {
|
||||
err.then((e) => { if(e) this.callback(e); });
|
||||
err.then(e => { if(e) this.callback(e); });
|
||||
} else if(err) {
|
||||
this.callback(err);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ Command.prototype.execute = function() {
|
||||
if(!filter) {
|
||||
return "No filter specified";
|
||||
}
|
||||
var commands = this.commander.wiki.filterTiddlers(filter);
|
||||
var commands = this.commander.wiki.filterTiddlers(filter)
|
||||
if(commands.length === 0) {
|
||||
return "No tiddlers found for filter '" + filter + "'";
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ Command.prototype.fetchFiles = function(options) {
|
||||
// Get the list of URLs
|
||||
var urls;
|
||||
if(options.url) {
|
||||
urls = [options.url];
|
||||
urls = [options.url]
|
||||
} else if(options.urlFilter) {
|
||||
urls = this.commander.wiki.filterTiddlers(options.urlFilter);
|
||||
} else {
|
||||
@@ -96,30 +96,30 @@ Command.prototype.fetchFile = function(url,options,callback,redirectCount) {
|
||||
var self = this,
|
||||
lib = url.substr(0,8) === "https://" ? require("https") : require("http");
|
||||
lib.get(url).on("response",function(response) {
|
||||
var type = (response.headers["content-type"] || "").split(";")[0],
|
||||
data = [];
|
||||
self.commander.write("Reading " + url + ": ");
|
||||
response.on("data",function(chunk) {
|
||||
data.push(chunk);
|
||||
self.commander.write(".");
|
||||
});
|
||||
response.on("end",function() {
|
||||
self.commander.write("\n");
|
||||
if(response.statusCode === 200) {
|
||||
self.processBody(Buffer.concat(data),type,options,url);
|
||||
callback(null);
|
||||
} else {
|
||||
if(response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) {
|
||||
return self.fetchFile(response.headers.location,options,callback,redirectCount + 1);
|
||||
} else {
|
||||
return callback("Error " + response.statusCode + " retrieving " + url);
|
||||
}
|
||||
}
|
||||
});
|
||||
response.on("error",function(e) {
|
||||
var type = (response.headers["content-type"] || "").split(";")[0],
|
||||
data = [];
|
||||
self.commander.write("Reading " + url + ": ");
|
||||
response.on("data",function(chunk) {
|
||||
data.push(chunk);
|
||||
self.commander.write(".");
|
||||
});
|
||||
response.on("end",function() {
|
||||
self.commander.write("\n");
|
||||
if(response.statusCode === 200) {
|
||||
self.processBody(Buffer.concat(data),type,options,url);
|
||||
callback(null);
|
||||
} else {
|
||||
if(response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) {
|
||||
return self.fetchFile(response.headers.location,options,callback,redirectCount + 1);
|
||||
} else {
|
||||
return callback("Error " + response.statusCode + " retrieving " + url)
|
||||
}
|
||||
}
|
||||
});
|
||||
response.on("error",function(e) {
|
||||
console.log("Error on GET request: " + e);
|
||||
callback(e);
|
||||
});
|
||||
});
|
||||
});
|
||||
return null;
|
||||
};
|
||||
@@ -153,18 +153,18 @@ Command.prototype.processBody = function(body,type,options,url) {
|
||||
if(options.transformFilter) {
|
||||
var transformedTitle = (incomingWiki.filterTiddlers(options.transformFilter,null,self.commander.wiki.makeTiddlerIterator([title])) || [""])[0];
|
||||
if(transformedTitle) {
|
||||
self.commander.log("Importing " + title + " as " + transformedTitle);
|
||||
self.commander.log("Importing " + title + " as " + transformedTitle)
|
||||
newTiddler = new $tw.Tiddler(tiddler,{title: transformedTitle});
|
||||
}
|
||||
} else {
|
||||
self.commander.log("Importing " + title);
|
||||
self.commander.log("Importing " + title)
|
||||
newTiddler = tiddler;
|
||||
}
|
||||
self.commander.wiki.importTiddler(newTiddler);
|
||||
count++;
|
||||
}
|
||||
});
|
||||
self.commander.log("Imported " + count + " tiddlers");
|
||||
self.commander.log("Imported " + count + " tiddlers")
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
@@ -7,59 +7,59 @@ Render individual tiddlers and save the results to the specified files
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
var widget = require("$:/core/modules/widgets/widget.js");
|
||||
var widget = require("$:/core/modules/widgets/widget.js");
|
||||
|
||||
exports.info = {
|
||||
name: "render",
|
||||
synchronous: true
|
||||
};
|
||||
exports.info = {
|
||||
name: "render",
|
||||
synchronous: true
|
||||
};
|
||||
|
||||
var Command = function(params,commander,callback) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
this.callback = callback;
|
||||
};
|
||||
var Command = function(params,commander,callback) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
this.callback = callback;
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
if(this.params.length < 1) {
|
||||
return "Missing tiddler filter";
|
||||
}
|
||||
var self = this,
|
||||
fs = require("fs"),
|
||||
path = require("path"),
|
||||
wiki = this.commander.wiki,
|
||||
tiddlerFilter = this.params[0],
|
||||
filenameFilter = this.params[1] || "[is[tiddler]addsuffix[.html]]",
|
||||
type = this.params[2] || "text/html",
|
||||
template = this.params[3],
|
||||
variableList = this.params.slice(4),
|
||||
tiddlers = wiki.filterTiddlers(tiddlerFilter),
|
||||
variables = Object.create(null);
|
||||
while(variableList.length >= 2) {
|
||||
variables[variableList[0]] = variableList[1];
|
||||
variableList = variableList.slice(2);
|
||||
}
|
||||
$tw.utils.each(tiddlers,function(title) {
|
||||
var filenameResults = wiki.filterTiddlers(filenameFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]));
|
||||
if(filenameResults.length > 0) {
|
||||
var filepath = path.resolve(self.commander.outputPath,filenameResults[0]);
|
||||
if(self.commander.verbose) {
|
||||
console.log("Rendering \"" + title + "\" to \"" + filepath + "\"");
|
||||
}
|
||||
var parser = wiki.parseTiddler(template || title),
|
||||
widgetNode = wiki.makeWidget(parser,{variables: $tw.utils.extend({},variables,{currentTiddler: title,storyTiddler: title})}),
|
||||
container = $tw.fakeDocument.createElement("div");
|
||||
widgetNode.render(container,null);
|
||||
var text = type === "text/html" ? container.innerHTML : container.textContent;
|
||||
$tw.utils.createFileDirectories(filepath);
|
||||
fs.writeFileSync(filepath,text,"utf8");
|
||||
} else {
|
||||
console.log("Not rendering \"" + title + "\" because the filename filter returned an empty result");
|
||||
Command.prototype.execute = function() {
|
||||
if(this.params.length < 1) {
|
||||
return "Missing tiddler filter";
|
||||
}
|
||||
});
|
||||
return null;
|
||||
};
|
||||
var self = this,
|
||||
fs = require("fs"),
|
||||
path = require("path"),
|
||||
wiki = this.commander.wiki,
|
||||
tiddlerFilter = this.params[0],
|
||||
filenameFilter = this.params[1] || "[is[tiddler]addsuffix[.html]]",
|
||||
type = this.params[2] || "text/html",
|
||||
template = this.params[3],
|
||||
variableList = this.params.slice(4),
|
||||
tiddlers = wiki.filterTiddlers(tiddlerFilter),
|
||||
variables = Object.create(null);
|
||||
while(variableList.length >= 2) {
|
||||
variables[variableList[0]] = variableList[1];
|
||||
variableList = variableList.slice(2);
|
||||
}
|
||||
$tw.utils.each(tiddlers,function(title) {
|
||||
var filenameResults = wiki.filterTiddlers(filenameFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]));
|
||||
if(filenameResults.length > 0) {
|
||||
var filepath = path.resolve(self.commander.outputPath,filenameResults[0]);
|
||||
if(self.commander.verbose) {
|
||||
console.log("Rendering \"" + title + "\" to \"" + filepath + "\"");
|
||||
}
|
||||
var parser = wiki.parseTiddler(template || title),
|
||||
widgetNode = wiki.makeWidget(parser,{variables: $tw.utils.extend({},variables,{currentTiddler: title,storyTiddler: title})}),
|
||||
container = $tw.fakeDocument.createElement("div");
|
||||
widgetNode.render(container,null);
|
||||
var text = type === "text/html" ? container.innerHTML : container.textContent;
|
||||
$tw.utils.createFileDirectories(filepath);
|
||||
fs.writeFileSync(filepath,text,"utf8");
|
||||
} else {
|
||||
console.log("Not rendering \"" + title + "\" because the filename filter returned an empty result");
|
||||
}
|
||||
});
|
||||
return null;
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
exports.Command = Command;
|
||||
|
||||
@@ -7,57 +7,57 @@ Saves individual tiddlers in their raw text or binary format to the specified fi
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "save",
|
||||
synchronous: true
|
||||
};
|
||||
exports.info = {
|
||||
name: "save",
|
||||
synchronous: true
|
||||
};
|
||||
|
||||
var Command = function(params,commander,callback) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
this.callback = callback;
|
||||
};
|
||||
var Command = function(params,commander,callback) {
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
this.callback = callback;
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
if(this.params.length < 1) {
|
||||
return "Missing filename filter";
|
||||
}
|
||||
var self = this,
|
||||
fs = require("fs"),
|
||||
path = require("path"),
|
||||
result = null,
|
||||
wiki = this.commander.wiki,
|
||||
tiddlerFilter = this.params[0],
|
||||
filenameFilter = this.params[1] || "[is[tiddler]]",
|
||||
tiddlers = wiki.filterTiddlers(tiddlerFilter);
|
||||
$tw.utils.each(tiddlers,function(title) {
|
||||
if(!result) {
|
||||
var tiddler = self.commander.wiki.getTiddler(title);
|
||||
if(tiddler) {
|
||||
var fileInfo = $tw.utils.generateTiddlerFileInfo(tiddler,{
|
||||
directory: path.resolve(self.commander.outputPath),
|
||||
pathFilters: [filenameFilter],
|
||||
wiki: wiki,
|
||||
fileInfo: {
|
||||
overwrite: true
|
||||
}
|
||||
});
|
||||
if(self.commander.verbose) {
|
||||
console.log("Saving \"" + title + "\" to \"" + fileInfo.filepath + "\"");
|
||||
}
|
||||
try {
|
||||
$tw.utils.saveTiddlerToFileSync(tiddler,fileInfo);
|
||||
} catch (err) {
|
||||
result = "Error saving tiddler \"" + title + "\", to file: \"" + fileInfo.filepath + "\"";
|
||||
}
|
||||
} else {
|
||||
result = "Tiddler '" + title + "' not found";
|
||||
}
|
||||
Command.prototype.execute = function() {
|
||||
if(this.params.length < 1) {
|
||||
return "Missing filename filter";
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
var self = this,
|
||||
fs = require("fs"),
|
||||
path = require("path"),
|
||||
result = null,
|
||||
wiki = this.commander.wiki,
|
||||
tiddlerFilter = this.params[0],
|
||||
filenameFilter = this.params[1] || "[is[tiddler]]",
|
||||
tiddlers = wiki.filterTiddlers(tiddlerFilter);
|
||||
$tw.utils.each(tiddlers,function(title) {
|
||||
if(!result) {
|
||||
var tiddler = self.commander.wiki.getTiddler(title);
|
||||
if(tiddler) {
|
||||
var fileInfo = $tw.utils.generateTiddlerFileInfo(tiddler,{
|
||||
directory: path.resolve(self.commander.outputPath),
|
||||
pathFilters: [filenameFilter],
|
||||
wiki: wiki,
|
||||
fileInfo: {
|
||||
overwrite: true
|
||||
}
|
||||
});
|
||||
if(self.commander.verbose) {
|
||||
console.log("Saving \"" + title + "\" to \"" + fileInfo.filepath + "\"");
|
||||
}
|
||||
try {
|
||||
$tw.utils.saveTiddlerToFileSync(tiddler,fileInfo);
|
||||
} catch (err) {
|
||||
result = "Error saving tiddler \"" + title + "\", to file: \"" + fileInfo.filepath + "\"";
|
||||
}
|
||||
} else {
|
||||
result = "Tiddler '" + title + "' not found";
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
exports.Command = Command;
|
||||
|
||||
@@ -43,7 +43,7 @@ Command.prototype.execute = function() {
|
||||
namedParames,
|
||||
tiddlerFilter,
|
||||
options = {};
|
||||
if(regFilter.test(this.params[1])) {
|
||||
if (regFilter.test(this.params[1])) {
|
||||
namedParames = this.commander.extractNamedParameters(this.params.slice(1));
|
||||
tiddlerFilter = namedParames.filter || "[all[tiddlers]]";
|
||||
} else {
|
||||
@@ -177,7 +177,7 @@ WikiFolderMaker.prototype.saveCustomPlugin = function(pluginTiddler) {
|
||||
$tw.utils.each(pluginTiddlers,function(tiddler,title) {
|
||||
if(!tiddler.title) {
|
||||
tiddler.title = title;
|
||||
}
|
||||
}
|
||||
self.saveTiddler(directory,new $tw.Tiddler(tiddler));
|
||||
});
|
||||
};
|
||||
|
||||
@@ -26,7 +26,7 @@ exports.getSubdirectories = function(dirPath) {
|
||||
}
|
||||
});
|
||||
return subdirs;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Recursively (and synchronously) copy a directory and all its content
|
||||
@@ -83,7 +83,7 @@ exports.copyFile = function(srcPath,dstPath) {
|
||||
dstFile = fs.openSync(dstPath,"w"),
|
||||
bytesRead = 1,
|
||||
pos = 0;
|
||||
while(bytesRead > 0) {
|
||||
while (bytesRead > 0) {
|
||||
bytesRead = fs.readSync(srcFile,fileBuffer,0,FILE_BUFFER_LENGTH,pos);
|
||||
fs.writeSync(dstFile,fileBuffer,0,bytesRead);
|
||||
pos += bytesRead;
|
||||
@@ -148,7 +148,7 @@ exports.deleteDirectory = function(dirPath) {
|
||||
fs.unlinkSync(currPath);
|
||||
}
|
||||
}
|
||||
fs.rmdirSync(dirPath);
|
||||
fs.rmdirSync(dirPath);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@@ -255,7 +255,7 @@ exports.generateTiddlerFileInfo = function(tiddler,options) {
|
||||
// Overriding to the .tid extension needs special handling
|
||||
fileInfo.type = "application/x-tiddler";
|
||||
fileInfo.hasMetaFile = false;
|
||||
} else if(metaExt === ".json") {
|
||||
} else if (metaExt === ".json") {
|
||||
// Overriding to the .json extension needs special handling
|
||||
fileInfo.type = "application/json";
|
||||
fileInfo.hasMetaFile = false;
|
||||
@@ -345,18 +345,18 @@ exports.generateTiddlerFilepath = function(title,options) {
|
||||
// Replace any Windows control codes
|
||||
filepath = filepath.replace(/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i,"_$1_");
|
||||
// Replace any leading spaces with the same number of underscores
|
||||
filepath = filepath.replace(/^ +/,function (u) { return u.replace(/ /g, "_");});
|
||||
filepath = filepath.replace(/^ +/,function (u) { return u.replace(/ /g, "_")});
|
||||
//If the path does not start with "." or ".." && a path seperator, then
|
||||
if(!/^\.{1,2}[/\\]/g.test(filepath)) {
|
||||
// Don't let the filename start with any dots because such files are invisible on *nix
|
||||
filepath = filepath.replace(/^\.+/g,function (u) { return u.replace(/\./g, "_");});
|
||||
filepath = filepath.replace(/^\.+/g,function (u) { return u.replace(/\./g, "_")});
|
||||
}
|
||||
// Replace any Unicode control codes
|
||||
filepath = filepath.replace(/[\x00-\x1f\x80-\x9f]/g,"_");
|
||||
// Replace any characters that can't be used in cross-platform filenames
|
||||
filepath = $tw.utils.transliterate(filepath.replace(/<|>|~|\:|\"|\||\?|\*|\^/g,"_"));
|
||||
// Replace any dots or spaces at the end of the extension with the same number of underscores
|
||||
extension = extension.replace(/[\. ]+$/, function (u) { return u.replace(/[\. ]/g, "_");});
|
||||
extension = extension.replace(/[\. ]+$/, function (u) { return u.replace(/[\. ]/g, "_")});
|
||||
// Truncate the extension if it is too long
|
||||
if(extension.length > 32) {
|
||||
extension = extension.substr(0,32);
|
||||
@@ -382,9 +382,9 @@ exports.generateTiddlerFilepath = function(title,options) {
|
||||
}
|
||||
// Add a uniquifier if the file already exists (default)
|
||||
var fullPath = path.resolve(directory, filepath + extension);
|
||||
if(!overwrite) {
|
||||
if (!overwrite) {
|
||||
var oldPath = (options.fileInfo) ? options.fileInfo.filepath : undefined,
|
||||
count = 0;
|
||||
count = 0;
|
||||
do {
|
||||
fullPath = path.resolve(directory,filepath + (count ? "_" + count : "") + extension);
|
||||
if(oldPath && oldPath == fullPath) break;
|
||||
@@ -401,7 +401,7 @@ exports.generateTiddlerFilepath = function(title,options) {
|
||||
writePath.indexOf(path.resolve(directory)) == 0 ||
|
||||
writePath.indexOf(path.resolve($tw.boot.wikiPath)) == 0 ||
|
||||
writePath.indexOf(path.resolve($tw.boot.wikiTiddlersPath,originalpath)) == 0 );
|
||||
}
|
||||
}
|
||||
if(encode) {
|
||||
writePath = path.resolve(directory,$tw.utils.encodeURIComponentExtended(fullPath));
|
||||
}
|
||||
@@ -521,12 +521,12 @@ Cleanup old files on disk, by comparing the options values:
|
||||
*/
|
||||
exports.cleanupTiddlerFiles = function(options,callback) {
|
||||
var adaptorInfo = options.adaptorInfo || {},
|
||||
bootInfo = options.bootInfo || {},
|
||||
title = options.title || "undefined";
|
||||
bootInfo = options.bootInfo || {},
|
||||
title = options.title || "undefined";
|
||||
if(adaptorInfo.filepath && bootInfo.filepath && adaptorInfo.filepath !== bootInfo.filepath) {
|
||||
$tw.utils.deleteTiddlerFile(adaptorInfo,function(err) {
|
||||
if(err) {
|
||||
if((err.code == "EPERM" || err.code == "EACCES") && err.syscall == "unlink") {
|
||||
if ((err.code == "EPERM" || err.code == "EACCES") && err.syscall == "unlink") {
|
||||
// Error deleting the previous file on disk, should fail gracefully
|
||||
$tw.syncer.displayError("Server desynchronized. Error cleaning up previous file for tiddler: \""+title+"\"",err);
|
||||
return callback(null,bootInfo);
|
||||
|
||||
@@ -19,7 +19,7 @@ exports.info = {
|
||||
exports.handler = function(request,response,state) {
|
||||
var text = state.wiki.renderTiddler(state.server.get("root-render-type"),state.server.get("root-tiddler")),
|
||||
responseHeaders = {
|
||||
"Content-Type": state.server.get("root-serve-type")
|
||||
};
|
||||
"Content-Type": state.server.get("root-serve-type")
|
||||
};
|
||||
state.sendResponse(200,responseHeaders,text);
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ exports.info = {
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
var title = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
||||
fields = $tw.utils.parseJSONSafe(state.data);
|
||||
fields = $tw.utils.parseJSONSafe(state.data);
|
||||
// Pull up any subfields in the `fields` object
|
||||
if(fields.fields) {
|
||||
$tw.utils.each(fields.fields,function(field,name) {
|
||||
|
||||
@@ -41,7 +41,7 @@ function Server(options) {
|
||||
}
|
||||
}
|
||||
// Setup the default required plugins
|
||||
this.requiredPlugins = this.get("required-plugins").split(",");
|
||||
this.requiredPlugins = this.get("required-plugins").split(',');
|
||||
// Initialise CORS
|
||||
this.corsEnable = this.get("cors-enable") === "yes";
|
||||
// Initialise CSRF
|
||||
@@ -62,9 +62,9 @@ function Server(options) {
|
||||
this.authorizationPrincipals = {
|
||||
readers: (this.get("readers") || authorizedUserName).split(",").map($tw.utils.trim),
|
||||
writers: (this.get("writers") || authorizedUserName).split(",").map($tw.utils.trim)
|
||||
};
|
||||
}
|
||||
if(this.get("admin") || authorizedUserName !== "(anon)") {
|
||||
this.authorizationPrincipals["admin"] = (this.get("admin") || authorizedUserName).split(",").map($tw.utils.trim);
|
||||
this.authorizationPrincipals["admin"] = (this.get("admin") || authorizedUserName).split(',').map($tw.utils.trim)
|
||||
}
|
||||
// Load and initialise authenticators
|
||||
$tw.modules.forEachModuleOfType("authenticator", function(title,authenticatorDefinition) {
|
||||
@@ -91,7 +91,7 @@ function Server(options) {
|
||||
this.listenOptions = {
|
||||
key: fs.readFileSync(path.resolve(this.boot.wikiPath,tlsKeyFilepath),"utf8"),
|
||||
cert: fs.readFileSync(path.resolve(this.boot.wikiPath,tlsCertFilepath),"utf8"),
|
||||
passphrase: tlsPassphrase || ""
|
||||
passphrase: tlsPassphrase || ''
|
||||
};
|
||||
this.protocol = "https";
|
||||
}
|
||||
@@ -116,7 +116,7 @@ encoding: the encoding of the data to send (passed to the end method of the resp
|
||||
*/
|
||||
function sendResponse(request,response,statusCode,headers,data,encoding) {
|
||||
if(this.enableBrowserCache && (statusCode == 200)) {
|
||||
var hash = crypto.createHash("md5");
|
||||
var hash = crypto.createHash('md5');
|
||||
// Put everything into the hash that could change and invalidate the data that
|
||||
// the browser already stored. The headers the data and the encoding.
|
||||
hash.update(data);
|
||||
@@ -250,7 +250,7 @@ Check whether a given user is authorized for the specified authorizationType ("r
|
||||
Server.prototype.isAuthorized = function(authorizationType,username) {
|
||||
var principals = this.authorizationPrincipals[authorizationType] || [];
|
||||
return principals.indexOf("(anon)") !== -1 || (username && (principals.indexOf("(authenticated)") !== -1 || principals.indexOf(username) !== -1));
|
||||
};
|
||||
}
|
||||
|
||||
Server.prototype.requestHandler = function(request,response,options) {
|
||||
options = options || {};
|
||||
@@ -337,7 +337,7 @@ Server.prototype.requestHandler = function(request,response,options) {
|
||||
request.on("end",function() {
|
||||
state.data = Buffer.concat(data);
|
||||
route.handler(request,response,state);
|
||||
});
|
||||
})
|
||||
} else {
|
||||
response.writeHead(400,"Invalid bodyFormat " + route.bodyFormat + " in route " + route.method + " " + route.path.source);
|
||||
response.end();
|
||||
@@ -362,8 +362,8 @@ Server.prototype.listen = function(port,host,prefix) {
|
||||
}
|
||||
// Warn if required plugins are missing
|
||||
var missing = [];
|
||||
for(var index=0; index<this.requiredPlugins.length; index++) {
|
||||
if(!this.wiki.getTiddler(this.requiredPlugins[index])) {
|
||||
for (var index=0; index<this.requiredPlugins.length; index++) {
|
||||
if (!this.wiki.getTiddler(this.requiredPlugins[index])) {
|
||||
missing.push(this.requiredPlugins[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,22 +9,22 @@ Base64 UTF-8 utlity functions.
|
||||
|
||||
"use strict";
|
||||
|
||||
const { TextEncoder, TextDecoder } = require("node:util");
|
||||
const{ TextEncoder, TextDecoder } = require("node:util");
|
||||
|
||||
exports.btoa = (binstr) => Buffer.from(binstr, "binary").toString("base64");
|
||||
exports.btoa = binstr => Buffer.from(binstr, "binary").toString("base64");
|
||||
|
||||
exports.atob = (b64) => Buffer.from(b64, "base64").toString("binary");
|
||||
exports.atob = b64 => Buffer.from(b64, "base64").toString("binary");
|
||||
|
||||
function base64ToBytes(base64) {
|
||||
const binString = exports.atob(base64);
|
||||
return Uint8Array.from(binString, (m) => m.codePointAt(0));
|
||||
return Uint8Array.from(binString, m => m.codePointAt(0));
|
||||
};
|
||||
|
||||
function bytesToBase64(bytes) {
|
||||
const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join("");
|
||||
const binString = Array.from(bytes, byte => String.fromCodePoint(byte)).join("");
|
||||
return exports.btoa(binString);
|
||||
};
|
||||
|
||||
exports.base64EncodeUtf8 = (str) => bytesToBase64(new TextEncoder().encode(str));
|
||||
exports.base64EncodeUtf8 = str => bytesToBase64(new TextEncoder().encode(str));
|
||||
|
||||
exports.base64DecodeUtf8 = (str) => new TextDecoder().decode(base64ToBytes(str));
|
||||
exports.base64DecodeUtf8 = str => new TextDecoder().decode(base64ToBytes(str));
|
||||
|
||||
@@ -10,10 +10,6 @@ Advanced/ShadowInfo/Shadow/Hint: The tiddler <$link to=<<infoTiddler>>><$text te
|
||||
Advanced/ShadowInfo/Shadow/Source: It is defined in the plugin <$link to=<<pluginTiddler>>><$text text=<<pluginTiddler>>/></$link>
|
||||
Advanced/ShadowInfo/OverriddenShadow/Hint: It is overridden by an ordinary tiddler
|
||||
Advanced/CascadeInfo/Heading: Cascade Details
|
||||
Advanced/CascadeInfo/Hint: These are the view template segments (tagged <<tag "$:/tags/ViewTemplate">>) using a cascade filter and their resulting template for the current tiddler.
|
||||
Advanced/CascadeInfo/Detail/View: View
|
||||
Advanced/CascadeInfo/Detail/ActiveCascadeFilter: Active cascade filter
|
||||
Advanced/CascadeInfo/Detail/Template: Template
|
||||
Fields/Caption: Fields
|
||||
List/Caption: List
|
||||
List/Empty: This tiddler does not have a list
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
/*\
|
||||
title: $:/core/modules/background-actions.js
|
||||
type: application/javascript
|
||||
module-type: global
|
||||
|
||||
Class to dispatch actions when filters change
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
|
||||
class BackgroundActionDispatcher {
|
||||
constructor(filterTracker, wiki) {
|
||||
this.filterTracker = filterTracker;
|
||||
this.wiki = wiki;
|
||||
this.nextTrackedFilterId = 1;
|
||||
this.trackedFilters = new Map(); // Use Map for better key management
|
||||
// Track the filter for the background actions
|
||||
this.filterTracker.track({
|
||||
filterString: "[all[tiddlers+shadows]tag[$:/tags/BackgroundAction]!is[draft]]",
|
||||
fnEnter: (title) => this.trackFilter(title),
|
||||
fnLeave: (title, enterValue) => this.untrackFilter(enterValue),
|
||||
fnChange: (title, enterValue) => {
|
||||
this.untrackFilter(enterValue);
|
||||
return this.trackFilter(title);
|
||||
},
|
||||
fnProcess: (changes) => this.process(changes)
|
||||
});
|
||||
}
|
||||
|
||||
trackFilter(title) {
|
||||
const tiddler = this.wiki.getTiddler(title);
|
||||
const id = this.nextTrackedFilterId++;
|
||||
const tracker = new BackgroundActionTracker({
|
||||
wiki: this.wiki,
|
||||
title,
|
||||
trackFilter: tiddler.fields["track-filter"],
|
||||
actions: tiddler.fields.text
|
||||
});
|
||||
this.trackedFilters.set(id, tracker);
|
||||
return id;
|
||||
}
|
||||
|
||||
untrackFilter(enterValue) {
|
||||
const tracker = this.trackedFilters.get(enterValue);
|
||||
if(tracker) {
|
||||
tracker.destroy();
|
||||
}
|
||||
this.trackedFilters.delete(enterValue);
|
||||
}
|
||||
|
||||
process(changes) {
|
||||
for(const tracker of this.trackedFilters.values()) {
|
||||
tracker.process(changes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Represents an individual tracked filter. Options include:
|
||||
wiki: wiki to use
|
||||
title: title of the tiddler being tracked
|
||||
trackFilter: filter string to track changes
|
||||
actions: actions to be executed when the filter changes
|
||||
*/
|
||||
class BackgroundActionTracker {
|
||||
constructor({wiki, title, trackFilter, actions}) {
|
||||
this.wiki = wiki;
|
||||
this.title = title;
|
||||
this.trackFilter = trackFilter;
|
||||
this.actions = actions;
|
||||
this.filterTracker = new $tw.FilterTracker(this.wiki);
|
||||
this.hasChanged = false;
|
||||
this.trackerID = this.filterTracker.track({
|
||||
filterString: this.trackFilter,
|
||||
fnEnter: () => { this.hasChanged = true; },
|
||||
fnLeave: () => { this.hasChanged = true; },
|
||||
fnProcess: (changes) => {
|
||||
if(this.hasChanged) {
|
||||
this.hasChanged = false;
|
||||
console.log("Processing background action", this.title);
|
||||
const tiddler = this.wiki.getTiddler(this.title);
|
||||
let doActions = true;
|
||||
if(tiddler && tiddler.fields.platforms) {
|
||||
doActions = false;
|
||||
const platforms = $tw.utils.parseStringArray(tiddler.fields.platforms);
|
||||
if(($tw.browser && platforms.includes("browser")) || ($tw.node && platforms.includes("node"))) {
|
||||
doActions = true;
|
||||
}
|
||||
}
|
||||
if(doActions) {
|
||||
this.wiki.invokeActionString(
|
||||
this.actions,
|
||||
null,
|
||||
{
|
||||
currentTiddler: this.title
|
||||
},{
|
||||
parentWidget: $tw.rootWidget
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
process(changes) {
|
||||
this.filterTracker.handleChangeEvent(changes);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.filterTracker.untrack(this.trackerID);
|
||||
}
|
||||
}
|
||||
|
||||
exports.BackgroundActionDispatcher = BackgroundActionDispatcher;
|
||||
@@ -197,7 +197,7 @@ FramedEngine.prototype.handleFocusEvent = function(event) {
|
||||
Handle a keydown event
|
||||
*/
|
||||
FramedEngine.prototype.handleKeydownEvent = function(event) {
|
||||
if($tw.keyboardManager.handleKeydownEvent(event, {onlyPriority: true})) {
|
||||
if ($tw.keyboardManager.handleKeydownEvent(event, {onlyPriority: true})) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,12 +55,12 @@ function editTextWidgetFactory(toolbarEngine,nonToolbarEngine) {
|
||||
var editInfo = this.getEditInfo(),
|
||||
Engine = this.editShowToolbar ? toolbarEngine : nonToolbarEngine;
|
||||
this.engine = new Engine({
|
||||
widget: this,
|
||||
value: editInfo.value,
|
||||
type: editInfo.type,
|
||||
parentNode: parent,
|
||||
nextSibling: nextSibling
|
||||
});
|
||||
widget: this,
|
||||
value: editInfo.value,
|
||||
type: editInfo.type,
|
||||
parentNode: parent,
|
||||
nextSibling: nextSibling
|
||||
});
|
||||
// Call the postRender hook
|
||||
if(this.postRender) {
|
||||
this.postRender();
|
||||
@@ -220,7 +220,7 @@ function editTextWidgetFactory(toolbarEngine,nonToolbarEngine) {
|
||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.placeholder || changedAttributes.size || changedAttributes.autoHeight || changedAttributes.minHeight || changedAttributes.focusPopup || changedAttributes.rows || changedAttributes.tabindex || changedAttributes.cancelPopups || changedAttributes.inputActions || changedAttributes.refreshTitle || changedAttributes.autocomplete || changedTiddlers[HEIGHT_MODE_TITLE] || changedTiddlers[ENABLE_TOOLBAR_TITLE] || changedTiddlers["$:/palette"] || changedAttributes.disabled || changedAttributes.fileDrop) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
} else if(changedTiddlers[this.editRefreshTitle]) {
|
||||
} else if (changedTiddlers[this.editRefreshTitle]) {
|
||||
this.engine.updateDomNodeText(this.getEditInfo().value);
|
||||
} else if(changedTiddlers[this.editTitle]) {
|
||||
var editInfo = this.getEditInfo();
|
||||
@@ -274,8 +274,8 @@ function editTextWidgetFactory(toolbarEngine,nonToolbarEngine) {
|
||||
});
|
||||
if($tw.keyboardManager.checkKeyDescriptors(event,keyInfoArray)) {
|
||||
var clickEvent = this.document.createEvent("Events");
|
||||
clickEvent.initEvent("click",true,false);
|
||||
el.dispatchEvent(clickEvent);
|
||||
clickEvent.initEvent("click",true,false);
|
||||
el.dispatchEvent(clickEvent);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,7 @@ Text editor operation to excise the selection to a new tiddler
|
||||
"use strict";
|
||||
|
||||
function isMarkdown(mediaType) {
|
||||
return mediaType === "text/markdown" || mediaType === "text/x-markdown";
|
||||
return mediaType === 'text/markdown' || mediaType === 'text/x-markdown';
|
||||
}
|
||||
|
||||
exports["excise"] = function(event,operation) {
|
||||
|
||||
@@ -19,7 +19,7 @@ exports["wrap-lines"] = function(event,operation) {
|
||||
operation.cutStart = operation.selStart - (prefix.length + 1);
|
||||
operation.cutEnd = operation.selEnd + suffix.length + 1;
|
||||
// Also cut the following newline (if there is any)
|
||||
if(operation.text[operation.cutEnd] === "\n") {
|
||||
if (operation.text[operation.cutEnd] === "\n") {
|
||||
operation.cutEnd++;
|
||||
}
|
||||
// Replace with selection
|
||||
|
||||
@@ -44,7 +44,7 @@ exports["wrap-selection"] = function(event,operation) {
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
function togglePrefixSuffix() {
|
||||
if(o.text.substring(o.selStart - prefix.length, o.selStart + suffix.length) === prefix + suffix) {
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
/*\
|
||||
title: $:/core/modules/filter-tracker.js
|
||||
type: application/javascript
|
||||
module-type: global
|
||||
|
||||
Class to track the results of a filter string
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
|
||||
class FilterTracker {
|
||||
constructor(wiki) {
|
||||
this.wiki = wiki;
|
||||
this.trackers = new Map();
|
||||
this.nextTrackerId = 1;
|
||||
}
|
||||
|
||||
handleChangeEvent(changes) {
|
||||
this.processTrackers();
|
||||
this.processChanges(changes);
|
||||
}
|
||||
|
||||
/*
|
||||
Add a tracker to the filter tracker. Returns null if any of the parameters are invalid, or a tracker id if the tracker was added successfully. Options include:
|
||||
filterString: the filter string to track
|
||||
fnEnter: function to call when a title enters the filter results. Called even if the tiddler does not actually exist. Called as (title), and should return a truthy value that is stored in the tracker as the "enterValue"
|
||||
fnLeave: function to call when a title leaves the filter results. Called as (title,enterValue)
|
||||
fnChange: function to call when a tiddler changes in the filter results. Only called for filter results that identify a tiddler or shadow tiddler. Called as (title,enterValue), and may optionally return a replacement enterValue
|
||||
fnProcess: function to call each time the tracker is processed, after any enter, leave or change functions are called. Called as (changes)
|
||||
*/
|
||||
track(options = {}) {
|
||||
const {
|
||||
filterString,
|
||||
fnEnter,
|
||||
fnLeave,
|
||||
fnChange,
|
||||
fnProcess
|
||||
} = options;
|
||||
const id = this.nextTrackerId++;
|
||||
const tracker = {
|
||||
id,
|
||||
filterString,
|
||||
fnEnter,
|
||||
fnLeave,
|
||||
fnChange,
|
||||
fnProcess,
|
||||
previousResults: [],
|
||||
resultValues: {}
|
||||
};
|
||||
this.trackers.set(id, tracker);
|
||||
// Process the tracker
|
||||
this.processTracker(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
untrack(id) {
|
||||
this.trackers.delete(id);
|
||||
}
|
||||
|
||||
processTrackers() {
|
||||
for(const id of this.trackers.keys()) {
|
||||
this.processTracker(id);
|
||||
}
|
||||
}
|
||||
|
||||
processTracker(id) {
|
||||
const tracker = this.trackers.get(id);
|
||||
if(!tracker) return;
|
||||
const results = [];
|
||||
// Evaluate the filter and remove duplicate results
|
||||
$tw.utils.each(this.wiki.filterTiddlers(tracker.filterString), (title) => {
|
||||
$tw.utils.pushTop(results, title);
|
||||
});
|
||||
// Process the newly entered results
|
||||
results.forEach((title) => {
|
||||
if(!tracker.previousResults.includes(title) && !tracker.resultValues[title] && tracker.fnEnter) {
|
||||
tracker.resultValues[title] = tracker.fnEnter(title) || true;
|
||||
}
|
||||
});
|
||||
// Process the results that have just left
|
||||
tracker.previousResults.forEach((title) => {
|
||||
if(!results.includes(title) && tracker.resultValues[title] && tracker.fnLeave) {
|
||||
tracker.fnLeave(title, tracker.resultValues[title]);
|
||||
delete tracker.resultValues[title];
|
||||
}
|
||||
});
|
||||
// Update the previous results
|
||||
tracker.previousResults = results;
|
||||
}
|
||||
|
||||
processChanges(changes) {
|
||||
for(const tracker of this.trackers.values()) {
|
||||
Object.keys(changes).forEach((title) => {
|
||||
if(title && tracker.previousResults.includes(title) && tracker.fnChange) {
|
||||
tracker.resultValues[title] = tracker.fnChange(title, tracker.resultValues[title]) || tracker.resultValues[title];
|
||||
}
|
||||
});
|
||||
if(tracker.fnProcess) {
|
||||
tracker.fnProcess(changes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.FilterTracker = FilterTracker;
|
||||
@@ -24,7 +24,7 @@ exports.cascade = function(operationSubFunction,options) {
|
||||
}
|
||||
var output = filterFnList[index](options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",{defaultValue:""})
|
||||
"..currentTiddler": widget.getVariable("currentTiddler","")
|
||||
}));
|
||||
if(output.length !== 0) {
|
||||
result = output[0];
|
||||
@@ -34,5 +34,5 @@ exports.cascade = function(operationSubFunction,options) {
|
||||
results.push(result);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ exports.filter = function(operationSubFunction,options) {
|
||||
results.each(function(title) {
|
||||
var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",{defaultValue:""}),
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",""),
|
||||
"index": "" + index,
|
||||
"revIndex": "" + (results.length - 1 - index),
|
||||
"length": "" + results.length
|
||||
@@ -30,5 +30,5 @@ exports.filter = function(operationSubFunction,options) {
|
||||
});
|
||||
results.remove(resultsToRemove);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ exports.map = function(operationSubFunction,options) {
|
||||
$tw.utils.each(inputTitles,function(title) {
|
||||
var filtered = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",{defaultValue:""}),
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",""),
|
||||
"index": "" + index,
|
||||
"revIndex": "" + (inputTitles.length - 1 - index),
|
||||
"length": "" + inputTitles.length
|
||||
@@ -28,12 +28,12 @@ exports.map = function(operationSubFunction,options) {
|
||||
if(filtered.length && flatten) {
|
||||
$tw.utils.each(filtered,function(value) {
|
||||
results.push(value);
|
||||
});
|
||||
})
|
||||
} else {
|
||||
results.push(filtered[0]||"");
|
||||
}
|
||||
++index;
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ exports.reduce = function(operationSubFunction,options) {
|
||||
results.each(function(title) {
|
||||
var list = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",{defaultValue:""}),
|
||||
"..currentTiddler": widget.getVariable("currentTiddler"),
|
||||
"index": "" + index,
|
||||
"revIndex": "" + (results.length - 1 - index),
|
||||
"length": "" + results.length,
|
||||
@@ -31,5 +31,5 @@ exports.reduce = function(operationSubFunction,options) {
|
||||
results.clear();
|
||||
results.push(accumulator);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@ exports.sort = function(operationSubFunction,options) {
|
||||
results.each(function(title) {
|
||||
var key = operationSubFunction(options.wiki.makeTiddlerIterator([title]),widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": widget.getVariable("currentTiddler",{defaultValue:""})
|
||||
"..currentTiddler": widget.getVariable("currentTiddler")
|
||||
}));
|
||||
sortKeys.push(key[0] || "");
|
||||
});
|
||||
@@ -36,12 +36,12 @@ exports.sort = function(operationSubFunction,options) {
|
||||
// Sort the indexes
|
||||
compareFn = $tw.utils.makeCompareFunction(sortType,{defaultType: "string", invert:invert, isCaseSensitive:isCaseSensitive});
|
||||
indexes = indexes.sort(function(a,b) {
|
||||
return compareFn(sortKeys[a],sortKeys[b]);
|
||||
return compareFn(sortKeys[a],sortKeys[b]);
|
||||
});
|
||||
// Add to results in correct order
|
||||
$tw.utils.each(indexes,function(index) {
|
||||
results.push(inputTitles[index]);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -43,7 +43,7 @@ function parseFilterOperation(operators,filterString,p) {
|
||||
var bracket = filterString.charAt(nextBracketPos);
|
||||
operator.operator = filterString.substring(p,nextBracketPos);
|
||||
// Any suffix?
|
||||
var colon = operator.operator.indexOf(":");
|
||||
var colon = operator.operator.indexOf(':');
|
||||
if(colon > -1) {
|
||||
// The raw suffix for older filters
|
||||
operator.suffix = operator.operator.substring(colon + 1);
|
||||
@@ -67,7 +67,7 @@ function parseFilterOperation(operators,filterString,p) {
|
||||
operator.operands = [];
|
||||
var parseOperand = function(bracketType) {
|
||||
var operand = {};
|
||||
switch(bracketType) {
|
||||
switch (bracketType) {
|
||||
case "{": // Curly brackets
|
||||
operand.indirect = true;
|
||||
nextBracketPos = filterString.indexOf("}",p);
|
||||
@@ -88,8 +88,8 @@ function parseFilterOperation(operators,filterString,p) {
|
||||
rexMatch = rex.exec(filterString.substring(p));
|
||||
if(rexMatch) {
|
||||
operator.regexp = new RegExp(rexMatch[1], rexMatch[2]);
|
||||
// DEPRECATION WARNING
|
||||
console.log("WARNING: Filter",operator.operator,"has a deprecated regexp operand",operator.regexp);
|
||||
// DEPRECATION WARNING
|
||||
console.log("WARNING: Filter",operator.operator,"has a deprecated regexp operand",operator.regexp);
|
||||
nextBracketPos = p + rex.lastIndex - 1;
|
||||
}
|
||||
else {
|
||||
@@ -108,7 +108,7 @@ function parseFilterOperation(operators,filterString,p) {
|
||||
}
|
||||
operator.operands.push(operand);
|
||||
p = nextBracketPos + 1;
|
||||
};
|
||||
}
|
||||
|
||||
p = nextBracketPos + 1;
|
||||
parseOperand(bracket);
|
||||
@@ -228,7 +228,7 @@ exports.getFilterRunPrefixes = function() {
|
||||
$tw.modules.applyMethods("filterrunprefix",this.filterRunPrefixes);
|
||||
}
|
||||
return this.filterRunPrefixes;
|
||||
};
|
||||
}
|
||||
|
||||
exports.filterTiddlers = function(filterString,widget,source) {
|
||||
var fn = this.compileFilter(filterString);
|
||||
@@ -314,19 +314,19 @@ exports.compileFilter = function(filterString) {
|
||||
|
||||
// Invoke the appropriate filteroperator module
|
||||
results = operatorFunction(accumulator,{
|
||||
operator: operator.operator,
|
||||
operand: operands.length > 0 ? operands[0] : undefined,
|
||||
operands: operands,
|
||||
multiValueOperands: multiValueOperands,
|
||||
isMultiValueOperand: isMultiValueOperand,
|
||||
prefix: operator.prefix,
|
||||
suffix: operator.suffix,
|
||||
suffixes: operator.suffixes,
|
||||
regexp: operator.regexp
|
||||
},{
|
||||
wiki: self,
|
||||
widget: widget
|
||||
});
|
||||
operator: operator.operator,
|
||||
operand: operands.length > 0 ? operands[0] : undefined,
|
||||
operands: operands,
|
||||
multiValueOperands: multiValueOperands,
|
||||
isMultiValueOperand: isMultiValueOperand,
|
||||
prefix: operator.prefix,
|
||||
suffix: operator.suffix,
|
||||
suffixes: operator.suffixes,
|
||||
regexp: operator.regexp
|
||||
},{
|
||||
wiki: self,
|
||||
widget: widget
|
||||
});
|
||||
if($tw.utils.isArray(results)) {
|
||||
accumulator = self.makeTiddlerIterator(results);
|
||||
} else {
|
||||
|
||||
@@ -32,4 +32,4 @@ var modes = {
|
||||
"gt": function(value) {return value > 0;},
|
||||
"lteq": function(value) {return value <= 0;},
|
||||
"lt": function(value) {return value < 0;}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,4 +31,4 @@ exports["deserialize"] = function(source,operator,options) {
|
||||
return [$tw.language.getString("Error/DeserializeOperator/MissingOperand")];
|
||||
}
|
||||
return results;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ Export our filter function
|
||||
*/
|
||||
exports.each = function(source,operator,options) {
|
||||
var results =[] ,
|
||||
value,values = {},
|
||||
field = operator.operand || "title";
|
||||
value,values = {},
|
||||
field = operator.operand || "title";
|
||||
if(operator.suffix === "value" && field === "title") {
|
||||
source(function(tiddler,title) {
|
||||
if(!$tw.utils.hop(values,title)) {
|
||||
|
||||
@@ -53,7 +53,7 @@ exports.field = function(source,operator,options) {
|
||||
if(source.byField && operator.operand) {
|
||||
indexedResults = source.byField(fieldname,operator.operand);
|
||||
if(indexedResults) {
|
||||
return indexedResults;
|
||||
return indexedResults
|
||||
}
|
||||
}
|
||||
source(function(tiddler,title) {
|
||||
|
||||
@@ -24,7 +24,7 @@ exports.fields = function(source,operator,options) {
|
||||
for(fieldName in tiddler.fields) {
|
||||
(operand.indexOf(fieldName) !== -1) ? $tw.utils.pushTop(results,fieldName) : "";
|
||||
}
|
||||
} else if(suffixes.indexOf("exclude") !== -1) {
|
||||
} else if (suffixes.indexOf("exclude") !== -1) {
|
||||
for(fieldName in tiddler.fields) {
|
||||
(operand.indexOf(fieldName) !== -1) ? "" : $tw.utils.pushTop(results,fieldName);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ exports.filter = function(source,operator,options) {
|
||||
source(function(tiddler,title) {
|
||||
var list = filterFn.call(options.wiki,options.wiki.makeTiddlerIterator([title]),options.widget.makeFakeWidgetWithVariables({
|
||||
"currentTiddler": "" + title,
|
||||
"..currentTiddler": options.widget.getVariable("currentTiddler",{defaultValue:""})
|
||||
"..currentTiddler": options.widget.getVariable("currentTiddler","")
|
||||
}));
|
||||
if((list.length > 0) === target) {
|
||||
results.push(title);
|
||||
|
||||
@@ -12,7 +12,7 @@ Export our filter function
|
||||
exports.timestamp = function(source,operand,options) {
|
||||
var results = [];
|
||||
source(function(tiddler,title) {
|
||||
if(title.match(/^-?\d+$/)) {
|
||||
if (title.match(/^-?\d+$/)) {
|
||||
var value = new Date(Number(title));
|
||||
results.push($tw.utils.formatDateString(value,operand || "[UTC]YYYY0MM0DD0hh0mm0ss0XXX"));
|
||||
}
|
||||
|
||||
@@ -157,13 +157,13 @@ function convertDataItemValueToStrings(item) {
|
||||
if(item === undefined) {
|
||||
return undefined;
|
||||
} else if(item === null) {
|
||||
return ["null"];
|
||||
return ["null"]
|
||||
} else if(typeof item === "object") {
|
||||
var results = [],i,t;
|
||||
if(Array.isArray(item)) {
|
||||
// Return all the items in arrays recursively
|
||||
for(i=0; i<item.length; i++) {
|
||||
t = convertDataItemValueToStrings(item[i]);
|
||||
t = convertDataItemValueToStrings(item[i])
|
||||
if(t !== undefined) {
|
||||
results.push.apply(results,t);
|
||||
}
|
||||
@@ -231,7 +231,7 @@ function getItemAtIndex(item,index) {
|
||||
return item[index];
|
||||
} else if(Array.isArray(item)) {
|
||||
index = $tw.utils.parseInt(index);
|
||||
if(index < 0) { index = index + item.length; };
|
||||
if(index < 0) { index = index + item.length };
|
||||
return item[index]; // Will be undefined if index was out-of-bounds
|
||||
} else {
|
||||
return undefined;
|
||||
@@ -289,7 +289,7 @@ function setDataItem(data,indexes,value) {
|
||||
var lastIndex = indexes[indexes.length - 1];
|
||||
if(Array.isArray(current)) {
|
||||
lastIndex = $tw.utils.parseInt(lastIndex);
|
||||
if(lastIndex < 0) { lastIndex = lastIndex + current.length; };
|
||||
if(lastIndex < 0) { lastIndex = lastIndex + current.length };
|
||||
}
|
||||
// Only set indexes on objects and arrays
|
||||
if(typeof current === "object") {
|
||||
@@ -316,7 +316,7 @@ function deleteDataItem(data,indexes) {
|
||||
var lastIndex = indexes[indexes.length - 1];
|
||||
if(Array.isArray(current) && current !== null) {
|
||||
lastIndex = $tw.utils.parseInt(lastIndex);
|
||||
if(lastIndex < 0) { lastIndex = lastIndex + current.length; };
|
||||
if(lastIndex < 0) { lastIndex = lastIndex + current.length };
|
||||
// Check if index is valid before splicing
|
||||
if(lastIndex >= 0 && lastIndex < current.length) {
|
||||
current.splice(lastIndex,1);
|
||||
|
||||
@@ -25,7 +25,7 @@ exports.lookup = function(source,operator,options) {
|
||||
indexSuffix = (suffixes[1] && suffixes[1][0] === "index") ? true : false,
|
||||
target;
|
||||
if(operator.operands.length == 2) {
|
||||
target = operator.operands[1];
|
||||
target = operator.operands[1]
|
||||
} else {
|
||||
target = indexSuffix ? "0": "text";
|
||||
}
|
||||
|
||||
@@ -17,35 +17,35 @@ Note that strings are converted to numbers automatically. Trailing non-digits ar
|
||||
"use strict";
|
||||
|
||||
exports.negate = makeNumericBinaryOperator(
|
||||
function(a) {return -a;}
|
||||
function(a) {return -a}
|
||||
);
|
||||
|
||||
exports.abs = makeNumericBinaryOperator(
|
||||
function(a) {return Math.abs(a);}
|
||||
function(a) {return Math.abs(a)}
|
||||
);
|
||||
|
||||
exports.ceil = makeNumericBinaryOperator(
|
||||
function(a) {return Math.ceil(a);}
|
||||
function(a) {return Math.ceil(a)}
|
||||
);
|
||||
|
||||
exports.floor = makeNumericBinaryOperator(
|
||||
function(a) {return Math.floor(a);}
|
||||
function(a) {return Math.floor(a)}
|
||||
);
|
||||
|
||||
exports.round = makeNumericBinaryOperator(
|
||||
function(a) {return Math.round(a);}
|
||||
function(a) {return Math.round(a)}
|
||||
);
|
||||
|
||||
exports.trunc = makeNumericBinaryOperator(
|
||||
function(a) {return Math.trunc(a);}
|
||||
function(a) {return Math.trunc(a)}
|
||||
);
|
||||
|
||||
exports.untrunc = makeNumericBinaryOperator(
|
||||
function(a) {return Math.ceil(Math.abs(a)) * Math.sign(a);}
|
||||
function(a) {return Math.ceil(Math.abs(a)) * Math.sign(a)}
|
||||
);
|
||||
|
||||
exports.sign = makeNumericBinaryOperator(
|
||||
function(a) {return Math.sign(a);}
|
||||
function(a) {return Math.sign(a)}
|
||||
);
|
||||
|
||||
exports.add = makeNumericBinaryOperator(
|
||||
@@ -103,29 +103,29 @@ exports.log = makeNumericBinaryOperator(
|
||||
);
|
||||
|
||||
exports.sum = makeNumericReducingOperator(
|
||||
function(accumulator,value) {return accumulator + value;},
|
||||
function(accumulator,value) {return accumulator + value},
|
||||
0 // Initial value
|
||||
);
|
||||
|
||||
exports.product = makeNumericReducingOperator(
|
||||
function(accumulator,value) {return accumulator * value;},
|
||||
function(accumulator,value) {return accumulator * value},
|
||||
1 // Initial value
|
||||
);
|
||||
|
||||
exports.maxall = makeNumericReducingOperator(
|
||||
function(accumulator,value) {return Math.max(accumulator,value);},
|
||||
function(accumulator,value) {return Math.max(accumulator,value)},
|
||||
-Infinity // Initial value
|
||||
);
|
||||
|
||||
exports.minall = makeNumericReducingOperator(
|
||||
function(accumulator,value) {return Math.min(accumulator,value);},
|
||||
function(accumulator,value) {return Math.min(accumulator,value)},
|
||||
Infinity // Initial value
|
||||
);
|
||||
|
||||
exports.median = makeNumericArrayOperator(
|
||||
function(values) {
|
||||
var len = values.length, median;
|
||||
values.sort(function(a,b) {return a-b;});
|
||||
values.sort(function(a,b) {return a-b});
|
||||
if(len % 2) {
|
||||
// Odd, return the middle number
|
||||
median = values[(len - 1) / 2];
|
||||
@@ -138,7 +138,7 @@ exports.median = makeNumericArrayOperator(
|
||||
);
|
||||
|
||||
exports.average = makeNumericReducingOperator(
|
||||
function(accumulator,value) {return accumulator + value;},
|
||||
function(accumulator,value) {return accumulator + value},
|
||||
0, // Initial value
|
||||
function(finalValue,numberOfValues) {
|
||||
return finalValue/numberOfValues;
|
||||
@@ -146,7 +146,7 @@ exports.average = makeNumericReducingOperator(
|
||||
);
|
||||
|
||||
exports.variance = makeNumericReducingOperator(
|
||||
function(accumulator,value) {return accumulator + value;},
|
||||
function(accumulator,value) {return accumulator + value},
|
||||
0,
|
||||
function(finalValue,numberOfValues,originalValues) {
|
||||
return getVarianceFromArray(originalValues,finalValue/numberOfValues);
|
||||
@@ -154,7 +154,7 @@ exports.variance = makeNumericReducingOperator(
|
||||
);
|
||||
|
||||
exports["standard-deviation"] = makeNumericReducingOperator(
|
||||
function(accumulator,value) {return accumulator + value;},
|
||||
function(accumulator,value) {return accumulator + value},
|
||||
0,
|
||||
function(finalValue,numberOfValues,originalValues) {
|
||||
var variance = getVarianceFromArray(originalValues,finalValue/numberOfValues);
|
||||
@@ -164,31 +164,31 @@ exports["standard-deviation"] = makeNumericReducingOperator(
|
||||
|
||||
//trigonometry
|
||||
exports.cos = makeNumericBinaryOperator(
|
||||
function(a) {return Math.cos(a);}
|
||||
function(a) {return Math.cos(a)}
|
||||
);
|
||||
|
||||
exports.sin = makeNumericBinaryOperator(
|
||||
function(a) {return Math.sin(a);}
|
||||
function(a) {return Math.sin(a)}
|
||||
);
|
||||
|
||||
exports.tan = makeNumericBinaryOperator(
|
||||
function(a) {return Math.tan(a);}
|
||||
function(a) {return Math.tan(a)}
|
||||
);
|
||||
|
||||
exports.acos = makeNumericBinaryOperator(
|
||||
function(a) {return Math.acos(a);}
|
||||
function(a) {return Math.acos(a)}
|
||||
);
|
||||
|
||||
exports.asin = makeNumericBinaryOperator(
|
||||
function(a) {return Math.asin(a);}
|
||||
function(a) {return Math.asin(a)}
|
||||
);
|
||||
|
||||
exports.atan = makeNumericBinaryOperator(
|
||||
function(a) {return Math.atan(a);}
|
||||
function(a) {return Math.atan(a)}
|
||||
);
|
||||
|
||||
exports.atan2 = makeNumericBinaryOperator(
|
||||
function(a,b) {return Math.atan2(a,b);}
|
||||
function(a,b) {return Math.atan2(a,b)}
|
||||
);
|
||||
|
||||
//Calculate the variance of a population of numbers in an array given its mean
|
||||
@@ -222,8 +222,8 @@ function makeNumericReducingOperator(fnCalc,initialValue,fnFinal) {
|
||||
return [];
|
||||
}
|
||||
var value = result.reduce(function(accumulator,currentValue) {
|
||||
return fnCalc(accumulator,currentValue);
|
||||
},initialValue);
|
||||
return fnCalc(accumulator,currentValue);
|
||||
},initialValue);
|
||||
if(fnFinal) {
|
||||
value = fnFinal(value,result.length,result);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ exports.range = function(source,operator,options) {
|
||||
}
|
||||
// Process the parts
|
||||
var beg, end, inc, i, fixed = 0;
|
||||
for(i=0; i<parts.length; i++) {
|
||||
for (i=0; i<parts.length; i++) {
|
||||
// Validate real number
|
||||
if(!/^\s*[+-]?((\d+(\.\d*)?)|(\.\d+))\s*$/.test(parts[i])) {
|
||||
return ["range: bad number \"" + parts[i] + "\""];
|
||||
@@ -36,10 +36,10 @@ exports.range = function(source,operator,options) {
|
||||
switch(parts.length) {
|
||||
case 1:
|
||||
end = parts[0];
|
||||
if(end >= 1) {
|
||||
if (end >= 1) {
|
||||
beg = 1;
|
||||
}
|
||||
else if(end <= -1) {
|
||||
else if (end <= -1) {
|
||||
beg = -1;
|
||||
}
|
||||
else {
|
||||
@@ -72,7 +72,7 @@ exports.range = function(source,operator,options) {
|
||||
end += direction * 0.5 * Math.pow(0.1,fixed);
|
||||
var safety = 10010;
|
||||
// Enumerate the range
|
||||
if(end<beg) {
|
||||
if (end<beg) {
|
||||
for(i=beg; i>end; i+=inc) {
|
||||
results.push(i.toFixed(fixed));
|
||||
if(--safety<0) {
|
||||
|
||||
@@ -15,7 +15,7 @@ Export our filter function
|
||||
exports.removesuffix = function(source,operator,options) {
|
||||
var results = [],
|
||||
suffixes = (operator.suffixes || [])[0] || [];
|
||||
if(!operator.operand) {
|
||||
if (!operator.operand) {
|
||||
source(function(tiddler,title) {
|
||||
results.push(title);
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ Export our filter function
|
||||
exports.suffix = function(source,operator,options) {
|
||||
var results = [],
|
||||
suffixes = (operator.suffixes || [])[0] || [];
|
||||
if(!operator.operand) {
|
||||
if (!operator.operand) {
|
||||
source(function(tiddler,title) {
|
||||
results.push(title);
|
||||
});
|
||||
|
||||
@@ -24,4 +24,4 @@ exports.variables = function(source,operator,options) {
|
||||
}
|
||||
}
|
||||
return names.sort();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -7,224 +7,224 @@ Extended filter operators to manipulate the current list.
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
/*
|
||||
Fetch titles from the current list
|
||||
*/
|
||||
var prepare_results = function (source) {
|
||||
var prepare_results = function (source) {
|
||||
var results = [];
|
||||
source(function (tiddler, title) {
|
||||
results.push(title);
|
||||
});
|
||||
return results;
|
||||
};
|
||||
source(function (tiddler, title) {
|
||||
results.push(title);
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Moves a number of items from the tail of the current list before the item named in the operand
|
||||
*/
|
||||
exports.putbefore = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand),
|
||||
count = $tw.utils.getInt(operator.suffix,1);
|
||||
return (index === -1) ?
|
||||
results.slice(0, -1) :
|
||||
results.slice(0, index).concat(results.slice(-count)).concat(results.slice(index, -count));
|
||||
};
|
||||
exports.putbefore = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand),
|
||||
count = $tw.utils.getInt(operator.suffix,1);
|
||||
return (index === -1) ?
|
||||
results.slice(0, -1) :
|
||||
results.slice(0, index).concat(results.slice(-count)).concat(results.slice(index, -count));
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Moves a number of items from the tail of the current list after the item named in the operand
|
||||
*/
|
||||
exports.putafter = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand),
|
||||
count = $tw.utils.getInt(operator.suffix,1);
|
||||
return (index === -1) ?
|
||||
results.slice(0, -1) :
|
||||
results.slice(0, index + 1).concat(results.slice(-count)).concat(results.slice(index + 1, -count));
|
||||
};
|
||||
exports.putafter = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand),
|
||||
count = $tw.utils.getInt(operator.suffix,1);
|
||||
return (index === -1) ?
|
||||
results.slice(0, -1) :
|
||||
results.slice(0, index + 1).concat(results.slice(-count)).concat(results.slice(index + 1, -count));
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Replaces the item named in the operand with a number of items from the tail of the current list
|
||||
*/
|
||||
exports.replace = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand),
|
||||
count = $tw.utils.getInt(operator.suffix,1);
|
||||
return (index === -1) ?
|
||||
results.slice(0, -count) :
|
||||
results.slice(0, index).concat(results.slice(-count)).concat(results.slice(index + 1, -count));
|
||||
};
|
||||
exports.replace = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand),
|
||||
count = $tw.utils.getInt(operator.suffix,1);
|
||||
return (index === -1) ?
|
||||
results.slice(0, -count) :
|
||||
results.slice(0, index).concat(results.slice(-count)).concat(results.slice(index + 1, -count));
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Moves a number of items from the tail of the current list to the head of the list
|
||||
*/
|
||||
exports.putfirst = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
count = $tw.utils.getInt(operator.suffix,1);
|
||||
return results.slice(-count).concat(results.slice(0, -count));
|
||||
};
|
||||
exports.putfirst = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
count = $tw.utils.getInt(operator.suffix,1);
|
||||
return results.slice(-count).concat(results.slice(0, -count));
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Moves a number of items from the head of the current list to the tail of the list
|
||||
*/
|
||||
exports.putlast = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
count = $tw.utils.getInt(operator.suffix,1);
|
||||
return results.slice(count).concat(results.slice(0, count));
|
||||
};
|
||||
exports.putlast = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
count = $tw.utils.getInt(operator.suffix,1);
|
||||
return results.slice(count).concat(results.slice(0, count));
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Moves the item named in the operand a number of places forward or backward in the list
|
||||
*/
|
||||
exports.move = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand),
|
||||
count = $tw.utils.getInt(operator.suffix,1),
|
||||
marker = results.splice(index, 1),
|
||||
offset = (index + count) > 0 ? index + count : 0;
|
||||
return results.slice(0, offset).concat(marker).concat(results.slice(offset));
|
||||
};
|
||||
exports.move = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand),
|
||||
count = $tw.utils.getInt(operator.suffix,1),
|
||||
marker = results.splice(index, 1),
|
||||
offset = (index + count) > 0 ? index + count : 0;
|
||||
return results.slice(0, offset).concat(marker).concat(results.slice(offset));
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Returns the items from the current list that are after the item named in the operand
|
||||
*/
|
||||
exports.allafter = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand);
|
||||
return (index === -1) ? [] :
|
||||
(operator.suffix) ? results.slice(index) :
|
||||
exports.allafter = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand);
|
||||
return (index === -1) ? [] :
|
||||
(operator.suffix) ? results.slice(index) :
|
||||
results.slice(index + 1);
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Returns the items from the current list that are before the item named in the operand
|
||||
*/
|
||||
exports.allbefore = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand);
|
||||
return (index === -1) ? [] :
|
||||
(operator.suffix) ? results.slice(0, index + 1) :
|
||||
exports.allbefore = function (source, operator) {
|
||||
var results = prepare_results(source),
|
||||
index = results.indexOf(operator.operand);
|
||||
return (index === -1) ? [] :
|
||||
(operator.suffix) ? results.slice(0, index + 1) :
|
||||
results.slice(0, index);
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Appends the items listed in the operand array to the tail of the current list
|
||||
*/
|
||||
exports.append = function (source, operator) {
|
||||
var append = $tw.utils.parseStringArray(operator.operand, "true"),
|
||||
results = prepare_results(source),
|
||||
count = parseInt(operator.suffix) || append.length;
|
||||
return (append.length === 0) ? results :
|
||||
(operator.prefix) ? results.concat(append.slice(-count)) :
|
||||
exports.append = function (source, operator) {
|
||||
var append = $tw.utils.parseStringArray(operator.operand, "true"),
|
||||
results = prepare_results(source),
|
||||
count = parseInt(operator.suffix) || append.length;
|
||||
return (append.length === 0) ? results :
|
||||
(operator.prefix) ? results.concat(append.slice(-count)) :
|
||||
results.concat(append.slice(0, count));
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Prepends the items listed in the operand array to the head of the current list
|
||||
*/
|
||||
exports.prepend = function (source, operator) {
|
||||
var prepend = $tw.utils.parseStringArray(operator.operand, "true"),
|
||||
results = prepare_results(source),
|
||||
count = $tw.utils.getInt(operator.suffix,prepend.length);
|
||||
return (prepend.length === 0) ? results :
|
||||
(operator.prefix) ? prepend.slice(-count).concat(results) :
|
||||
exports.prepend = function (source, operator) {
|
||||
var prepend = $tw.utils.parseStringArray(operator.operand, "true"),
|
||||
results = prepare_results(source),
|
||||
count = $tw.utils.getInt(operator.suffix,prepend.length);
|
||||
return (prepend.length === 0) ? results :
|
||||
(operator.prefix) ? prepend.slice(-count).concat(results) :
|
||||
prepend.slice(0, count).concat(results);
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Returns all items from the current list except the items listed in the operand array
|
||||
*/
|
||||
exports.remove = function (source, operator) {
|
||||
var array = $tw.utils.parseStringArray(operator.operand, "true"),
|
||||
results = prepare_results(source),
|
||||
count = parseInt(operator.suffix) || array.length,
|
||||
p,
|
||||
len,
|
||||
index;
|
||||
len = array.length - 1;
|
||||
for(p = 0; p < count; ++p) {
|
||||
if(operator.prefix) {
|
||||
index = results.indexOf(array[len - p]);
|
||||
} else {
|
||||
index = results.indexOf(array[p]);
|
||||
exports.remove = function (source, operator) {
|
||||
var array = $tw.utils.parseStringArray(operator.operand, "true"),
|
||||
results = prepare_results(source),
|
||||
count = parseInt(operator.suffix) || array.length,
|
||||
p,
|
||||
len,
|
||||
index;
|
||||
len = array.length - 1;
|
||||
for (p = 0; p < count; ++p) {
|
||||
if (operator.prefix) {
|
||||
index = results.indexOf(array[len - p]);
|
||||
} else {
|
||||
index = results.indexOf(array[p]);
|
||||
}
|
||||
if (index !== -1) {
|
||||
results.splice(index, 1);
|
||||
}
|
||||
}
|
||||
if(index !== -1) {
|
||||
results.splice(index, 1);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
};
|
||||
return results;
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Returns all items from the current list sorted in the order of the items in the operand array
|
||||
*/
|
||||
exports.sortby = function (source, operator) {
|
||||
var results = prepare_results(source);
|
||||
if(!results || results.length < 2) {
|
||||
exports.sortby = function (source, operator) {
|
||||
var results = prepare_results(source);
|
||||
if (!results || results.length < 2) {
|
||||
return results;
|
||||
}
|
||||
var lookup = $tw.utils.parseStringArray(operator.operand, "true");
|
||||
results.sort(function (a, b) {
|
||||
return lookup.indexOf(a) - lookup.indexOf(b);
|
||||
});
|
||||
return results;
|
||||
}
|
||||
var lookup = $tw.utils.parseStringArray(operator.operand, "true");
|
||||
results.sort(function (a, b) {
|
||||
return lookup.indexOf(a) - lookup.indexOf(b);
|
||||
});
|
||||
return results;
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Removes all duplicate items from the current list
|
||||
*/
|
||||
exports.unique = function (source, operator) {
|
||||
var results = prepare_results(source);
|
||||
var set = results.reduce(function (a, b) {
|
||||
if(a.indexOf(b) < 0) {
|
||||
a.push(b);
|
||||
}
|
||||
return a;
|
||||
}, []);
|
||||
return set;
|
||||
};
|
||||
exports.unique = function (source, operator) {
|
||||
var results = prepare_results(source);
|
||||
var set = results.reduce(function (a, b) {
|
||||
if (a.indexOf(b) < 0) {
|
||||
a.push(b);
|
||||
}
|
||||
return a;
|
||||
}, []);
|
||||
return set;
|
||||
};
|
||||
|
||||
var cycleValueInArray = function(results,operands,stepSize) {
|
||||
var resultsIndex,
|
||||
step = stepSize || 1,
|
||||
i = 0,
|
||||
opLength = operands.length,
|
||||
nextOperandIndex;
|
||||
for(i; i < opLength; i++) {
|
||||
resultsIndex = results.indexOf(operands[i]);
|
||||
var cycleValueInArray = function(results,operands,stepSize) {
|
||||
var resultsIndex,
|
||||
step = stepSize || 1,
|
||||
i = 0,
|
||||
opLength = operands.length,
|
||||
nextOperandIndex;
|
||||
for(i; i < opLength; i++) {
|
||||
resultsIndex = results.indexOf(operands[i]);
|
||||
if(resultsIndex !== -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(resultsIndex !== -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(resultsIndex !== -1) {
|
||||
i = i + step;
|
||||
nextOperandIndex = (i < opLength ? i : i % opLength);
|
||||
if(operands.length > 1) {
|
||||
results.splice(resultsIndex,1,operands[nextOperandIndex]);
|
||||
i = i + step;
|
||||
nextOperandIndex = (i < opLength ? i : i % opLength);
|
||||
if(operands.length > 1) {
|
||||
results.splice(resultsIndex,1,operands[nextOperandIndex]);
|
||||
} else {
|
||||
results.splice(resultsIndex,1);
|
||||
}
|
||||
} else {
|
||||
results.splice(resultsIndex,1);
|
||||
results.push(operands[0]);
|
||||
}
|
||||
} else {
|
||||
results.push(operands[0]);
|
||||
return results;
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
/*
|
||||
/*
|
||||
Toggles an item in the current list.
|
||||
*/
|
||||
exports.toggle = function(source,operator) {
|
||||
return cycleValueInArray(prepare_results(source),operator.operands);
|
||||
};
|
||||
|
||||
exports.cycle = function(source,operator) {
|
||||
var results = prepare_results(source),
|
||||
operands = (operator.operand.length ? $tw.utils.parseStringArray(operator.operand, "true") : [""]),
|
||||
step = $tw.utils.getInt(operator.operands[1]||"",1);
|
||||
if(step < 0) {
|
||||
operands.reverse();
|
||||
step = Math.abs(step);
|
||||
exports.toggle = function(source,operator) {
|
||||
return cycleValueInArray(prepare_results(source),operator.operands);
|
||||
}
|
||||
|
||||
exports.cycle = function(source,operator) {
|
||||
var results = prepare_results(source),
|
||||
operands = (operator.operand.length ? $tw.utils.parseStringArray(operator.operand, "true") : [""]),
|
||||
step = $tw.utils.getInt(operator.operands[1]||"",1);
|
||||
if(step < 0) {
|
||||
operands.reverse();
|
||||
step = Math.abs(step);
|
||||
}
|
||||
return cycleValueInArray(results,operands,step);
|
||||
}
|
||||
return cycleValueInArray(results,operands,step);
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ function BackSubIndexer(indexer,extractor) {
|
||||
BackSubIndexer.prototype.init = function() {
|
||||
// lazy init until first lookup
|
||||
this.index = null;
|
||||
};
|
||||
}
|
||||
|
||||
BackSubIndexer.prototype._init = function() {
|
||||
this.index = Object.create(null);
|
||||
@@ -60,11 +60,11 @@ BackSubIndexer.prototype._init = function() {
|
||||
self.index[target][sourceTitle] = true;
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
BackSubIndexer.prototype.rebuild = function() {
|
||||
this.index = null;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Get things that is being referenced in the text, e.g. tiddler names in the link syntax.
|
||||
@@ -78,7 +78,7 @@ BackSubIndexer.prototype._getTarget = function(tiddler) {
|
||||
return this.wiki[this.extractor](parser.tree, tiddler.fields.title);
|
||||
}
|
||||
return [];
|
||||
};
|
||||
}
|
||||
|
||||
BackSubIndexer.prototype.update = function(updateDescriptor) {
|
||||
// lazy init/update until first lookup
|
||||
@@ -86,8 +86,8 @@ BackSubIndexer.prototype.update = function(updateDescriptor) {
|
||||
return;
|
||||
}
|
||||
var newTargets = [],
|
||||
oldTargets = [],
|
||||
self = this;
|
||||
oldTargets = [],
|
||||
self = this;
|
||||
if(updateDescriptor.old.exists) {
|
||||
oldTargets = this._getTarget(updateDescriptor.old.tiddler);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ BackSubIndexer.prototype.update = function(updateDescriptor) {
|
||||
}
|
||||
self.index[target][updateDescriptor.new.tiddler.fields.title] = true;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
BackSubIndexer.prototype.lookup = function(title) {
|
||||
if(!this.index) {
|
||||
@@ -117,6 +117,6 @@ BackSubIndexer.prototype.lookup = function(title) {
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.BackIndexer = BackIndexer;
|
||||
|
||||
@@ -19,7 +19,7 @@ FieldIndexer.prototype.init = function() {
|
||||
this.index = null;
|
||||
this.maxIndexedValueLength = DEFAULT_MAXIMUM_INDEXED_VALUE_LENGTH;
|
||||
this.addIndexMethods();
|
||||
};
|
||||
}
|
||||
|
||||
// Provided for testing
|
||||
FieldIndexer.prototype.setMaxIndexedValueLength = function(length) {
|
||||
@@ -33,14 +33,14 @@ FieldIndexer.prototype.addIndexMethods = function() {
|
||||
this.wiki.each.byField = function(name,value) {
|
||||
var lookup = self.lookup(name,value);
|
||||
return lookup && lookup.filter(function(title) {
|
||||
return self.wiki.tiddlerExists(title);
|
||||
return self.wiki.tiddlerExists(title)
|
||||
});
|
||||
};
|
||||
// get shadow tiddlers, including shadow tiddlers that is overwritten
|
||||
this.wiki.eachShadow.byField = function(name,value) {
|
||||
var lookup = self.lookup(name,value);
|
||||
return lookup && lookup.filter(function(title) {
|
||||
return self.wiki.isShadowTiddler(title);
|
||||
return self.wiki.isShadowTiddler(title)
|
||||
});
|
||||
};
|
||||
this.wiki.eachTiddlerPlusShadows.byField = function(name,value) {
|
||||
|
||||
@@ -14,12 +14,12 @@ exports.getInfoTiddlerFields = function(updateInfoTiddlersCallback) {
|
||||
this.updateCallback = updateCallback;
|
||||
this.resizeHandlers = new Map();
|
||||
this.dimensionsInfo = [
|
||||
["outer/width", (win) => win.outerWidth],
|
||||
["outer/height", (win) => win.outerHeight],
|
||||
["inner/width", (win) => win.innerWidth],
|
||||
["inner/height", (win) => win.innerHeight],
|
||||
["client/width", (win) => win.document.documentElement.clientWidth],
|
||||
["client/height", (win) => win.document.documentElement.clientHeight]
|
||||
["outer/width", win => win.outerWidth],
|
||||
["outer/height", win => win.outerHeight],
|
||||
["inner/width", win => win.innerWidth],
|
||||
["inner/height", win => win.innerHeight],
|
||||
["client/width", win => win.document.documentElement.clientWidth],
|
||||
["client/height", win => win.document.documentElement.clientHeight]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*\
|
||||
title: $:/core/modules/info/mediaquerytracker.js
|
||||
type: application/javascript
|
||||
module-type: info
|
||||
|
||||
Initialise $:/info/ tiddlers derived from media queries via
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
|
||||
exports.getInfoTiddlerFields = function(updateInfoTiddlersCallback) {
|
||||
if($tw.browser) {
|
||||
// Functions to start and stop tracking a particular media query tracker tiddler
|
||||
function track(title) {
|
||||
var result = {},
|
||||
tiddler = $tw.wiki.getTiddler(title);
|
||||
if(tiddler) {
|
||||
var mediaQuery = tiddler.fields["media-query"],
|
||||
infoTiddler = tiddler.fields["info-tiddler"],
|
||||
infoTiddlerAlt = tiddler.fields["info-tiddler-alt"];
|
||||
if(mediaQuery && infoTiddler) {
|
||||
// Evaluate and track the media query
|
||||
result.mqList = window.matchMedia(mediaQuery);
|
||||
function getResultTiddlers() {
|
||||
var value = result.mqList.matches ? "yes" : "no",
|
||||
tiddlers = [];
|
||||
tiddlers.push({title: infoTiddler, text: value});
|
||||
if(infoTiddlerAlt) {
|
||||
tiddlers.push({title: infoTiddlerAlt, text: value});
|
||||
}
|
||||
return tiddlers;
|
||||
};
|
||||
updateInfoTiddlersCallback(getResultTiddlers());
|
||||
result.handler = function(event) {
|
||||
updateInfoTiddlersCallback(getResultTiddlers());
|
||||
};
|
||||
result.mqList.addEventListener("change",result.handler);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function untrack(enterValue) {
|
||||
if(enterValue.mqList && enterValue.handler) {
|
||||
enterValue.mqList.removeEventListener("change",enterValue.handler);
|
||||
}
|
||||
}
|
||||
// Track media query tracker tiddlers
|
||||
function fnEnter(title) {
|
||||
return track(title);
|
||||
}
|
||||
function fnLeave(title,enterValue) {
|
||||
untrack(enterValue);
|
||||
}
|
||||
function fnChange(title,enterValue) {
|
||||
untrack(enterValue);
|
||||
return track(title);
|
||||
}
|
||||
$tw.filterTracker.track({
|
||||
filterString: "[all[tiddlers+shadows]tag[$:/tags/MediaQueryTracker]!is[draft]]",
|
||||
fnEnter: fnEnter,
|
||||
fnLeave: fnLeave,
|
||||
fnChange: fnChange
|
||||
});
|
||||
}
|
||||
return [];
|
||||
};
|
||||
@@ -33,6 +33,13 @@ exports.getInfoTiddlerFields = function(updateInfoTiddlersCallback) {
|
||||
// Screen size
|
||||
infoTiddlerFields.push({title: "$:/info/browser/screen/width", text: window.screen.width.toString()});
|
||||
infoTiddlerFields.push({title: "$:/info/browser/screen/height", text: window.screen.height.toString()});
|
||||
// Dark mode through event listener on MediaQueryList
|
||||
var mqList = window.matchMedia("(prefers-color-scheme: dark)"),
|
||||
getDarkModeTiddler = function() {return {title: "$:/info/darkmode", text: mqList.matches ? "yes" : "no"};};
|
||||
infoTiddlerFields.push(getDarkModeTiddler());
|
||||
mqList.addListener(function(event) {
|
||||
updateInfoTiddlersCallback([getDarkModeTiddler()]);
|
||||
});
|
||||
// Language
|
||||
infoTiddlerFields.push({title: "$:/info/browser/language", text: navigator.language || ""});
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ function KeyboardManager(options) {
|
||||
this.shortcutParsedList = []; // Stores the parsed key descriptors
|
||||
this.shortcutPriorityList = []; // Stores the parsed shortcut priority
|
||||
this.lookupNames = ["shortcuts"];
|
||||
this.lookupNames.push($tw.platform.isMac ? "shortcuts-mac" : "shortcuts-not-mac");
|
||||
this.lookupNames.push($tw.platform.isMac ? "shortcuts-mac" : "shortcuts-not-mac")
|
||||
this.lookupNames.push($tw.platform.isWindows ? "shortcuts-windows" : "shortcuts-not-windows");
|
||||
this.lookupNames.push($tw.platform.isLinux ? "shortcuts-linux" : "shortcuts-not-linux");
|
||||
this.updateShortcutLists(this.getShortcutTiddlerList());
|
||||
@@ -161,7 +161,7 @@ KeyboardManager.prototype.getModifierKeys = function() {
|
||||
91, // Meta (left)
|
||||
93, // Meta (right)
|
||||
224 // Meta (Firefox)
|
||||
];
|
||||
]
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -266,7 +266,7 @@ KeyboardManager.prototype.getPrintableShortcuts = function(keyInfoArray) {
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
KeyboardManager.prototype.checkKeyDescriptor = function(event,keyInfo) {
|
||||
return keyInfo &&
|
||||
@@ -293,15 +293,15 @@ KeyboardManager.prototype.getMatchingKeyDescriptor = function(event,keyInfoArray
|
||||
KeyboardManager.prototype.getEventModifierKeyDescriptor = function(event) {
|
||||
return event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey ? "ctrl" :
|
||||
event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ? "shift" :
|
||||
event.ctrlKey && event.shiftKey && !event.altKey && !event.metaKey ? "ctrl-shift" :
|
||||
event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey ? "alt" :
|
||||
event.altKey && event.shiftKey && !event.ctrlKey && !event.metaKey ? "alt-shift" :
|
||||
event.altKey && event.ctrlKey && !event.shiftKey && !event.metaKey ? "ctrl-alt" :
|
||||
event.altKey && event.shiftKey && event.ctrlKey && !event.metaKey ? "ctrl-alt-shift" :
|
||||
event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey ? "meta" :
|
||||
event.metaKey && event.ctrlKey && !event.shiftKey && !event.altKey ? "meta-ctrl" :
|
||||
event.metaKey && event.ctrlKey && event.shiftKey && !event.altKey ? "meta-ctrl-shift" :
|
||||
event.metaKey && event.ctrlKey && event.shiftKey && event.altKey ? "meta-ctrl-alt-shift" : "normal";
|
||||
event.ctrlKey && event.shiftKey && !event.altKey && !event.metaKey ? "ctrl-shift" :
|
||||
event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey ? "alt" :
|
||||
event.altKey && event.shiftKey && !event.ctrlKey && !event.metaKey ? "alt-shift" :
|
||||
event.altKey && event.ctrlKey && !event.shiftKey && !event.metaKey ? "ctrl-alt" :
|
||||
event.altKey && event.shiftKey && event.ctrlKey && !event.metaKey ? "ctrl-alt-shift" :
|
||||
event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey ? "meta" :
|
||||
event.metaKey && event.ctrlKey && !event.shiftKey && !event.altKey ? "meta-ctrl" :
|
||||
event.metaKey && event.ctrlKey && event.shiftKey && !event.altKey ? "meta-ctrl-shift" :
|
||||
event.metaKey && event.ctrlKey && event.shiftKey && event.altKey ? "meta-ctrl-alt-shift" : "normal";
|
||||
};
|
||||
|
||||
KeyboardManager.prototype.getShortcutTiddlerList = function() {
|
||||
@@ -371,8 +371,8 @@ KeyboardManager.prototype.handleShortcutChanges = function(changedTiddlers) {
|
||||
var newList = this.getShortcutTiddlerList();
|
||||
var hasChanged = $tw.utils.hopArray(changedTiddlers,this.shortcutTiddlers) ? true :
|
||||
($tw.utils.hopArray(changedTiddlers,newList) ? true :
|
||||
(this.detectNewShortcuts(changedTiddlers))
|
||||
);
|
||||
(this.detectNewShortcuts(changedTiddlers))
|
||||
);
|
||||
// Re-cache shortcuts if something changed
|
||||
if(hasChanged) {
|
||||
this.updateShortcutLists(newList);
|
||||
|
||||
@@ -46,24 +46,24 @@ exports.run = function(filter,format) {
|
||||
var p = fields.indexOf(value);
|
||||
if(p !== -1) {
|
||||
fields.splice(p,1);
|
||||
fields.unshift(value);
|
||||
fields.unshift(value)
|
||||
}
|
||||
});
|
||||
// Output the column headings
|
||||
var output = [], row = [];
|
||||
fields.forEach(function(value) {
|
||||
row.push(quoteAndEscape(value));
|
||||
row.push(quoteAndEscape(value))
|
||||
});
|
||||
output.push(row.join(","));
|
||||
// Output each tiddler
|
||||
for(var t=0;t<tiddlers.length; t++) {
|
||||
row = [];
|
||||
tiddler = this.wiki.getTiddler(tiddlers[t]);
|
||||
if(tiddler) {
|
||||
for(f=0; f<fields.length; f++) {
|
||||
row.push(quoteAndEscape(tiddler ? tiddler.getFieldString(fields[f]) || "" : ""));
|
||||
}
|
||||
}
|
||||
if(tiddler) {
|
||||
for(f=0; f<fields.length; f++) {
|
||||
row.push(quoteAndEscape(tiddler ? tiddler.getFieldString(fields[f]) || "" : ""));
|
||||
}
|
||||
}
|
||||
output.push(row.join(","));
|
||||
}
|
||||
return output.join("\n");
|
||||
|
||||
@@ -31,8 +31,8 @@ exports.run = function(shortcuts,prefix,separator,suffix) {
|
||||
}));
|
||||
if(shortcutArray.length > 0) {
|
||||
shortcutArray.sort(function(a,b) {
|
||||
return a.toLowerCase().localeCompare(b.toLowerCase());
|
||||
});
|
||||
return a.toLowerCase().localeCompare(b.toLowerCase());
|
||||
})
|
||||
return prefix + shortcutArray.join(separator) + suffix;
|
||||
} else {
|
||||
return "";
|
||||
|
||||
@@ -13,13 +13,13 @@ The audio parser parses an audio tiddler into an embeddable HTML element
|
||||
|
||||
var AudioParser = function(type,text,options) {
|
||||
var element = {
|
||||
type: "element",
|
||||
tag: "$audio", // Using $audio to enable widget interception
|
||||
attributes: {
|
||||
controls: {type: "string", value: "controls"},
|
||||
style: {type: "string", value: "width: 100%; object-fit: contain"}
|
||||
}
|
||||
};
|
||||
type: "element",
|
||||
tag: "$audio", // Using $audio to enable widget interception
|
||||
attributes: {
|
||||
controls: {type: "string", value: "controls"},
|
||||
style: {type: "string", value: "width: 100%; object-fit: contain"}
|
||||
}
|
||||
};
|
||||
|
||||
// Pass through source information
|
||||
if(options._canonical_uri) {
|
||||
|
||||
@@ -59,7 +59,7 @@ var BinaryParser = function(type,text,options) {
|
||||
class: {type: "string", value: "tc-binary-warning"}
|
||||
},
|
||||
children: [warn, link]
|
||||
};
|
||||
}
|
||||
this.tree = [element];
|
||||
this.source = text;
|
||||
this.type = type;
|
||||
|
||||
@@ -45,7 +45,7 @@ var CsvParser = function(type,text,options) {
|
||||
row.children.push({
|
||||
"type": "element", "tag": tag, "children": [{
|
||||
"type": "text",
|
||||
"text": columns[column] || ""
|
||||
"text": columns[column] || ''
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ exports.parseWhiteSpace = function(source,pos) {
|
||||
type: "whitespace",
|
||||
start: pos,
|
||||
end: p
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -143,14 +143,7 @@ exports.parseParameterDefinition = function(paramString,options) {
|
||||
var paramInfo = {name: paramMatch[1]},
|
||||
defaultValue = paramMatch[2] || paramMatch[3] || paramMatch[4] || paramMatch[5];
|
||||
if(defaultValue !== undefined) {
|
||||
// Check for an MVV reference ((varname))
|
||||
var mvvDefaultMatch = /^\(\(([^)|]+)\)\)$/.exec(defaultValue);
|
||||
if(mvvDefaultMatch) {
|
||||
paramInfo.defaultType = "multivalue-variable";
|
||||
paramInfo.defaultVariable = mvvDefaultMatch[1];
|
||||
} else {
|
||||
paramInfo["default"] = defaultValue;
|
||||
}
|
||||
paramInfo["default"] = defaultValue;
|
||||
}
|
||||
params.push(paramInfo);
|
||||
// Look for the next parameter
|
||||
@@ -170,7 +163,7 @@ exports.parseMacroParameters = function(node,source,pos) {
|
||||
}
|
||||
node.end = pos;
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Look for a macro invocation parameter. Returns null if not found, or {type: "macro-parameter", name:, value:, start:, end:}
|
||||
@@ -192,16 +185,16 @@ exports.parseMacroParameter = function(source,pos) {
|
||||
pos = token.end;
|
||||
// Get the parameter details
|
||||
node.value = token.match[2] !== undefined ? token.match[2] : (
|
||||
token.match[3] !== undefined ? token.match[3] : (
|
||||
token.match[4] !== undefined ? token.match[4] : (
|
||||
token.match[5] !== undefined ? token.match[5] : (
|
||||
token.match[6] !== undefined ? token.match[6] : (
|
||||
""
|
||||
token.match[3] !== undefined ? token.match[3] : (
|
||||
token.match[4] !== undefined ? token.match[4] : (
|
||||
token.match[5] !== undefined ? token.match[5] : (
|
||||
token.match[6] !== undefined ? token.match[6] : (
|
||||
""
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
);
|
||||
if(token.match[1]) {
|
||||
node.name = token.match[1];
|
||||
}
|
||||
@@ -254,46 +247,6 @@ exports.parseMacroInvocationAsTransclusion = function(source,pos) {
|
||||
return node;
|
||||
};
|
||||
|
||||
/*
|
||||
Look for an MVV (multi-valued variable) reference as a transclusion, i.e. ((varname)) or ((varname params))
|
||||
Returns null if not found, or a parse tree node of type "transclude" with isMVV: true
|
||||
*/
|
||||
exports.parseMVVReferenceAsTransclusion = function(source,pos) {
|
||||
var node = {
|
||||
type: "transclude",
|
||||
isMVV: true,
|
||||
start: pos,
|
||||
attributes: {},
|
||||
orderedAttributes: []
|
||||
};
|
||||
// Define our regexps
|
||||
var reVarName = /([^\s>"'=:)]+)/g;
|
||||
// Skip whitespace
|
||||
pos = $tw.utils.skipWhiteSpace(source,pos);
|
||||
// Look for a double opening parenthesis
|
||||
var token = $tw.utils.parseTokenString(source,pos,"((");
|
||||
if(!token) {
|
||||
return null;
|
||||
}
|
||||
pos = token.end;
|
||||
// Get the variable name
|
||||
token = $tw.utils.parseTokenRegExp(source,pos,reVarName);
|
||||
if(!token) {
|
||||
return null;
|
||||
}
|
||||
$tw.utils.addAttributeToParseTreeNode(node,"$variable",token.match[1]);
|
||||
pos = token.end;
|
||||
// Skip whitespace
|
||||
pos = $tw.utils.skipWhiteSpace(source,pos);
|
||||
// Look for a double closing parenthesis
|
||||
token = $tw.utils.parseTokenString(source,pos,"))");
|
||||
if(!token) {
|
||||
return null;
|
||||
}
|
||||
node.end = token.end;
|
||||
return node;
|
||||
};
|
||||
|
||||
/*
|
||||
Parse macro parameters as attributes. Returns the position after the last attribute
|
||||
*/
|
||||
@@ -368,20 +321,19 @@ exports.parseMacroParameterAsAttribute = function(source,pos) {
|
||||
node.type = "indirect";
|
||||
node.textReference = indirectValue.match[1];
|
||||
} else {
|
||||
// Look for a macro invocation value
|
||||
var macroInvocation = $tw.utils.parseMacroInvocationAsTransclusion(source,pos);
|
||||
if(macroInvocation && isNewStyleSeparator) {
|
||||
pos = macroInvocation.end;
|
||||
node.type = "macro";
|
||||
node.value = macroInvocation;
|
||||
// Look for a unquoted value
|
||||
var unquotedValue = $tw.utils.parseTokenRegExp(source,pos,reUnquotedAttribute);
|
||||
if(unquotedValue) {
|
||||
pos = unquotedValue.end;
|
||||
node.type = "string";
|
||||
node.value = unquotedValue.match[1];
|
||||
} else {
|
||||
// Look for an MVV reference value
|
||||
var mvvReference = $tw.utils.parseMVVReferenceAsTransclusion(source,pos);
|
||||
if(mvvReference && isNewStyleSeparator) {
|
||||
pos = mvvReference.end;
|
||||
// Look for a macro invocation value
|
||||
var macroInvocation = $tw.utils.parseMacroInvocationAsTransclusion(source,pos);
|
||||
if(macroInvocation && isNewStyleSeparator) {
|
||||
pos = macroInvocation.end;
|
||||
node.type = "macro";
|
||||
node.value = mvvReference;
|
||||
node.isMVV = true;
|
||||
node.value = macroInvocation;
|
||||
} else {
|
||||
var substitutedValue = $tw.utils.parseTokenRegExp(source,pos,reSubstitutedValue);
|
||||
if(substitutedValue && isNewStyleSeparator) {
|
||||
@@ -389,14 +341,6 @@ exports.parseMacroParameterAsAttribute = function(source,pos) {
|
||||
node.type = "substituted";
|
||||
node.rawValue = substitutedValue.match[1] || substitutedValue.match[2];
|
||||
} else {
|
||||
// Look for a unquoted value
|
||||
var unquotedValue = $tw.utils.parseTokenRegExp(source,pos,reUnquotedAttribute);
|
||||
if(unquotedValue) {
|
||||
pos = unquotedValue.end;
|
||||
node.type = "string";
|
||||
node.value = unquotedValue.match[1];
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -527,20 +471,19 @@ exports.parseAttribute = function(source,pos) {
|
||||
node.type = "indirect";
|
||||
node.textReference = indirectValue.match[1];
|
||||
} else {
|
||||
// Look for a macro invocation value
|
||||
var macroInvocation = $tw.utils.parseMacroInvocationAsTransclusion(source,pos);
|
||||
if(macroInvocation) {
|
||||
pos = macroInvocation.end;
|
||||
node.type = "macro";
|
||||
node.value = macroInvocation;
|
||||
// Look for a unquoted value
|
||||
var unquotedValue = $tw.utils.parseTokenRegExp(source,pos,reUnquotedAttribute);
|
||||
if(unquotedValue) {
|
||||
pos = unquotedValue.end;
|
||||
node.type = "string";
|
||||
node.value = unquotedValue.match[1];
|
||||
} else {
|
||||
// Look for an MVV reference value
|
||||
var mvvReference = $tw.utils.parseMVVReferenceAsTransclusion(source,pos);
|
||||
if(mvvReference) {
|
||||
pos = mvvReference.end;
|
||||
// Look for a macro invocation value
|
||||
var macroInvocation = $tw.utils.parseMacroInvocationAsTransclusion(source,pos);
|
||||
if(macroInvocation) {
|
||||
pos = macroInvocation.end;
|
||||
node.type = "macro";
|
||||
node.value = mvvReference;
|
||||
node.isMVV = true;
|
||||
node.value = macroInvocation;
|
||||
} else {
|
||||
var substitutedValue = $tw.utils.parseTokenRegExp(source,pos,reSubstitutedValue);
|
||||
if(substitutedValue) {
|
||||
@@ -548,16 +491,8 @@ exports.parseAttribute = function(source,pos) {
|
||||
node.type = "substituted";
|
||||
node.rawValue = substitutedValue.match[1] || substitutedValue.match[2];
|
||||
} else {
|
||||
// Look for a unquoted value
|
||||
var unquotedValue = $tw.utils.parseTokenRegExp(source,pos,reUnquotedAttribute);
|
||||
if(unquotedValue) {
|
||||
pos = unquotedValue.end;
|
||||
node.type = "string";
|
||||
node.value = unquotedValue.match[1];
|
||||
} else {
|
||||
node.type = "string";
|
||||
node.value = "true";
|
||||
}
|
||||
node.type = "string";
|
||||
node.value = "true";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +46,10 @@ exports.parse = function() {
|
||||
}
|
||||
// Return the $codeblock widget
|
||||
return [{
|
||||
type: "codeblock",
|
||||
attributes: {
|
||||
code: {type: "string", value: text, start: codeStart, end: this.parser.pos},
|
||||
language: {type: "string", value: this.match[1], start: languageStart, end: languageEnd}
|
||||
}
|
||||
type: "codeblock",
|
||||
attributes: {
|
||||
code: {type: "string", value: text, start: codeStart, end: this.parser.pos},
|
||||
language: {type: "string", value: this.match[1], start: languageStart, end: languageEnd}
|
||||
}
|
||||
}];
|
||||
};
|
||||
|
||||
@@ -51,10 +51,10 @@ exports.parse = function() {
|
||||
var commentStart = this.match.index;
|
||||
var commentEnd = this.endMatch.index + this.endMatch[0].length;
|
||||
return [{
|
||||
type: "void",
|
||||
children: [],
|
||||
text: this.parser.source.slice(commentStart, commentEnd),
|
||||
start: commentStart,
|
||||
end: commentEnd
|
||||
type: "void",
|
||||
children: [],
|
||||
text: this.parser.source.slice(commentStart, commentEnd),
|
||||
start: commentStart,
|
||||
end: commentEnd
|
||||
}];
|
||||
};
|
||||
|
||||
@@ -44,9 +44,9 @@ exports.parse = function() {
|
||||
var commentStart = this.match.index;
|
||||
var commentEnd = this.endMatch.index + this.endMatch[0].length;
|
||||
return [{
|
||||
type: "void",
|
||||
text: this.parser.source.slice(commentStart, commentEnd),
|
||||
start: commentStart,
|
||||
end: commentEnd
|
||||
type: "void",
|
||||
text: this.parser.source.slice(commentStart, commentEnd),
|
||||
start: commentStart,
|
||||
end: commentEnd
|
||||
}];
|
||||
};
|
||||
|
||||
@@ -95,7 +95,7 @@ exports.parseIfClause = function(filterCondition) {
|
||||
hasLineBreak = !!$tw.utils.parseTokenRegExp(this.parser.source,this.parser.pos,/([^\S\n\r]*\r?\n(?:[^\S\n\r]*\r?\n|$))/g);
|
||||
// If we found an else then we need to parse the body looking for the endif
|
||||
var reEndString = "\\<\\%\\s*(endif)\\s*\\%\\>",
|
||||
ex;
|
||||
ex;
|
||||
if(hasLineBreak) {
|
||||
ex = this.parser.parseBlocksTerminatedExtended(reEndString);
|
||||
} else {
|
||||
|
||||
@@ -32,7 +32,7 @@ Instantiate parse rule
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /\\(function|procedure|widget)\s+([^(\s]+)\((\s*([^)]*(?:\)\)[^)]*)*))?\)(\s*\r?\n)?/mg;
|
||||
this.matchRegExp = /\\(function|procedure|widget)\s+([^(\s]+)\((\s*([^)]*))?\)(\s*\r?\n)?/mg;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/*\
|
||||
title: $:/core/modules/parsers/wikiparser/rules/mvvdisplayinline.js
|
||||
type: application/javascript
|
||||
module-type: wikirule
|
||||
|
||||
Wiki rule for inline display of multi-valued variables and filter results.
|
||||
|
||||
Variable display: ((varname)) or ((varname||separator))
|
||||
Filter display: (((filter))) or (((filter||separator)))
|
||||
|
||||
The default separator is ", " (comma space).
|
||||
|
||||
\*/
|
||||
|
||||
"use strict";
|
||||
|
||||
exports.name = "mvvdisplayinline";
|
||||
exports.types = {inline: true};
|
||||
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
};
|
||||
|
||||
exports.findNextMatch = function(startPos) {
|
||||
var source = this.parser.source;
|
||||
var nextStart = startPos;
|
||||
while((nextStart = source.indexOf("((",nextStart)) >= 0) {
|
||||
if(source.charAt(nextStart + 2) === "(") {
|
||||
// Filter mode: (((filter))) or (((filter||sep)))
|
||||
var match = /^\(\(\(([\s\S]+?)\)\)\)/.exec(source.substring(nextStart));
|
||||
if(match) {
|
||||
// Check for separator: split on last || before )))
|
||||
var inner = match[1];
|
||||
var sepIndex = inner.lastIndexOf("||");
|
||||
if(sepIndex >= 0) {
|
||||
this.nextMatch = {
|
||||
type: "filter",
|
||||
filter: inner.substring(0,sepIndex),
|
||||
separator: inner.substring(sepIndex + 2),
|
||||
start: nextStart,
|
||||
end: nextStart + match[0].length
|
||||
};
|
||||
} else {
|
||||
this.nextMatch = {
|
||||
type: "filter",
|
||||
filter: inner,
|
||||
separator: ", ",
|
||||
start: nextStart,
|
||||
end: nextStart + match[0].length
|
||||
};
|
||||
}
|
||||
return nextStart;
|
||||
}
|
||||
} else {
|
||||
// Variable mode: ((varname)) or ((varname||sep))
|
||||
var match = /^\(\(([^()|]+?)(?:\|\|([^)]*))?\)\)/.exec(source.substring(nextStart));
|
||||
if(match) {
|
||||
this.nextMatch = {
|
||||
type: "variable",
|
||||
varName: match[1],
|
||||
separator: match[2] !== undefined ? match[2] : ", ",
|
||||
start: nextStart,
|
||||
end: nextStart + match[0].length
|
||||
};
|
||||
return nextStart;
|
||||
}
|
||||
}
|
||||
nextStart += 2;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/*
|
||||
Parse the most recent match
|
||||
*/
|
||||
exports.parse = function() {
|
||||
var match = this.nextMatch;
|
||||
this.nextMatch = null;
|
||||
this.parser.pos = match.end;
|
||||
var filter, sep = match.separator;
|
||||
if(match.type === "variable") {
|
||||
filter = "[(" + match.varName + ")join[" + sep + "]]";
|
||||
} else {
|
||||
filter = match.filter + " +[join[" + sep + "]]";
|
||||
}
|
||||
return [{
|
||||
type: "text",
|
||||
attributes: {
|
||||
text: {name: "text", type: "filtered", filter: filter}
|
||||
},
|
||||
orderedAttributes: [
|
||||
{name: "text", type: "filtered", filter: filter}
|
||||
]
|
||||
}];
|
||||
};
|
||||
@@ -67,5 +67,5 @@ exports.parse = function() {
|
||||
return [{
|
||||
type: "void",
|
||||
children: tree
|
||||
}];
|
||||
}]
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ var processRow = function(prevColumns) {
|
||||
// End of row
|
||||
if(prevCell && colSpanCount > 1) {
|
||||
if(prevCell.attributes && prevCell.attributes && prevCell.attributes.colspan) {
|
||||
colSpanCount += prevCell.attributes.colspan.value;
|
||||
colSpanCount += prevCell.attributes.colspan.value;
|
||||
} else {
|
||||
colSpanCount -= 1;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ exports.parse = function() {
|
||||
table.children.splice(0,0,rowContainer); // Insert it at the bottom
|
||||
}
|
||||
// Set the alignment - TODO: figure out why TW did this
|
||||
// rowContainer.attributes.align = rowCount === 0 ? "top" : "bottom";
|
||||
// rowContainer.attributes.align = rowCount === 0 ? "top" : "bottom";
|
||||
// Parse the caption
|
||||
rowContainer.children = this.parser.parseInlineRun(rowTermRegExp,{eatTerminator: true});
|
||||
} else {
|
||||
|
||||
@@ -32,17 +32,17 @@ exports.parse = function() {
|
||||
params = this.match[3] ? this.match[3].split("|") : [];
|
||||
// Prepare the transclude widget
|
||||
var transcludeNode = {
|
||||
type: "transclude",
|
||||
attributes: {},
|
||||
isBlock: true
|
||||
};
|
||||
type: "transclude",
|
||||
attributes: {},
|
||||
isBlock: true
|
||||
};
|
||||
$tw.utils.each(params,function(paramValue,index) {
|
||||
var name = "" + index;
|
||||
transcludeNode.attributes[name] = {
|
||||
name: name,
|
||||
type: "string",
|
||||
value: paramValue
|
||||
};
|
||||
}
|
||||
});
|
||||
// Prepare the tiddler widget
|
||||
var tr, targetTitle, targetField, targetIndex, tiddlerNode;
|
||||
|
||||
@@ -32,16 +32,16 @@ exports.parse = function() {
|
||||
params = this.match[3] ? this.match[3].split("|") : [];
|
||||
// Prepare the transclude widget
|
||||
var transcludeNode = {
|
||||
type: "transclude",
|
||||
attributes: {}
|
||||
};
|
||||
type: "transclude",
|
||||
attributes: {}
|
||||
};
|
||||
$tw.utils.each(params,function(paramValue,index) {
|
||||
var name = "" + index;
|
||||
transcludeNode.attributes[name] = {
|
||||
name: name,
|
||||
type: "string",
|
||||
value: paramValue
|
||||
};
|
||||
}
|
||||
});
|
||||
// Prepare the tiddler widget
|
||||
var tr, targetTitle, targetField, targetIndex, tiddlerNode;
|
||||
|
||||
@@ -32,10 +32,10 @@ function SaverHandler(options) {
|
||||
this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter));
|
||||
// Count of changes that have not yet been saved
|
||||
var filteredChanges = self.filterFn.call(self.wiki,function(iterator) {
|
||||
$tw.utils.each(self.preloadDirty,function(title) {
|
||||
var tiddler = self.wiki.getTiddler(title);
|
||||
iterator(tiddler,title);
|
||||
});
|
||||
$tw.utils.each(self.preloadDirty,function(title) {
|
||||
var tiddler = self.wiki.getTiddler(title);
|
||||
iterator(tiddler,title);
|
||||
});
|
||||
});
|
||||
this.numChanges = filteredChanges.length;
|
||||
// Listen out for changes to tiddlers
|
||||
|
||||
@@ -15,27 +15,27 @@ var AndTidWiki = function(wiki) {
|
||||
|
||||
AndTidWiki.prototype.save = function(text,method,callback,options) {
|
||||
var filename = options && options.variables ? options.variables.filename : null;
|
||||
if(method === "download") {
|
||||
if (method === "download") {
|
||||
// Support download
|
||||
if(window.twi.saveDownload) {
|
||||
if (window.twi.saveDownload) {
|
||||
try {
|
||||
window.twi.saveDownload(text,filename);
|
||||
} catch(err) {
|
||||
if(err.message === "Method not found") {
|
||||
if (err.message === "Method not found") {
|
||||
window.twi.saveDownload(text);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var link = document.createElement("a");
|
||||
link.setAttribute("href","data:text/plain," + encodeURIComponent(text));
|
||||
if(filename) {
|
||||
link.setAttribute("download",filename);
|
||||
if (filename) {
|
||||
link.setAttribute("download",filename);
|
||||
}
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
} else if(window.twi.saveWiki) {
|
||||
} else if (window.twi.saveWiki) {
|
||||
// Direct save in Tiddloid
|
||||
window.twi.saveWiki(text);
|
||||
} else {
|
||||
|
||||
@@ -22,7 +22,7 @@ var findSaver = function(window) {
|
||||
console.log({ msg: "custom saver is disabled", reason: err });
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
var saver = findSaver(window) || findSaver(window.parent) || {};
|
||||
|
||||
var CustomSaver = function(wiki) {
|
||||
|
||||
@@ -80,7 +80,7 @@ GiteaSaver.prototype.save = function(text,method,callback) {
|
||||
callback: function(err,getResponseDataJson,xhr) {
|
||||
if(xhr.status === 404) {
|
||||
callback("Please ensure the branch in the Gitea repo exists");
|
||||
} else {
|
||||
}else{
|
||||
data["branch"] = branch;
|
||||
self.upload(uri + filename, use_put?"PUT":"POST", headers, data, callback);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ GitLabSaver.prototype.save = function(text,method,callback) {
|
||||
var uri = endpoint + "/projects/" + encodeURIComponent(repo) + "/repository/";
|
||||
// Perform a get request to get the details (inc shas) of files in the same path as our file
|
||||
$tw.utils.httpRequest({
|
||||
url: uri + "tree/?path=" + encodeURIComponent(path.replace(/^\/+|\/$/g, "")) + "&branch=" + encodeURIComponent(branch.replace(/^\/+|\/$/g, "")),
|
||||
url: uri + "tree/?path=" + encodeURIComponent(path.replace(/^\/+|\/$/g, '')) + "&branch=" + encodeURIComponent(branch.replace(/^\/+|\/$/g, '')),
|
||||
type: "GET",
|
||||
headers: headers,
|
||||
callback: function(err,getResponseDataJson,xhr) {
|
||||
@@ -71,7 +71,7 @@ GitLabSaver.prototype.save = function(text,method,callback) {
|
||||
};
|
||||
// Perform a request to save the file
|
||||
$tw.utils.httpRequest({
|
||||
url: uri + "files/" + encodeURIComponent(path.replace(/^\/+/, "") + filename),
|
||||
url: uri + "files/" + encodeURIComponent(path.replace(/^\/+/, '') + filename),
|
||||
type: requestType,
|
||||
headers: headers,
|
||||
data: JSON.stringify(data),
|
||||
|
||||
@@ -94,7 +94,7 @@ PutSaver.prototype.save = function(text,method,callback) {
|
||||
} else if(status === 403) { // permission denied
|
||||
errorMsg = $tw.language.getString("Error/PutForbidden");
|
||||
}
|
||||
if(xhr.responseText) {
|
||||
if (xhr.responseText) {
|
||||
// treat any server response like a plain text error explanation
|
||||
errorMsg = errorMsg + "\n\n" + xhr.responseText;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ UploadSaver.prototype.save = function(text,method,callback) {
|
||||
uploadWithUrlOnly = this.wiki.getTextReference("$:/UploadWithUrlOnly") || "no",
|
||||
url = this.wiki.getTextReference("$:/UploadURL");
|
||||
// Bail out if we don't have the bits we need
|
||||
if(uploadWithUrlOnly === "yes") {
|
||||
if (uploadWithUrlOnly === "yes") {
|
||||
// The url is good enough. No need for a username and password.
|
||||
// Assume the server uses some other kind of auth mechanism.
|
||||
if(!url || url.toString().trim() === "") {
|
||||
|
||||
@@ -59,7 +59,7 @@ function loadIFrame(url,callback) {
|
||||
Unload library iframe for given url
|
||||
*/
|
||||
function unloadIFrame(url){
|
||||
var iframes = document.getElementsByTagName("iframe");
|
||||
var iframes = document.getElementsByTagName('iframe');
|
||||
for(var t=iframes.length-1; t--; t>=0) {
|
||||
var iframe = iframes[t];
|
||||
if(iframe.getAttribute("library") === "true" &&
|
||||
|
||||
@@ -40,7 +40,7 @@ $tw.eventBus = {
|
||||
emit(event,data) {
|
||||
const listeners = this.listenersMap.get(event);
|
||||
if(listeners) {
|
||||
listeners.forEach((fn) => fn(data));
|
||||
listeners.forEach(fn => fn(data));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@ exports.startup = function() {
|
||||
faviconLink.setAttribute("href",dataURI);
|
||||
$tw.faviconPublisher.send({verb: "FAVICON",body: dataURI});
|
||||
}
|
||||
};
|
||||
}
|
||||
$tw.faviconPublisher = new $tw.utils.BrowserMessagingPublisher({type: "FAVICON", onsubscribe: setFavicon});
|
||||
// Set up the favicon
|
||||
setFavicon();
|
||||
|
||||
@@ -13,11 +13,6 @@ Load core modules
|
||||
exports.name = "load-modules";
|
||||
exports.synchronous = true;
|
||||
|
||||
// Set to `true` to enable performance instrumentation
|
||||
var PERFORMANCE_INSTRUMENTATION_CONFIG_TITLE = "$:/config/Performance/Instrumentation";
|
||||
|
||||
var widget = require("$:/core/modules/widgets/widget.js");
|
||||
|
||||
exports.startup = function() {
|
||||
// Load modules
|
||||
$tw.modules.applyMethods("utils",$tw.utils);
|
||||
@@ -36,27 +31,6 @@ exports.startup = function() {
|
||||
$tw.modules.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerModules);
|
||||
$tw.macros = $tw.modules.getModulesByTypeAsHashmap("macro");
|
||||
$tw.wiki.initParsers();
|
||||
// --------------------------
|
||||
// The rest of the startup process here is not strictly to do with loading modules, but are needed before other startup
|
||||
// modules are executed. It is easier to put them here than to introduce a new startup module
|
||||
// --------------------------
|
||||
// Create a root widget for attaching event handlers. By using it as the parentWidget for another widget tree, one can reuse the event handlers
|
||||
$tw.rootWidget = new widget.widget({
|
||||
type: "widget",
|
||||
children: []
|
||||
},{
|
||||
wiki: $tw.wiki,
|
||||
document: $tw.browser ? document : $tw.fakeDocument
|
||||
});
|
||||
// Set up the performance framework
|
||||
$tw.perf = new $tw.Performance($tw.wiki.getTiddlerText(PERFORMANCE_INSTRUMENTATION_CONFIG_TITLE,"no") === "yes");
|
||||
// Kick off the filter tracker
|
||||
$tw.filterTracker = new $tw.FilterTracker($tw.wiki);
|
||||
$tw.wiki.addEventListener("change",function(changes) {
|
||||
$tw.filterTracker.handleChangeEvent(changes);
|
||||
});
|
||||
// Kick off the background action dispatcher
|
||||
$tw.backgroundActionDispatcher = new $tw.BackgroundActionDispatcher($tw.filterTracker,$tw.wiki);
|
||||
if($tw.node) {
|
||||
$tw.Commander.initCommands();
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ exports.startup = function() {
|
||||
$tw.utils.addClass($tw.pageContainer,"tc-page-container-wrapper");
|
||||
document.body.insertBefore($tw.pageContainer,document.body.firstChild);
|
||||
$tw.pageWidgetNode.render($tw.pageContainer,null);
|
||||
$tw.hooks.invokeHook("th-page-refreshed");
|
||||
$tw.hooks.invokeHook("th-page-refreshed");
|
||||
})();
|
||||
// Remove any splash screen elements
|
||||
var removeList = document.querySelectorAll(".tc-remove-when-wiki-loaded");
|
||||
|
||||
@@ -81,7 +81,7 @@ exports.startup = function() {
|
||||
$tw.rootWidget.addEventListener("tm-focus-selector",function(event) {
|
||||
var selector = event.param || "",
|
||||
element,
|
||||
baseElement = event.event && event.event.target ? event.event.target.ownerDocument : document;
|
||||
baseElement = event.event && event.event.target ? event.event.target.ownerDocument : document;
|
||||
element = $tw.utils.querySelectorSafe(selector,baseElement);
|
||||
if(element && element.focus) {
|
||||
element.focus(event.paramObject);
|
||||
|
||||
@@ -14,6 +14,11 @@ exports.name = "startup";
|
||||
exports.after = ["load-modules"];
|
||||
exports.synchronous = true;
|
||||
|
||||
// Set to `true` to enable performance instrumentation
|
||||
var PERFORMANCE_INSTRUMENTATION_CONFIG_TITLE = "$:/config/Performance/Instrumentation";
|
||||
|
||||
var widget = require("$:/core/modules/widgets/widget.js");
|
||||
|
||||
exports.startup = function() {
|
||||
// Minimal browser detection
|
||||
if($tw.browser) {
|
||||
@@ -49,6 +54,16 @@ exports.startup = function() {
|
||||
}
|
||||
// Initialise version
|
||||
$tw.version = $tw.utils.extractVersionInfo();
|
||||
// Set up the performance framework
|
||||
$tw.perf = new $tw.Performance($tw.wiki.getTiddlerText(PERFORMANCE_INSTRUMENTATION_CONFIG_TITLE,"no") === "yes");
|
||||
// Create a root widget for attaching event handlers. By using it as the parentWidget for another widget tree, one can reuse the event handlers
|
||||
$tw.rootWidget = new widget.widget({
|
||||
type: "widget",
|
||||
children: []
|
||||
},{
|
||||
wiki: $tw.wiki,
|
||||
document: $tw.browser ? document : $tw.fakeDocument
|
||||
});
|
||||
// Kick off the language manager and switcher
|
||||
$tw.language = new $tw.Language();
|
||||
$tw.languageSwitcher = new $tw.PluginSwitcher({
|
||||
@@ -113,7 +128,7 @@ exports.startup = function() {
|
||||
$tw.syncer = new $tw.Syncer({
|
||||
wiki: $tw.wiki,
|
||||
syncadaptor: $tw.syncadaptor,
|
||||
logging: $tw.wiki.getTiddlerText("$:/config/SyncLogging", "yes") === "yes"
|
||||
logging: $tw.wiki.getTiddlerText('$:/config/SyncLogging', "yes") === "yes"
|
||||
});
|
||||
}
|
||||
// Setup the saver handler
|
||||
|
||||
@@ -96,15 +96,15 @@ exports.startup = function() {
|
||||
$tw.rootWidget.addEventListener("tm-close-window",function(event) {
|
||||
var windowID = event.param,
|
||||
win = $tw.windows[windowID];
|
||||
if(win) {
|
||||
win.close();
|
||||
}
|
||||
if(win) {
|
||||
win.close();
|
||||
}
|
||||
});
|
||||
var closeAllWindows = function() {
|
||||
$tw.utils.each($tw.windows,function(win) {
|
||||
win.close();
|
||||
});
|
||||
};
|
||||
}
|
||||
$tw.rootWidget.addEventListener("tm-close-all-windows",closeAllWindows);
|
||||
// Close open windows when unloading main window
|
||||
$tw.addUnloadTask(closeAllWindows);
|
||||
|
||||
@@ -16,7 +16,7 @@ var ClassicStoryView = function(listWidget) {
|
||||
};
|
||||
|
||||
ClassicStoryView.prototype.navigateTo = function(historyInfo) {
|
||||
var duration = $tw.utils.getAnimationDuration();
|
||||
var duration = $tw.utils.getAnimationDuration()
|
||||
var listElementIndex = this.listWidget.findListItem(0,historyInfo.title);
|
||||
if(listElementIndex === undefined) {
|
||||
return;
|
||||
|
||||
@@ -62,7 +62,7 @@ PopStoryView.prototype.insert = function(widget) {
|
||||
]);
|
||||
setTimeout(function() {
|
||||
$tw.utils.removeStyles(targetElement, ["transition", "transform", "opactity"]);
|
||||
}, duration);
|
||||
}, duration)
|
||||
};
|
||||
|
||||
PopStoryView.prototype.remove = function(widget) {
|
||||
|
||||
@@ -16,7 +16,7 @@ var ZoominListView = function(listWidget) {
|
||||
this.listWidget = listWidget;
|
||||
this.textNodeLogger = new $tw.utils.Logger("zoomin story river view", {
|
||||
enable: true,
|
||||
colour: "red"
|
||||
colour: 'red'
|
||||
});
|
||||
// Get the index of the tiddler that is at the top of the history
|
||||
var history = this.listWidget.wiki.getTiddlerDataCached(this.listWidget.historyTitle,[]),
|
||||
@@ -51,7 +51,7 @@ ZoominListView.prototype.navigateTo = function(historyInfo) {
|
||||
// Abandon if the list entry isn't a DOM element (it might be a text node)
|
||||
if(!targetElement) {
|
||||
return;
|
||||
} else if(targetElement.nodeType === Node.TEXT_NODE) {
|
||||
} else if (targetElement.nodeType === Node.TEXT_NODE) {
|
||||
this.logTextNodeRoot(targetElement);
|
||||
return;
|
||||
}
|
||||
@@ -66,11 +66,11 @@ ZoominListView.prototype.navigateTo = function(historyInfo) {
|
||||
]);
|
||||
// Get the position of the source node, or use the centre of the window as the source position
|
||||
var sourceBounds = historyInfo.fromPageRect || {
|
||||
left: window.innerWidth/2 - 2,
|
||||
top: window.innerHeight/2 - 2,
|
||||
width: window.innerWidth/8,
|
||||
height: window.innerHeight/8
|
||||
};
|
||||
left: window.innerWidth/2 - 2,
|
||||
top: window.innerHeight/2 - 2,
|
||||
width: window.innerWidth/8,
|
||||
height: window.innerHeight/8
|
||||
};
|
||||
// Try to find the title node in the target tiddler
|
||||
var titleDomNode = findTitleDomNode(listItemWidget) || listItemWidget.findFirstDomNode(),
|
||||
zoomBounds = titleDomNode.getBoundingClientRect();
|
||||
@@ -139,7 +139,7 @@ ZoominListView.prototype.insert = function(widget) {
|
||||
// Abandon if the list entry isn't a DOM element (it might be a text node)
|
||||
if(!targetElement) {
|
||||
return;
|
||||
} else if(targetElement.nodeType === Node.TEXT_NODE) {
|
||||
} else if (targetElement.nodeType === Node.TEXT_NODE) {
|
||||
this.logTextNodeRoot(targetElement);
|
||||
return;
|
||||
}
|
||||
@@ -183,7 +183,7 @@ ZoominListView.prototype.remove = function(widget) {
|
||||
var toWidgetDomNode = toWidget && toWidget.findFirstDomNode();
|
||||
// Set up the tiddler we're moving back in
|
||||
if(toWidgetDomNode) {
|
||||
if(toWidgetDomNode.nodeType === Node.TEXT_NODE) {
|
||||
if (toWidgetDomNode.nodeType === Node.TEXT_NODE) {
|
||||
this.logTextNodeRoot(toWidgetDomNode);
|
||||
toWidgetDomNode = null;
|
||||
} else {
|
||||
|
||||
@@ -89,7 +89,7 @@ function Syncer(options) {
|
||||
self.processTaskQueue();
|
||||
} else {
|
||||
// Look for deletions of tiddlers we're already syncing
|
||||
var outstandingDeletion = false;
|
||||
var outstandingDeletion = false
|
||||
$tw.utils.each(changes,function(change,title,object) {
|
||||
if(change.deleted && $tw.utils.hop(self.tiddlerInfo,title)) {
|
||||
outstandingDeletion = true;
|
||||
@@ -304,7 +304,7 @@ Syncer.prototype.syncFromServer = function() {
|
||||
|
||||
Syncer.prototype.canSyncFromServer = function() {
|
||||
return !!this.syncadaptor.getUpdatedTiddlers || !!this.syncadaptor.getSkinnyTiddlers;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Force load a tiddler from the server
|
||||
@@ -530,7 +530,7 @@ function SaveTiddlerTask(syncer,title) {
|
||||
|
||||
SaveTiddlerTask.prototype.toString = function() {
|
||||
return "SAVE " + this.title;
|
||||
};
|
||||
}
|
||||
|
||||
SaveTiddlerTask.prototype.run = function(callback) {
|
||||
var self = this,
|
||||
@@ -568,7 +568,7 @@ function DeleteTiddlerTask(syncer,title) {
|
||||
|
||||
DeleteTiddlerTask.prototype.toString = function() {
|
||||
return "DELETE " + this.title;
|
||||
};
|
||||
}
|
||||
|
||||
DeleteTiddlerTask.prototype.run = function(callback) {
|
||||
var self = this;
|
||||
@@ -595,7 +595,7 @@ function LoadTiddlerTask(syncer,title) {
|
||||
|
||||
LoadTiddlerTask.prototype.toString = function() {
|
||||
return "LOAD " + this.title;
|
||||
};
|
||||
}
|
||||
|
||||
LoadTiddlerTask.prototype.run = function(callback) {
|
||||
var self = this;
|
||||
@@ -621,7 +621,7 @@ function SyncFromServerTask(syncer) {
|
||||
|
||||
SyncFromServerTask.prototype.toString = function() {
|
||||
return "SYNCFROMSERVER";
|
||||
};
|
||||
}
|
||||
|
||||
SyncFromServerTask.prototype.run = function(callback) {
|
||||
var self = this;
|
||||
|
||||
@@ -13,19 +13,19 @@ Base64 utility functions
|
||||
Base64 utility functions that work in either browser or Node.js
|
||||
*/
|
||||
|
||||
exports.btoa = (binstr) => window.btoa(binstr);
|
||||
exports.atob = (b64) => window.atob(b64);
|
||||
exports.btoa = binstr => window.btoa(binstr);
|
||||
exports.atob = b64 => window.atob(b64);
|
||||
|
||||
function base64ToBytes(base64) {
|
||||
const binString = exports.atob(base64);
|
||||
return Uint8Array.from(binString, (m) => m.codePointAt(0));
|
||||
return Uint8Array.from(binString, m => m.codePointAt(0));
|
||||
};
|
||||
|
||||
function bytesToBase64(bytes) {
|
||||
const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join("");
|
||||
const binString = Array.from(bytes, byte => String.fromCodePoint(byte)).join("");
|
||||
return exports.btoa(binString);
|
||||
};
|
||||
|
||||
exports.base64EncodeUtf8 = (str) => bytesToBase64(new TextEncoder().encode(str));
|
||||
exports.base64EncodeUtf8 = str => bytesToBase64(new TextEncoder().encode(str));
|
||||
|
||||
exports.base64DecodeUtf8 = (str) => new TextDecoder().decode(base64ToBytes(str));
|
||||
exports.base64DecodeUtf8 = str => new TextDecoder().decode(base64ToBytes(str));
|
||||
@@ -15,23 +15,23 @@ var getCellInfo = function(text, start, length, SEPARATOR) {
|
||||
var isCellQuoted = text.charAt(start) === QUOTE;
|
||||
var cellStart = isCellQuoted ? start + 1 : start;
|
||||
|
||||
if(text.charAt(i) === SEPARATOR) {
|
||||
if (text.charAt(i) === SEPARATOR) {
|
||||
return [cellStart, cellStart, false];
|
||||
}
|
||||
|
||||
for(var i = cellStart; i < length; i++) {
|
||||
for (var i = cellStart; i < length; i++) {
|
||||
var cellCharacter = text.charAt(i);
|
||||
var isEOL = cellCharacter === "\n" || cellCharacter === "\r";
|
||||
|
||||
if(isEOL && !isCellQuoted) {
|
||||
if (isEOL && !isCellQuoted) {
|
||||
return [cellStart, i, false];
|
||||
|
||||
} else if(cellCharacter === SEPARATOR && !isCellQuoted) {
|
||||
} else if (cellCharacter === SEPARATOR && !isCellQuoted) {
|
||||
return [cellStart, i, false];
|
||||
|
||||
} else if(cellCharacter === QUOTE && isCellQuoted) {
|
||||
var nextCharacter = i + 1 < length ? text.charAt(i + 1) : "";
|
||||
if(nextCharacter !== QUOTE) {
|
||||
} else if (cellCharacter === QUOTE && isCellQuoted) {
|
||||
var nextCharacter = i + 1 < length ? text.charAt(i + 1) : '';
|
||||
if (nextCharacter !== QUOTE) {
|
||||
return [cellStart, i, true];
|
||||
} else {
|
||||
i++;
|
||||
@@ -40,10 +40,10 @@ var getCellInfo = function(text, start, length, SEPARATOR) {
|
||||
}
|
||||
|
||||
return [cellStart, i, isCellQuoted];
|
||||
};
|
||||
}
|
||||
|
||||
exports.parseCsvString = function(text, options) {
|
||||
if(!text) {
|
||||
if (!text) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ exports.parseCsvString = function(text, options) {
|
||||
rows = [],
|
||||
nextRow = [];
|
||||
|
||||
for(var i = 0; i < length; i++) {
|
||||
for (var i = 0; i < length; i++) {
|
||||
var cellInfo = getCellInfo(text, i, length, SEPARATOR);
|
||||
var cellText = text.substring(cellInfo[0], cellInfo[1]);
|
||||
if(cellInfo[2]) {
|
||||
if (cellInfo[2]) {
|
||||
cellText = cellText.replace(/""/g, '"');
|
||||
cellInfo[1]++;
|
||||
}
|
||||
@@ -65,20 +65,20 @@ exports.parseCsvString = function(text, options) {
|
||||
i = cellInfo[1];
|
||||
|
||||
var character = text.charAt(i);
|
||||
var nextCharacter = i + 1 < length ? text.charAt(i + 1) : "";
|
||||
var nextCharacter = i + 1 < length ? text.charAt(i + 1) : '';
|
||||
|
||||
if(character === "\r" || character === "\n") {
|
||||
if (character === "\r" || character === "\n") {
|
||||
// Edge case for empty rows
|
||||
if(nextRow.length === 1 && nextRow[0] === "") {
|
||||
if (nextRow.length === 1 && nextRow[0] === '') {
|
||||
nextRow.length = 0;
|
||||
}
|
||||
rows.push(nextRow);
|
||||
nextRow = [];
|
||||
|
||||
if(character === "\r") {
|
||||
var nextCharacter = i + 1 < length ? text.charAt(i + 1) : "";
|
||||
if (character === "\r") {
|
||||
var nextCharacter = i + 1 < length ? text.charAt(i + 1) : '';
|
||||
|
||||
if(nextCharacter === "\n") {
|
||||
if (nextCharacter === "\n") {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -86,14 +86,14 @@ exports.parseCsvString = function(text, options) {
|
||||
}
|
||||
|
||||
// Special case if last cell in last row is an empty cell
|
||||
if(text.charAt(length - 1) === SEPARATOR) {
|
||||
if (text.charAt(length - 1) === SEPARATOR) {
|
||||
nextRow.push("");
|
||||
}
|
||||
|
||||
rows.push(nextRow);
|
||||
|
||||
return rows;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Parse a CSV string with a header row and return an array of hashmaps.
|
||||
@@ -103,17 +103,17 @@ exports.parseCsvStringWithHeader = function(text,options) {
|
||||
var headers = csv[0];
|
||||
|
||||
csv = csv.slice(1);
|
||||
for(var i = 0; i < csv.length; i++) {
|
||||
for (var i = 0; i < csv.length; i++) {
|
||||
var row = csv[i];
|
||||
var rowObject = Object.create(null);
|
||||
|
||||
for(var columnIndex=0; columnIndex<headers.length; columnIndex++) {
|
||||
var columnName = headers[columnIndex];
|
||||
if(columnName) {
|
||||
if (columnName) {
|
||||
rowObject[columnName] = $tw.utils.trim(row[columnIndex] || "");
|
||||
}
|
||||
}
|
||||
csv[i] = rowObject;
|
||||
}
|
||||
return csv;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ Deprecated util functions
|
||||
|
||||
\*/
|
||||
|
||||
exports.logTable = (data) => console.table(data);
|
||||
exports.logTable = data => console.table(data);
|
||||
|
||||
exports.repeat = (str,count) => str.repeat(count);
|
||||
|
||||
@@ -23,13 +23,13 @@ exports.trim = function(str) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.hopArray = (object,array) => array.some((element) => $tw.utils.hop(object,element));
|
||||
exports.hopArray = (object,array) => array.some(element => $tw.utils.hop(object,element));
|
||||
|
||||
exports.sign = Math.sign;
|
||||
|
||||
exports.strEndsWith = (str,ending,position) => str.endsWith(ending,position);
|
||||
|
||||
exports.stringifyNumber = (num) => num.toString();
|
||||
exports.stringifyNumber = num => num.toString();
|
||||
|
||||
exports.tagToCssSelector = function(tagName) {
|
||||
return "tc-tagged-" + encodeURIComponent(tagName).replace(/[!"#$%&'()*+,\-./:;<=>?@[\\\]^`{\|}~,]/mg,function(c) {
|
||||
|
||||
@@ -30,10 +30,10 @@ Remove style properties of an element
|
||||
styleProperties: ordered array of string property names
|
||||
*/
|
||||
exports.removeStyles = function(element, styleProperties) {
|
||||
for(var i=0; i<styleProperties.length; i++) {
|
||||
for (var i=0; i<styleProperties.length; i++) {
|
||||
element.style.removeProperty($tw.utils.convertStyleNameToPropertyName(styleProperties[i]));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Remove single style property of an element
|
||||
@@ -41,8 +41,8 @@ Remove single style property of an element
|
||||
styleProperty: string property name
|
||||
*/
|
||||
exports.removeStyle = function(element, styleProperty) {
|
||||
$tw.utils.removeStyles(element, [styleProperty]);
|
||||
};
|
||||
$tw.utils.removeStyles(element, [styleProperty])
|
||||
}
|
||||
|
||||
/*
|
||||
Converts a standard CSS property name into the local browser-specific equivalent. For example:
|
||||
@@ -150,19 +150,19 @@ exports.getFullScreenApis = function() {
|
||||
var d = document,
|
||||
db = d.body,
|
||||
result = {
|
||||
"_requestFullscreen": db.webkitRequestFullscreen !== undefined ? "webkitRequestFullscreen" :
|
||||
db.mozRequestFullScreen !== undefined ? "mozRequestFullScreen" :
|
||||
db.requestFullscreen !== undefined ? "requestFullscreen" : "",
|
||||
"_exitFullscreen": d.webkitExitFullscreen !== undefined ? "webkitExitFullscreen" :
|
||||
d.mozCancelFullScreen !== undefined ? "mozCancelFullScreen" :
|
||||
d.exitFullscreen !== undefined ? "exitFullscreen" : "",
|
||||
"_fullscreenElement": d.webkitFullscreenElement !== undefined ? "webkitFullscreenElement" :
|
||||
d.mozFullScreenElement !== undefined ? "mozFullScreenElement" :
|
||||
d.fullscreenElement !== undefined ? "fullscreenElement" : "",
|
||||
"_fullscreenChange": d.webkitFullscreenElement !== undefined ? "webkitfullscreenchange" :
|
||||
d.mozFullScreenElement !== undefined ? "mozfullscreenchange" :
|
||||
d.fullscreenElement !== undefined ? "fullscreenchange" : ""
|
||||
};
|
||||
"_requestFullscreen": db.webkitRequestFullscreen !== undefined ? "webkitRequestFullscreen" :
|
||||
db.mozRequestFullScreen !== undefined ? "mozRequestFullScreen" :
|
||||
db.requestFullscreen !== undefined ? "requestFullscreen" : "",
|
||||
"_exitFullscreen": d.webkitExitFullscreen !== undefined ? "webkitExitFullscreen" :
|
||||
d.mozCancelFullScreen !== undefined ? "mozCancelFullScreen" :
|
||||
d.exitFullscreen !== undefined ? "exitFullscreen" : "",
|
||||
"_fullscreenElement": d.webkitFullscreenElement !== undefined ? "webkitFullscreenElement" :
|
||||
d.mozFullScreenElement !== undefined ? "mozFullScreenElement" :
|
||||
d.fullscreenElement !== undefined ? "fullscreenElement" : "",
|
||||
"_fullscreenChange": d.webkitFullscreenElement !== undefined ? "webkitfullscreenchange" :
|
||||
d.mozFullScreenElement !== undefined ? "mozfullscreenchange" :
|
||||
d.fullscreenElement !== undefined ? "fullscreenchange" : ""
|
||||
};
|
||||
if(!result._requestFullscreen || !result._exitFullscreen || !result._fullscreenElement || !result._fullscreenChange) {
|
||||
return null;
|
||||
} else {
|
||||
|
||||
@@ -74,7 +74,7 @@ exports.resizeTextAreaToFit = function(domNode,minHeight) {
|
||||
// Get the scroll container and register the current scroll position
|
||||
var container = $tw.utils.getScrollContainer(domNode),
|
||||
scrollTop = container.scrollTop;
|
||||
// Measure the specified minimum height
|
||||
// Measure the specified minimum height
|
||||
domNode.style.height = minHeight;
|
||||
var measuredHeight = domNode.offsetHeight || parseInt(minHeight,10);
|
||||
// Set its height to auto so that it snaps to the correct height
|
||||
@@ -246,7 +246,7 @@ exports.copyToClipboard = function(text,options) {
|
||||
}
|
||||
if(!options.doNotNotify) {
|
||||
var successNotification = options.successNotification || "$:/language/Notifications/CopiedToClipboard/Succeeded",
|
||||
failureNotification = options.failureNotification || "$:/language/Notifications/CopiedToClipboard/Failed";
|
||||
failureNotification = options.failureNotification || "$:/language/Notifications/CopiedToClipboard/Failed"
|
||||
$tw.notifier.display(succeeded ? successNotification : failureNotification);
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
@@ -257,8 +257,8 @@ Collect DOM variables
|
||||
*/
|
||||
exports.collectDOMVariables = function(selectedNode,domNode,event) {
|
||||
var variables = {},
|
||||
selectedNodeRect,
|
||||
domNodeRect;
|
||||
selectedNodeRect,
|
||||
domNodeRect;
|
||||
if(selectedNode) {
|
||||
$tw.utils.each(selectedNode.attributes,function(attribute) {
|
||||
variables["dom-" + attribute.name] = attribute.value.toString();
|
||||
|
||||
@@ -151,7 +151,7 @@ exports.importDataTransfer = function(dataTransfer,fallbackTitle,callback) {
|
||||
if($tw.log.IMPORT) {
|
||||
console.log("Available data types:");
|
||||
for(var type=0; type<dataTransfer.types.length; type++) {
|
||||
console.log("type",dataTransfer.types[type],dataTransfer.getData(dataTransfer.types[type]));
|
||||
console.log("type",dataTransfer.types[type],dataTransfer.getData(dataTransfer.types[type]))
|
||||
}
|
||||
}
|
||||
for(var t=0; t<importDataTypes.length; t++) {
|
||||
@@ -162,7 +162,7 @@ exports.importDataTransfer = function(dataTransfer,fallbackTitle,callback) {
|
||||
// Import the tiddlers in the data
|
||||
if(data !== "" && data !== null) {
|
||||
if($tw.log.IMPORT) {
|
||||
console.log("Importing data type '" + dataType.type + "', data: '" + data + "'");
|
||||
console.log("Importing data type '" + dataType.type + "', data: '" + data + "'")
|
||||
}
|
||||
var tiddlerFields = dataType.toTiddlerFieldsArray(data,fallbackTitle);
|
||||
callback(tiddlerFields);
|
||||
@@ -181,7 +181,7 @@ exports.importPaste = function(item,fallbackTitle,callback) {
|
||||
|
||||
item.getAsString(function(data){
|
||||
if($tw.log.IMPORT) {
|
||||
console.log("Importing data type '" + dataType.type + "', data: '" + data + "'");
|
||||
console.log("Importing data type '" + dataType.type + "', data: '" + data + "'")
|
||||
}
|
||||
var tiddlerFields = dataType.toTiddlerFieldsArray(data,fallbackTitle);
|
||||
callback(tiddlerFields);
|
||||
@@ -200,7 +200,7 @@ exports.itemHasValidDataType = function(item) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
var importDataTypes = [
|
||||
{type: "text/vnd.tiddler", IECompatible: false, toTiddlerFieldsArray: function(data,fallbackTitle) {
|
||||
|
||||
@@ -106,7 +106,7 @@ bearerAuthTokenFromStore: name of password store entry contain bear authorizatio
|
||||
*/
|
||||
function HttpClientRequest(options) {
|
||||
var self = this;
|
||||
console.log("Initiating an HTTP request",options);
|
||||
console.log("Initiating an HTTP request",options)
|
||||
this.wiki = options.wiki;
|
||||
this.completionActions = options.oncompletion;
|
||||
this.progressActions = options.onprogress;
|
||||
@@ -193,11 +193,11 @@ HttpClientRequest.prototype.send = function(callback) {
|
||||
headers: JSON.stringify(headers)
|
||||
};
|
||||
/* Convert data from binary to base64 */
|
||||
if(xhr.responseType === "arraybuffer") {
|
||||
if (xhr.responseType === "arraybuffer") {
|
||||
var binary = "",
|
||||
bytes = new Uint8Array(data),
|
||||
len = bytes.byteLength;
|
||||
for(var i=0; i<len; i++) {
|
||||
for (var i=0; i<len; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
resultVariables.data = $tw.utils.base64Encode(binary,true);
|
||||
@@ -211,7 +211,7 @@ HttpClientRequest.prototype.send = function(callback) {
|
||||
},
|
||||
progress: function(lengthComputable,loaded,total) {
|
||||
if(lengthComputable) {
|
||||
setBinding(self.bindProgress,"" + Math.floor((loaded/total) * 100));
|
||||
setBinding(self.bindProgress,"" + Math.floor((loaded/total) * 100))
|
||||
}
|
||||
self.wiki.invokeActionString(self.progressActions,undefined,$tw.utils.extend({},self.variables,{
|
||||
lengthComputable: lengthComputable ? "yes" : "no",
|
||||
@@ -302,14 +302,14 @@ exports.httpRequest = function(options) {
|
||||
options.callback(null,this[returnProp],this);
|
||||
return;
|
||||
}
|
||||
// Something went wrong
|
||||
options.callback($tw.language.getString("Error/XMLHttpRequest") + ": " + this.status,this[returnProp],this);
|
||||
// Something went wrong
|
||||
options.callback($tw.language.getString("Error/XMLHttpRequest") + ": " + this.status,this[returnProp],this);
|
||||
}
|
||||
};
|
||||
// Handle progress
|
||||
if(options.progress) {
|
||||
request.onprogress = function(event) {
|
||||
console.log("Progress event",event);
|
||||
console.log("Progress event",event)
|
||||
options.progress(event.lengthComputable,event.loaded,event.total);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ Keyboard utilities; now deprecated. Instead, use $tw.keyboardManager
|
||||
if($tw.keyboardManager) {
|
||||
return $tw.keyboardManager[method].apply($tw.keyboardManager,Array.prototype.slice.call(arguments,0));
|
||||
} else {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ Modal.prototype.display = function(title,options) {
|
||||
options = options || {};
|
||||
this.srcDocument = options.variables && (options.variables.rootwindow === "true" ||
|
||||
options.variables.rootwindow === "yes") ? document :
|
||||
(options.event && options.event.event && options.event.event.target ? options.event.event.target.ownerDocument : document);
|
||||
(options.event && options.event.event && options.event.event.target ? options.event.event.target.ownerDocument : document);
|
||||
this.srcWindow = this.srcDocument.defaultView;
|
||||
var self = this,
|
||||
refreshHandler,
|
||||
@@ -42,10 +42,10 @@ Modal.prototype.display = function(title,options) {
|
||||
}
|
||||
// Create the variables
|
||||
var variables = $tw.utils.extend({
|
||||
currentTiddler: title,
|
||||
"tv-story-list": (options.event && options.event.widget ? options.event.widget.getVariable("tv-story-list") : ""),
|
||||
"tv-history-list": (options.event && options.event.widget ? options.event.widget.getVariable("tv-history-list") : "")
|
||||
},options.variables);
|
||||
currentTiddler: title,
|
||||
"tv-story-list": (options.event && options.event.widget ? options.event.widget.getVariable("tv-story-list") : ""),
|
||||
"tv-history-list": (options.event && options.event.widget ? options.event.widget.getVariable("tv-history-list") : "")
|
||||
},options.variables);
|
||||
|
||||
// Create the wrapper divs
|
||||
var wrapper = this.srcDocument.createElement("div"),
|
||||
@@ -115,7 +115,7 @@ Modal.prototype.display = function(title,options) {
|
||||
text: {
|
||||
type: "string",
|
||||
value: title
|
||||
}}}],
|
||||
}}}],
|
||||
parentWidget: navigatorWidgetNode,
|
||||
document: this.srcDocument,
|
||||
variables: variables,
|
||||
@@ -165,8 +165,8 @@ Modal.prototype.display = function(title,options) {
|
||||
text: {
|
||||
type: "string",
|
||||
value: $tw.language.getString("Buttons/Close/Caption")
|
||||
}}}
|
||||
]}],
|
||||
}}}
|
||||
]}],
|
||||
parentWidget: navigatorWidgetNode,
|
||||
document: this.srcDocument,
|
||||
variables: variables,
|
||||
|
||||
@@ -23,14 +23,14 @@ var Popup = function(options) {
|
||||
Global regular expression for parsing the location of a popup.
|
||||
This is also used by the Reveal widget.
|
||||
*/
|
||||
exports.popupLocationRegExp = /^(@?)\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/;
|
||||
exports.popupLocationRegExp = /^(@?)\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/
|
||||
|
||||
/*
|
||||
Objekt containing the available prefixes for coordinates build with the `buildCoordinates` function:
|
||||
- csOffsetParent: Uses a coordinate system based on the offset parent (no prefix).
|
||||
- csAbsolute: Use an absolute coordinate system (prefix "@").
|
||||
*/
|
||||
exports.coordinatePrefix = { csOffsetParent: "", csAbsolute: "@" };
|
||||
exports.coordinatePrefix = { csOffsetParent: "", csAbsolute: "@" }
|
||||
|
||||
/*
|
||||
Trigger a popup open or closed. Parameters are in a hashmap:
|
||||
@@ -182,7 +182,7 @@ Popup.prototype.cancel = function(level) {
|
||||
popup.wiki.deleteTiddler(popup.title);
|
||||
} else {
|
||||
popup.wiki.deleteTiddler($tw.utils.parseTextReference(popup.title).title);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.popups.length === 0) {
|
||||
@@ -220,7 +220,7 @@ exports.parseCoordinates = function(coordinates) {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Builds a coordinate string from a coordinate system identifier and an object
|
||||
@@ -232,11 +232,11 @@ This function is safe to call, even if the popup class was not initialized.
|
||||
*/
|
||||
exports.buildCoordinates = function(prefix,position) {
|
||||
var coord = prefix + "(" + position.left + "," + position.top + "," + position.width + "," + position.height + ")";
|
||||
if(exports.popupLocationRegExp.test(coord)) {
|
||||
if (exports.popupLocationRegExp.test(coord)) {
|
||||
return coord;
|
||||
} else {
|
||||
return "(0,0,0,0)";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.Popup = Popup;
|
||||
|
||||
@@ -32,7 +32,7 @@ var PageScroller = function() {
|
||||
|
||||
PageScroller.prototype.isScrolling = function() {
|
||||
return this.idRequestFrame !== null;
|
||||
};
|
||||
}
|
||||
|
||||
PageScroller.prototype.cancelScroll = function(srcWindow) {
|
||||
if(this.idRequestFrame) {
|
||||
@@ -78,7 +78,7 @@ PageScroller.prototype.scrollIntoView = function(element,callback,options) {
|
||||
}
|
||||
// Get the client bounds of the element and adjust by the scroll position
|
||||
var getBounds = function() {
|
||||
var clientBounds = typeof callback === "function" ? callback() : element.getBoundingClientRect(),
|
||||
var clientBounds = typeof callback === 'function' ? callback() : element.getBoundingClientRect(),
|
||||
scrollPosition = $tw.utils.getScrollPosition(srcWindow);
|
||||
return {
|
||||
left: clientBounds.left + scrollPosition.x,
|
||||
|
||||
@@ -22,13 +22,13 @@ var TW_Node = function (){
|
||||
throw TypeError("Illegal constructor");
|
||||
};
|
||||
|
||||
Object.defineProperty(TW_Node.prototype, "ELEMENT_NODE", {
|
||||
Object.defineProperty(TW_Node.prototype, 'ELEMENT_NODE', {
|
||||
get: function() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(TW_Node.prototype, "TEXT_NODE", {
|
||||
Object.defineProperty(TW_Node.prototype, 'TEXT_NODE', {
|
||||
get: function() {
|
||||
return 3;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ var TW_Style = function(el) {
|
||||
return new Proxy(styleObject, {
|
||||
get: function(target, property) {
|
||||
// If the property exists on styleObject, return it (get, set, setProperty methods)
|
||||
if(property in target) {
|
||||
if (property in target) {
|
||||
return target[property];
|
||||
}
|
||||
// Otherwise, return the corresponding property from _style
|
||||
|
||||
@@ -59,7 +59,7 @@ LinkedList.prototype.push = function(/* values */) {
|
||||
LinkedList.prototype.pushTop = function(value) {
|
||||
var t;
|
||||
if($tw.utils.isArray(value)) {
|
||||
for(t=0; t<value.length; t++) {
|
||||
for (t=0; t<value.length; t++) {
|
||||
_assertString(value[t]);
|
||||
}
|
||||
for(t=0; t<value.length; t++) {
|
||||
|
||||
@@ -83,7 +83,7 @@ Logger.prototype.alert = function(/* args */) {
|
||||
$tw.utils.each(existingAlerts,function(title) {
|
||||
var tiddler = $tw.wiki.getTiddler(title);
|
||||
if(tiddler.fields.text === text && tiddler.fields.component === self.componentName && tiddler.fields.modified && (!alertFields || tiddler.fields.modified < alertFields.modified)) {
|
||||
alertFields = $tw.utils.extend({},tiddler.fields);
|
||||
alertFields = $tw.utils.extend({},tiddler.fields);
|
||||
}
|
||||
});
|
||||
if(alertFields) {
|
||||
|
||||
@@ -45,7 +45,7 @@ Performance.prototype.log = function() {
|
||||
orderedMeasures = Object.keys(this.measures).sort(function(a,b) {
|
||||
if(self.measures[a].time > self.measures[b].time) {
|
||||
return -1;
|
||||
} else if(self.measures[a].time < self.measures[b].time) {
|
||||
} else if (self.measures[a].time < self.measures[b].time) {
|
||||
return + 1;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -54,10 +54,10 @@ Performance.prototype.log = function() {
|
||||
$tw.utils.each(orderedMeasures,function(name) {
|
||||
totalTime += self.measures[name].time;
|
||||
});
|
||||
var results = [];
|
||||
var results = []
|
||||
$tw.utils.each(orderedMeasures,function(name) {
|
||||
var measure = self.measures[name];
|
||||
results.push({name: name,invocations: measure.invocations, avgTime: measure.time / measure.invocations, totalTime: measure.time, percentTime: (measure.time / totalTime) * 100});
|
||||
results.push({name: name,invocations: measure.invocations, avgTime: measure.time / measure.invocations, totalTime: measure.time, percentTime: (measure.time / totalTime) * 100})
|
||||
});
|
||||
self.logger.table(results);
|
||||
};
|
||||
|
||||
@@ -47,10 +47,10 @@ exports.repackPlugin = function(title,additionalTiddlers,excludeTiddlers) {
|
||||
});
|
||||
// Retrieve and bump the version number
|
||||
var pluginVersion = $tw.utils.parseVersion(pluginTiddler.getFieldString("version") || "0.0.0") || {
|
||||
major: "0",
|
||||
minor: "0",
|
||||
patch: "0"
|
||||
};
|
||||
major: "0",
|
||||
minor: "0",
|
||||
patch: "0"
|
||||
};
|
||||
pluginVersion.patch++;
|
||||
var version = pluginVersion.major + "." + pluginVersion.minor + "." + pluginVersion.patch;
|
||||
if(pluginVersion.prerelease) {
|
||||
|
||||
@@ -916,12 +916,12 @@ exports.transliterationPairs = {
|
||||
|
||||
exports.transliterate = function(str) {
|
||||
return str.replace(/[^A-Za-z0-9\[\] ]/g,function(ch) {
|
||||
return exports.transliterationPairs[ch] || ch;
|
||||
return exports.transliterationPairs[ch] || ch
|
||||
});
|
||||
};
|
||||
|
||||
exports.transliterateToSafeASCII = function(str) {
|
||||
return str.replace(/[^\x20-\x7F]/g,function(ch) {
|
||||
return exports.transliterationPairs[ch] || "";
|
||||
return exports.transliterationPairs[ch] || ""
|
||||
});
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user