1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-24 17:10:29 +00:00

Appeasing the gods of JSHint

This commit is contained in:
Jeremy Ruston 2012-11-06 17:21:56 +00:00
parent 54252a5400
commit 9f6909ddc4
28 changed files with 69 additions and 66 deletions

View File

@ -39,7 +39,7 @@ if(typeof(window) === "undefined" && !global.$tw) {
// Crypto helper object // Crypto helper object
// Setup crypto // Setup crypto
$tw.crypto = new function() { var Crypto = function() {
var password = null, var password = null,
callSjcl = function(method,inputText) { callSjcl = function(method,inputText) {
var outputText; var outputText;
@ -49,20 +49,20 @@ $tw.crypto = new function() {
try { try {
outputText = $tw.crypto.sjcl[method](password,inputText); outputText = $tw.crypto.sjcl[method](password,inputText);
} catch(ex) { } catch(ex) {
console.log("Crypto error:" + ex) console.log("Crypto error:" + ex);
outputText = null; outputText = null;
} }
return outputText; return outputText;
}, },
getPassword = function() { getPassword = function() {
if($tw.browser) { if($tw.browser) {
password = prompt("Enter password to decrypt TiddlyWiki"); password = window.prompt("Enter password to decrypt TiddlyWiki");
} }
}; };
this.setPassword = function(newPassword) { this.setPassword = function(newPassword) {
password = newPassword; password = newPassword;
} };
this.encrypt = function(text) { this.encrypt = function(text) {
return callSjcl("encrypt",text); return callSjcl("encrypt",text);
}; };
@ -70,6 +70,7 @@ $tw.crypto = new function() {
return callSjcl("decrypt",text); return callSjcl("decrypt",text);
}; };
}; };
$tw.crypto = new Crypto();
$tw.crypto.sjcl = $tw.browser ? window.sjcl : require("./sjcl.js"); $tw.crypto.sjcl = $tw.browser ? window.sjcl : require("./sjcl.js");
@ -453,6 +454,7 @@ $tw.Wiki.prototype.installPlugins = function() {
Register all the module tiddlers that have a module type Register all the module tiddlers that have a module type
*/ */
$tw.Wiki.prototype.registerModuleTiddlers = function() { $tw.Wiki.prototype.registerModuleTiddlers = function() {
/*jslint evil: true */
var title, tiddler; var title, tiddler;
// If in the browser, define any modules from plugins // If in the browser, define any modules from plugins
if($tw.browser) { if($tw.browser) {
@ -466,7 +468,7 @@ $tw.Wiki.prototype.registerModuleTiddlers = function() {
tiddler.fields.text, tiddler.fields.text,
"})" "})"
]; ];
$tw.modules.define(tiddler.fields.title,tiddler.fields["module-type"],window.eval(source.join(""))); $tw.modules.define(tiddler.fields.title,tiddler.fields["module-type"],window["eval"](source.join("")));
} }
} }
} }
@ -750,27 +752,28 @@ Load all the tiddlers from a directory
$tw.extractTiddlersFromPath = function(filepath,basetitle,excludeRegExp) { $tw.extractTiddlersFromPath = function(filepath,basetitle,excludeRegExp) {
basetitle = basetitle || "$:/plugins"; basetitle = basetitle || "$:/plugins";
excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/; excludeRegExp = excludeRegExp || /^\.DS_Store$|.meta$/;
var tiddlers = []; var tiddlers = [],
stat, files, pluginInfo, pluginTiddlers, f, file, titlePrefix, t, filesInfo, p, tidInfo, typeInfo, text;
if(fs.existsSync(filepath)) { if(fs.existsSync(filepath)) {
var stat = fs.statSync(filepath); stat = fs.statSync(filepath);
if(stat.isDirectory()) { if(stat.isDirectory()) {
var files = fs.readdirSync(filepath); files = fs.readdirSync(filepath);
// Look for a tiddlywiki.plugin file // Look for a tiddlywiki.plugin file
if(files.indexOf("tiddlywiki.plugin") !== -1) { if(files.indexOf("tiddlywiki.plugin") !== -1) {
// Read the plugin information // Read the plugin information
var pluginInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.plugin").toString("utf8")); pluginInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.plugin").toString("utf8"));
// Read the plugin files // Read the plugin files
var pluginTiddlers = []; pluginTiddlers = [];
for(var f=0; f<files.length; f++) { for(f=0; f<files.length; f++) {
var file = files[f]; file = files[f];
if(!excludeRegExp.test(file) && file !== "tiddlywiki.plugin" && file !== "tiddlywiki.files") { if(!excludeRegExp.test(file) && file !== "tiddlywiki.plugin" && file !== "tiddlywiki.files") {
pluginTiddlers.push.apply(pluginTiddlers,$tw.extractTiddlersFromPath(filepath + "/" + file,basetitle + "/" + file,excludeRegExp)); pluginTiddlers.push.apply(pluginTiddlers,$tw.extractTiddlersFromPath(filepath + "/" + file,basetitle + "/" + file,excludeRegExp));
} }
} }
// Save the plugin tiddlers into the plugin // Save the plugin tiddlers into the plugin
pluginInfo.tiddlers = pluginInfo.tiddlers || {}; pluginInfo.tiddlers = pluginInfo.tiddlers || {};
var titlePrefix = pluginInfo.title + "/"; titlePrefix = pluginInfo.title + "/";
for(var t=0; t<pluginTiddlers.length; t++) { for(t=0; t<pluginTiddlers.length; t++) {
// Check that the constituent tiddler has the plugin title as a prefix // Check that the constituent tiddler has the plugin title as a prefix
if(pluginTiddlers[t].title.indexOf(titlePrefix) === 0 && pluginTiddlers[t].title.length > titlePrefix.length) { if(pluginTiddlers[t].title.indexOf(titlePrefix) === 0 && pluginTiddlers[t].title.length > titlePrefix.length) {
pluginInfo.tiddlers[pluginTiddlers[t].title.substr(titlePrefix.length)] = pluginTiddlers[t]; pluginInfo.tiddlers[pluginTiddlers[t].title.substr(titlePrefix.length)] = pluginTiddlers[t];
@ -783,18 +786,18 @@ $tw.extractTiddlersFromPath = function(filepath,basetitle,excludeRegExp) {
// Look for a tiddlywiki.files file // Look for a tiddlywiki.files file
} else if(files.indexOf("tiddlywiki.files") !== -1) { } else if(files.indexOf("tiddlywiki.files") !== -1) {
// If so, process the files it describes // If so, process the files it describes
var filesInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.files").toString("utf8")); filesInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.files").toString("utf8"));
for(var p=0; p<filesInfo.tiddlers.length; p++) { for(p=0; p<filesInfo.tiddlers.length; p++) {
var tidInfo = filesInfo.tiddlers[p], tidInfo = filesInfo.tiddlers[p];
typeInfo = $tw.config.contentTypeInfo[tidInfo.fields.type || "text/plain"], typeInfo = $tw.config.contentTypeInfo[tidInfo.fields.type || "text/plain"];
text = fs.readFileSync(path.resolve(filepath,tidInfo.file)).toString(typeInfo ? typeInfo.encoding : "utf8"); text = fs.readFileSync(path.resolve(filepath,tidInfo.file)).toString(typeInfo ? typeInfo.encoding : "utf8");
tidInfo.fields.text = text; tidInfo.fields.text = text;
tiddlers.push(tidInfo.fields); tiddlers.push(tidInfo.fields);
} }
} else { } else {
// If not, read all the files in the directory // If not, read all the files in the directory
for(var f=0; f<files.length; f++) { for(f=0; f<files.length; f++) {
var file = files[f]; file = files[f];
if(!excludeRegExp.test(file)) { if(!excludeRegExp.test(file)) {
tiddlers.push.apply(tiddlers,$tw.extractTiddlersFromPath(filepath + "/" + file,basetitle + "/" + file,excludeRegExp)); tiddlers.push.apply(tiddlers,$tw.extractTiddlersFromPath(filepath + "/" + file,basetitle + "/" + file,excludeRegExp));
} }

View File

@ -216,7 +216,7 @@ exports.operators = {
filter: function(operator) { filter: function(operator) {
var op = operator.prefix === "!" ? "true" : "false"; var op = operator.prefix === "!" ? "true" : "false";
return "var term = this.getTiddler(\"" + $tw.utils.stringify(operator.operand) + "\").fields.text;" + return "var term = this.getTiddler(\"" + $tw.utils.stringify(operator.operand) + "\").fields.text;" +
"subResults = this.search(term,{titles: subResults, invert: " + op + ", exclude: [\"" + $tw.utils.stringify(operator.operand) + "\"]});" "subResults = this.search(term,{titles: subResults, invert: " + op + ", exclude: [\"" + $tw.utils.stringify(operator.operand) + "\"]});";
} }
}, },
"field": { // Special handler for field comparisons "field": { // Special handler for field comparisons

View File

@ -61,7 +61,6 @@ exports.executeMacro = function() {
]); ]);
child.execute(this.parents,this.tiddlerTitle); child.execute(this.parents,this.tiddlerTitle);
return child; return child;
return this.viewer.render();
}; };
})(); })();

View File

@ -123,7 +123,7 @@ exports.createListElement = function(title) {
node.execute(this.parents,this.tiddlerTitle); node.execute(this.parents,this.tiddlerTitle);
// Add any specified classes // Add any specified classes
if(this.hasParameter("itemClass")) { if(this.hasParameter("itemClass")) {
attributes["class"].push(this.params["itemClass"]); attributes["class"].push(this.params.itemClass);
} }
var listElement = $tw.Tree.Element(this.isBlock ? "div" : "span",attributes,[node],{ var listElement = $tw.Tree.Element(this.isBlock ? "div" : "span",attributes,[node],{
events: ["tw-navigate","tw-EditTiddler","tw-SaveTiddler","tw-CloseTiddler","tw-NewTiddler"], events: ["tw-navigate","tw-EditTiddler","tw-SaveTiddler","tw-CloseTiddler","tw-NewTiddler"],

View File

@ -26,7 +26,7 @@ function CecilyListView(listMacro) {
domNode.style.position = "absolute"; domNode.style.position = "absolute";
this.positionTiddler(title,domNode); this.positionTiddler(title,domNode);
} }
}; }
CecilyListView.prototype.getMapTiddlerTitle = function() { CecilyListView.prototype.getMapTiddlerTitle = function() {
return this.listMacro.params.map || "$:/TiddlerMap"; return this.listMacro.params.map || "$:/TiddlerMap";
@ -117,6 +117,6 @@ CecilyListView.prototype.remove = function(index) {
return true; return true;
}; };
exports["cecily"] = CecilyListView; exports.cecily = CecilyListView;
})(); })();

View File

@ -88,6 +88,6 @@ ClassicListView.prototype.remove = function(index) {
return true; return true;
}; };
exports["classic"] = ClassicListView; exports.classic = ClassicListView;
})(); })();

