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
// Setup crypto
$tw.crypto = new function() {
var Crypto = function() {
var password = null,
callSjcl = function(method,inputText) {
var outputText;
@ -49,20 +49,20 @@ $tw.crypto = new function() {
try {
outputText = $tw.crypto.sjcl[method](password,inputText);
} catch(ex) {
console.log("Crypto error:" + ex)
console.log("Crypto error:" + ex);
outputText = null;
}
return outputText;
},
getPassword = function() {
if($tw.browser) {
password = prompt("Enter password to decrypt TiddlyWiki");
password = window.prompt("Enter password to decrypt TiddlyWiki");
}
};
this.setPassword = function(newPassword) {
password = newPassword;
}
};
this.encrypt = function(text) {
return callSjcl("encrypt",text);
};
@ -70,6 +70,7 @@ $tw.crypto = new function() {
return callSjcl("decrypt",text);
};
};
$tw.crypto = new Crypto();
$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
*/
$tw.Wiki.prototype.registerModuleTiddlers = function() {
/*jslint evil: true */
var title, tiddler;
// If in the browser, define any modules from plugins
if($tw.browser) {
@ -466,7 +468,7 @@ $tw.Wiki.prototype.registerModuleTiddlers = function() {
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) {
basetitle = basetitle || "$:/plugins";
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)) {
var stat = fs.statSync(filepath);
stat = fs.statSync(filepath);
if(stat.isDirectory()) {
var files = fs.readdirSync(filepath);
files = fs.readdirSync(filepath);
// Look for a tiddlywiki.plugin file
if(files.indexOf("tiddlywiki.plugin") !== -1) {
// 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
var pluginTiddlers = [];
for(var f=0; f<files.length; f++) {
var file = files[f];
pluginTiddlers = [];
for(f=0; f<files.length; f++) {
file = files[f];
if(!excludeRegExp.test(file) && file !== "tiddlywiki.plugin" && file !== "tiddlywiki.files") {
pluginTiddlers.push.apply(pluginTiddlers,$tw.extractTiddlersFromPath(filepath + "/" + file,basetitle + "/" + file,excludeRegExp));
}
}
// Save the plugin tiddlers into the plugin
pluginInfo.tiddlers = pluginInfo.tiddlers || {};
var titlePrefix = pluginInfo.title + "/";
for(var t=0; t<pluginTiddlers.length; t++) {
titlePrefix = pluginInfo.title + "/";
for(t=0; t<pluginTiddlers.length; t++) {
// 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) {
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
} else if(files.indexOf("tiddlywiki.files") !== -1) {
// If so, process the files it describes
var filesInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.files").toString("utf8"));
for(var p=0; p<filesInfo.tiddlers.length; p++) {
var tidInfo = filesInfo.tiddlers[p],
typeInfo = $tw.config.contentTypeInfo[tidInfo.fields.type || "text/plain"],
text = fs.readFileSync(path.resolve(filepath,tidInfo.file)).toString(typeInfo ? typeInfo.encoding : "utf8");
filesInfo = JSON.parse(fs.readFileSync(filepath + "/tiddlywiki.files").toString("utf8"));
for(p=0; p<filesInfo.tiddlers.length; p++) {
tidInfo = filesInfo.tiddlers[p];
typeInfo = $tw.config.contentTypeInfo[tidInfo.fields.type || "text/plain"];
text = fs.readFileSync(path.resolve(filepath,tidInfo.file)).toString(typeInfo ? typeInfo.encoding : "utf8");
tidInfo.fields.text = text;
tiddlers.push(tidInfo.fields);
}
} else {
// If not, read all the files in the directory
for(var f=0; f<files.length; f++) {
var file = files[f];
for(f=0; f<files.length; f++) {
file = files[f];
if(!excludeRegExp.test(file)) {
tiddlers.push.apply(tiddlers,$tw.extractTiddlersFromPath(filepath + "/" + file,basetitle + "/" + file,excludeRegExp));
}

View File

@ -216,7 +216,7 @@ exports.operators = {
filter: function(operator) {
var op = operator.prefix === "!" ? "true" : "false";
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

View File

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

View File

@ -123,7 +123,7 @@ exports.createListElement = function(title) {
node.execute(this.parents,this.tiddlerTitle);
// Add any specified classes
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],{
events: ["tw-navigate","tw-EditTiddler","tw-SaveTiddler","tw-CloseTiddler","tw-NewTiddler"],

View File

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

View File

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

View File

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

View File

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

View File

@ -46,10 +46,10 @@ exports.executeMacro = function() {
$tw.utils.pushTop(outerClasses,this.classes);
}
if(this.hasParameter("width")) {
outerAttributes.style.width = this.params["width"];
outerAttributes.style.width = this.params.width;
}
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),
outerFrame = $tw.Tree.Element("div",outerAttributes,[innerFrame]);
@ -85,7 +85,7 @@ exports.scrollTo = function(bounds) {
t = 1;
}
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;
}, 10);
}

View File

@ -53,7 +53,7 @@ exports.executeMacro = function() {
Viewer = this.wiki.macros.view.fieldviewers[this.params.format];
}
if(!Viewer) {
Viewer = this.wiki.macros.view.fieldviewers["text"];
Viewer = this.wiki.macros.view.fieldviewers.text;
}
this.viewer = new Viewer(this,tiddler,field,value);
// 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);
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 {
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);
}
}
};
exports["transclude"] = TranscludeViewer;
exports.transclude = TranscludeViewer;
})();

View File

@ -42,8 +42,8 @@ WikifiedViewer.prototype.render = function() {
childrenClone[t].execute(parents,this.viewMacro.tiddlerTitle);
}
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";
var ImageParser = function(options) {
this.wiki = options.wiki;
this.wiki = options.wiki;
};
ImageParser.prototype.parse = function(type,text) {
var element = "img",
src;
if(type === "application/pdf" || type === ".pdf") {
src = "data:application/pdf;base64," + text;
element = "embed";
} else if(type === "image/svg+xml" || type === ".svg") {
src = "data:image/svg+xml," + encodeURIComponent(text);
var element = "img",
src;
if(type === "application/pdf" || type === ".pdf") {
src = "data:application/pdf;base64," + text;
element = "embed";
} else if(type === "image/svg+xml" || type === ".svg") {
src = "data:image/svg+xml," + encodeURIComponent(text);
} else {
src = "data:" + type + ";base64," + text;
src = "data:" + type + ";base64," + text;
}
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) {
var tree = [],
reStart = /\{\{([^\{\r\n]+){\r?\n/mg,
reStart = /\{\{([^\{\r\n]+)\{\r?\n/mg,
reEndString = "(\\}\\}\\}$(?:\\r?\\n)?)",
endMatch;
reStart.lastIndex = this.pos;

View File

@ -29,7 +29,7 @@ exports.regExpString = "\\{\\{(?:[^\\{\\r\\n]+)\\{";
exports.parse = function(match,isBlock) {
var tree,
reStart = /\{\{([^\{\r\n]+){/mg,
reStart = /\{\{([^\{\r\n]+)\{/mg,
reEnd = /(\}\}\})/g;
reStart.lastIndex = this.pos;
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.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
window.alert(http.responseText);
}
};
http.send(data);

View File

@ -169,7 +169,7 @@ exports["application/x-tiddler-encrypted-div"] = function(tiddlers) {
exports["application/x-tiddler-javascript"] = function(tiddlers) {
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
if($tw.browser) {
// Call browser startup modules
var modules = $tw.modules.types["browser-startup"];
for(var m=0; m<modules.length; m++) {
modules = $tw.modules.types["browser-startup"];
for(m=0; m<modules.length; m++) {
modules[m].startup();
}
// Install the popup manager

View File

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

View File

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

View File

@ -122,7 +122,7 @@ Modal.prototype.display = function(title) {
{transition: "opacity " + d + " ease-out"}
]);
$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
$tw.utils.forceLayout(modalBackdrop);

View File

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

View File

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

View File

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