diff --git a/Makefile b/Makefile
index f3cfb1d7a..3865293d2 100644
--- a/Makefile
+++ b/Makefile
@@ -93,4 +93,4 @@ JSDEPS := $(patsubst ts/%.ts, web/%.js, $(TSDEPS))
js: $(JSDEPS)
web/%.js: ts/%.ts
- (cd ts && ./node_modules/.bin/tsc lib/global.d.ts $(notdir $<) --outFile ../web/$(notdir $@))
+ (cd ts && ./node_modules/.bin/tsc --lib es6,dom lib/global.d.ts $(notdir $<) --outFile ../web/$(notdir $@))
diff --git a/web/editor.js b/ts/editor.ts
similarity index 93%
rename from web/editor.js
rename to ts/editor.ts
index f6d378a21..5d72f312c 100644
--- a/web/editor.js
+++ b/ts/editor.ts
@@ -1,11 +1,18 @@
/* Copyright: Ankitects Pty Ltd and contributors
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
+import DragOverEvent = JQuery.DragOverEvent;
+
var currentField = null;
var changeTimer = null;
var dropTarget = null;
var currentNoteId = null;
+declare interface String {
+ format(...args) : string;
+}
+
+/* kept for compatibility with add-ons */
String.prototype.format = function () {
var args = arguments;
return this.replace(/\{\d+\}/g, function (m) {
@@ -40,16 +47,16 @@ function triggerKeyTimer() {
}, 600);
}
-function onKey() {
+function onKey(evt: KeyboardEvent) {
// esc clears focus, allowing dialog to close
- if (window.event.which === 27) {
+ if (evt.which === 27) {
currentField.blur();
return;
}
// shift+tab goes to previous field
if (navigator.platform === "MacIntel" &&
- window.event.which === 9 && window.event.shiftKey) {
- window.event.preventDefault();
+ evt.which === 9 && evt.shiftKey) {
+ evt.preventDefault();
focusPrevious();
return;
}
@@ -83,9 +90,9 @@ function insertNewline() {
// is the cursor in an environment that respects whitespace?
function inPreEnvironment() {
- var n = window.getSelection().anchorNode;
+ let n = window.getSelection().anchorNode as Element;
if (n.nodeType === 3) {
- n = n.parentNode;
+ n = n.parentNode as Element;
}
return window.getComputedStyle(n).whiteSpace.startsWith("pre");
}
@@ -123,7 +130,7 @@ function toggleEditorButton(buttonid) {
}
}
-function setFormat(cmd, arg, nosave) {
+function setFormat(cmd: string, arg?: any, nosave: boolean = false) {
document.execCommand(cmd, false, arg);
if (!nosave) {
saveField('key');
@@ -186,8 +193,8 @@ function focusPrevious() {
}
function onDragOver(elem) {
- var e = window.event;
- e.dataTransfer.dropEffect = "copy";
+ var e = window.event as unknown as DragOverEvent;
+ //e.dataTransfer.dropEffect = "copy";
e.preventDefault();
// if we focus the target element immediately, the drag&drop turns into a
// copy, so note it down for later instead
@@ -316,12 +323,12 @@ function setFields(fields) {
if (!f) {
f = "
";
}
- txt += "