View File

@ -46,7 +46,7 @@ SidewaysListView.prototype.insert = function(index) {
{verticalAlign: "top"}, {verticalAlign: "top"},
{display: "inline-block"}, {display: "inline-block"},
{transition: "none"}, {transition: "none"},
{opacity: "0.0"}, {opacity: "0.0"}
]); ]);
var currWidth = targetElement.offsetWidth + parseInt(window.getComputedStyle(targetElement).marginLeft,10); var currWidth = targetElement.offsetWidth + parseInt(window.getComputedStyle(targetElement).marginLeft,10);
$tw.utils.setStyle(targetElement,[ $tw.utils.setStyle(targetElement,[
@ -89,6 +89,6 @@ SidewaysListView.prototype.remove = function(index) {
return true; return true;
}; };
exports["sideways"] = SidewaysListView; exports.sideways = SidewaysListView;
})(); })();

View File

@ -165,8 +165,9 @@ exports.eventMap["tw-NewTiddler"] = function(event) {
// Get the story details // Get the story details
this.story = this.getList(this.storyTitle); this.story = this.getList(this.storyTitle);
// Create the new tiddler // Create the new tiddler
var title;
for(var t=0; true; t++) { for(var t=0; true; t++) {
var title = "New Tiddler" + (t ? " " + t : ""); title = "New Tiddler" + (t ? " " + t : "");
if(!this.wiki.tiddlerExists(title)) { if(!this.wiki.tiddlerExists(title)) {
break; break;
} }

View File

@ -46,10 +46,10 @@ exports.executeMacro = function() {
$tw.utils.pushTop(outerClasses,this.classes); $tw.utils.pushTop(outerClasses,this.classes);
} }
if(this.hasParameter("width")) { if(this.hasParameter("width")) {
outerAttributes.style.width = this.params["width"]; outerAttributes.style.width = this.params.width;
} }
if(this.hasParameter("height")) { if(this.hasParameter("height")) {
outerAttributes.style.height = this.params["height"]; outerAttributes.style.height = this.params.height;
} }
var innerFrame = $tw.Tree.Element("div",innerAttributes,this.content), var innerFrame = $tw.Tree.Element("div",innerAttributes,this.content),
outerFrame = $tw.Tree.Element("div",outerAttributes,[innerFrame]); outerFrame = $tw.Tree.Element("div",outerAttributes,[innerFrame]);
@ -85,7 +85,7 @@ exports.scrollTo = function(bounds) {
t = 1; t = 1;
} }
t = slowInSlowOut(t); t = slowInSlowOut(t);
self.child.domNode.scrollLeft = self.startX + (self.endX - self.startX) * t self.child.domNode.scrollLeft = self.startX + (self.endX - self.startX) * t;
self.child.domNode.scrollTop = self.startY + (self.endY - self.startY) * t; self.child.domNode.scrollTop = self.startY + (self.endY - self.startY) * t;
}, 10); }, 10);
} }

View File

@ -53,7 +53,7 @@ exports.executeMacro = function() {
Viewer = this.wiki.macros.view.fieldviewers[this.params.format]; Viewer = this.wiki.macros.view.fieldviewers[this.params.format];
} }
if(!Viewer) { if(!Viewer) {
Viewer = this.wiki.macros.view.fieldviewers["text"]; Viewer = this.wiki.macros.view.fieldviewers.text;
} }
this.viewer = new Viewer(this,tiddler,field,value); this.viewer = new Viewer(this,tiddler,field,value);
// Call the viewer to generate the content // Call the viewer to generate the content

View File

@ -28,6 +28,6 @@ DateViewer.prototype.render = function() {
} }
}; };
exports["date"] = DateViewer; exports.date = DateViewer;
})(); })();

View File

@ -32,8 +32,8 @@ LinkViewer.prototype.render = function() {
link.execute(this.viewMacro.parents,this.viewMacro.tiddlerTitle); link.execute(this.viewMacro.parents,this.viewMacro.tiddlerTitle);
return link; return link;
} }
} };
exports["link"] = LinkViewer; exports.link = LinkViewer;
})(); })();

View File

@ -70,6 +70,6 @@ RelativeDateViewer.prototype.update = function() {
} }
}; };
exports["relativedate"] = RelativeDateViewer; exports.relativedate = RelativeDateViewer;
})(); })();

View File

@ -30,8 +30,8 @@ TextViewer.prototype.render = function() {
} else { } else {
return $tw.Tree.Text(this.value); return $tw.Tree.Text(this.value);
} }
} };
exports["text"] = TextViewer; exports.text = TextViewer;
})(); })();

View File

@ -31,8 +31,8 @@ TranscludeViewer.prototype.render = function() {
} }
return $tw.Tree.Element(this.viewMacro.isBlock ? "div" : "span",{},childrenClone); return $tw.Tree.Element(this.viewMacro.isBlock ? "div" : "span",{},childrenClone);
} }
} };
exports["transclude"] = TranscludeViewer; exports.transclude = TranscludeViewer;
})(); })();

View File

@ -42,8 +42,8 @@ WikifiedViewer.prototype.render = function() {
childrenClone[t].execute(parents,this.viewMacro.tiddlerTitle); childrenClone[t].execute(parents,this.viewMacro.tiddlerTitle);
} }
return $tw.Tree.Element(this.viewMacro.isBlock ? "div" : "span",{},childrenClone); return $tw.Tree.Element(this.viewMacro.isBlock ? "div" : "span",{},childrenClone);
} };
exports["wikified"] = WikifiedViewer; exports.wikified = WikifiedViewer;
})(); })();

View File

@ -13,19 +13,19 @@ Parses an image into a parse tree containing an HTML img element
"use strict"; "use strict";
var ImageParser = function(options) { var ImageParser = function(options) {
this.wiki = options.wiki; this.wiki = options.wiki;
}; };
ImageParser.prototype.parse = function(type,text) { ImageParser.prototype.parse = function(type,text) {
var element = "img", var element = "img",
src; src;
if(type === "application/pdf" || type === ".pdf") { if(type === "application/pdf" || type === ".pdf") {
src = "data:application/pdf;base64," + text; src = "data:application/pdf;base64," + text;
element = "embed"; element = "embed";
} else if(type === "image/svg+xml" || type === ".svg") { } else if(type === "image/svg+xml" || type === ".svg") {
src = "data:image/svg+xml," + encodeURIComponent(text); src = "data:image/svg+xml," + encodeURIComponent(text);
} else { } else {
src = "data:" + type + ";base64," + text; src = "data:" + type + ";base64," + text;
} }
return new $tw.Renderer([$tw.Tree.Element(element,{src: src})],new $tw.Dependencies()); return new $tw.Renderer([$tw.Tree.Element(element,{src: src})],new $tw.Dependencies());
}; };

View File

@ -32,7 +32,7 @@ exports.regExpString = "\\{\\{(?:[^\\{\\r\\n]+)\\{$\\r?\\n";
exports.parse = function(match,isBlock) { exports.parse = function(match,isBlock) {
var tree = [], var tree = [],
reStart = /\{\{([^\{\r\n]+){\r?\n/mg, reStart = /\{\{([^\{\r\n]+)\{\r?\n/mg,
reEndString = "(\\}\\}\\}$(?:\\r?\\n)?)", reEndString = "(\\}\\}\\}$(?:\\r?\\n)?)",
endMatch; endMatch;
reStart.lastIndex = this.pos; reStart.lastIndex = this.pos;

View File

@ -29,7 +29,7 @@ exports.regExpString = "\\{\\{(?:[^\\{\\r\\n]+)\\{";
exports.parse = function(match,isBlock) { exports.parse = function(match,isBlock) {
var tree, var tree,
reStart = /\{\{([^\{\r\n]+){/mg, reStart = /\{\{([^\{\r\n]+)\{/mg,
reEnd = /(\}\}\})/g; reEnd = /(\}\}\})/g;
reStart.lastIndex = this.pos; reStart.lastIndex = this.pos;
match = reStart.exec(this.source); match = reStart.exec(this.source);

View File

@ -56,7 +56,7 @@ UploadSaver.prototype.save = function(text) {
http.setRequestHeader("Content-Type","multipart/form-data; ;charset=UTF-8; boundary=" + boundary); http.setRequestHeader("Content-Type","multipart/form-data; ;charset=UTF-8; boundary=" + boundary);
http.onreadystatechange = function() { http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) { if(http.readyState == 4 && http.status == 200) {
alert(http.responseText); window.alert(http.responseText);
} }
}; };
http.send(data); http.send(data);

View File

@ -169,7 +169,7 @@ exports["application/x-tiddler-encrypted-div"] = function(tiddlers) {
exports["application/x-tiddler-javascript"] = function(tiddlers) { exports["application/x-tiddler-javascript"] = function(tiddlers) {
return mapEachTiddler(this,tiddlers,function(tiddler) { return mapEachTiddler(this,tiddlers,function(tiddler) {
return "$tw.preloadTiddler(" + JSON.stringify(tiddler.fields) + ");\n" return "$tw.preloadTiddler(" + JSON.stringify(tiddler.fields) + ");\n";
}); });
}; };

View File

@ -42,8 +42,8 @@ exports.startup = function() {
// Host-specific startup // Host-specific startup
if($tw.browser) { if($tw.browser) {
// Call browser startup modules // Call browser startup modules
var modules = $tw.modules.types["browser-startup"]; modules = $tw.modules.types["browser-startup"];
for(var m=0; m<modules.length; m++) { for(m=0; m<modules.length; m++) {
modules[m].startup(); modules[m].startup();
} }
// Install the popup manager // Install the popup manager

View File

@ -52,7 +52,7 @@ exports.convertStyleNameToPropertyName = function(styleName) {
} }
} }
// Put it in the cache too // Put it in the cache too
styleNameCache[styleName] = propertyName styleNameCache[styleName] = propertyName;
return propertyName; return propertyName;
}; };
@ -124,7 +124,7 @@ exports.convertEventName = function(eventName) {
} }
} }
// Put it in the cache too // Put it in the cache too
eventNameCache[eventName] = newEventName eventNameCache[eventName] = newEventName;
return newEventName; return newEventName;
}; };

View File

@ -139,7 +139,7 @@ exports.pulseElement = function(element) {
},false); },false);
// Apply the pulse class // Apply the pulse class
$tw.utils.removeClass(element,"pulse"); $tw.utils.removeClass(element,"pulse");
element.offsetWidth; $tw.utils.forceLayout(element);
$tw.utils.addClass(element,"pulse"); $tw.utils.addClass(element,"pulse");
}; };

View File

@ -122,7 +122,7 @@ Modal.prototype.display = function(title) {
{transition: "opacity " + d + " ease-out"} {transition: "opacity " + d + " ease-out"}
]); ]);
$tw.utils.setStyle(modalWrapper,[ $tw.utils.setStyle(modalWrapper,[
{transition: $tw.utils.roundTripPropertyName("transform") + " " + $tw.config.preferences.animationDurationMs + " ease-in-out"}, {transition: $tw.utils.roundTripPropertyName("transform") + " " + $tw.config.preferences.animationDurationMs + " ease-in-out"}
]); ]);
// Force layout // Force layout
$tw.utils.forceLayout(modalBackdrop); $tw.utils.forceLayout(modalBackdrop);

View File

@ -258,7 +258,7 @@ exports.stringify = function(s) {
Escape the RegExp special characters with a preceding backslash Escape the RegExp special characters with a preceding backslash
*/ */
exports.escapeRegExp = function(s) { exports.escapeRegExp = function(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') return s.replace(/[\-\/\\\^\$\*\+\?\.\(\)\|\[\]\{\}]/g, '\\$&');
}; };
exports.nextTick = function(fn) { exports.nextTick = function(fn) {

View File

@ -687,7 +687,7 @@ exports.search = function(text,options) {
return options.invert ? !match : match; return options.invert ? !match : match;
} }
return false; return false;
} };
// Loop through all the tiddlers doing the search // Loop through all the tiddlers doing the search
var results = []; var results = [];
if($tw.utils.isArray(options.titles)) { if($tw.utils.isArray(options.titles)) {

View File

@ -9,7 +9,7 @@ Message handler for full screen mode
(function(){ (function(){
/*jslint node: true, browser: true */ /*jslint node: true, browser: true */
/*global $tw: false */ /*global $tw: false, Element: false */
"use strict"; "use strict";
var toggleFullScreen = function() { var toggleFullScreen = function() {