run prettier

This commit is contained in:
Damien Elmes 2019-12-18 16:12:39 +10:00
parent d7d0d9bf88
commit 40418c3712
6 changed files with 137 additions and 91 deletions

View file

@ -4,7 +4,6 @@
$(init);
function init() {
$("tr.deck").draggable({
scroll: false,
@ -13,21 +12,21 @@ function init() {
return $(this).clone(false);
},
delay: 200,
opacity: 0.7
opacity: 0.7,
});
$("tr.deck").droppable({
drop: handleDropEvent,
hoverClass: 'drag-hover'
hoverClass: "drag-hover",
});
$("tr.top-level-drag-row").droppable({
drop: handleDropEvent,
hoverClass: 'drag-hover'
hoverClass: "drag-hover",
});
}
function handleDropEvent(event, ui) {
var draggedDeckId = ui.draggable.attr('id');
var ontoDeckId = $(this).attr('id') || '';
var draggedDeckId = ui.draggable.attr("id");
var ontoDeckId = $(this).attr("id") || "";
pycmd("drag:" + draggedDeckId + "," + ontoDeckId);
}

View file

@ -54,8 +54,7 @@ function onKey(evt: KeyboardEvent) {
return;
}
// shift+tab goes to previous field
if (navigator.platform === "MacIntel" &&
evt.which === 9 && evt.shiftKey) {
if (navigator.platform === "MacIntel" && evt.which === 9 && evt.shiftKey) {
evt.preventDefault();
focusPrevious();
return;
@ -133,7 +132,7 @@ function toggleEditorButton(buttonid) {
function setFormat(cmd: string, arg?: any, nosave: boolean = false) {
document.execCommand(cmd, false, arg);
if (!nosave) {
saveField('key');
saveField("key");
updateButtonState();
}
}
@ -164,13 +163,15 @@ function onFocus(elem) {
var cur = 0;
do {
cur += obj.offsetTop;
} while (obj = obj.offsetParent);
} while ((obj = obj.offsetParent));
return cur;
}
var y = pos(elem);
if ((window.pageYOffset + window.innerHeight) < (y + elem.offsetHeight) ||
window.pageYOffset > y) {
if (
window.pageYOffset + window.innerHeight < y + elem.offsetHeight ||
window.pageYOffset > y
) {
window.scroll(0, y + elem.offsetHeight - window.innerHeight);
}
}
@ -193,7 +194,7 @@ function focusPrevious() {
}
function onDragOver(elem) {
var e = window.event as unknown as DragOverEvent;
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
@ -244,7 +245,15 @@ function saveField(type) {
return;
}
// type is either 'blur' or 'key'
pycmd(type + ":" + currentFieldOrdinal() + ":" + currentNoteId + ":" + currentField.innerHTML);
pycmd(
type +
":" +
currentFieldOrdinal() +
":" +
currentNoteId +
":" +
currentField.innerHTML
);
}
function currentFieldOrdinal() {
@ -266,7 +275,10 @@ function enableButtons() {
// disable the buttons if a field is not currently focused
function maybeDisableButtons() {
if (!document.activeElement || document.activeElement.className !== "field") {
if (
!document.activeElement ||
document.activeElement.className !== "field"
) {
disableButtons();
} else {
enableButtons();
@ -325,13 +337,18 @@ function setFields(fields) {
}
txt += `<tr><td class=fname>${n}</td></tr><tr><td width=100%>`;
txt += `<div id=f${i} onkeydown='onKey(window.event);' oninput='onInput()' onmouseup='onKey();'`;
txt += " onfocus='onFocus(this);' onblur='onBlur();' class='field clearfix' ";
txt +=
" onfocus='onFocus(this);' onblur='onBlur();' class='field clearfix' ";
txt += "ondragover='onDragOver(this);' onpaste='onPaste(this);' ";
txt += "oncopy='onCutOrCopy(this);' oncut='onCutOrCopy(this);' ";
txt += `contentEditable=true class=field>${f}</div>`;
txt += "</td></tr>";
}
$("#fields").html("<table cellpadding=0 width=100% style='table-layout: fixed;'>" + txt + "</table>");
$("#fields").html(
"<table cellpadding=0 width=100% style='table-layout: fixed;'>" +
txt +
"</table>"
);
maybeDisableButtons();
}
@ -344,8 +361,7 @@ function setBackgrounds(cols) {
function setFonts(fonts) {
for (var i = 0; i < fonts.length; i++) {
var n = $("#f" + i);
n.css("font-family", fonts[i][0])
.css("font-size", fonts[i][1]);
n.css("font-family", fonts[i][0]).css("font-size", fonts[i][1]);
n[0].dir = fonts[i][2] ? "rtl" : "ltr";
}
}
@ -398,29 +414,48 @@ var allowedTagsExtended = {};
var TAGS_WITHOUT_ATTRS = ["P", "DIV", "BR", "SUB", "SUP"];
var i;
for (i = 0; i < TAGS_WITHOUT_ATTRS.length; i++) {
allowedTagsBasic[TAGS_WITHOUT_ATTRS[i]] = {"attrs": []};
allowedTagsBasic[TAGS_WITHOUT_ATTRS[i]] = { attrs: [] };
}
TAGS_WITHOUT_ATTRS = ["H1", "H2", "H3", "LI", "UL", "OL", "BLOCKQUOTE", "CODE",
"PRE", "TABLE", "DD", "DT", "DL", "B", "U", "I", "RUBY", "RT", "RP"];
TAGS_WITHOUT_ATTRS = [
"H1",
"H2",
"H3",
"LI",
"UL",
"OL",
"BLOCKQUOTE",
"CODE",
"PRE",
"TABLE",
"DD",
"DT",
"DL",
"B",
"U",
"I",
"RUBY",
"RT",
"RP",
];
for (i = 0; i < TAGS_WITHOUT_ATTRS.length; i++) {
allowedTagsExtended[TAGS_WITHOUT_ATTRS[i]] = {"attrs": []};
allowedTagsExtended[TAGS_WITHOUT_ATTRS[i]] = { attrs: [] };
}
allowedTagsBasic["IMG"] = {"attrs": ["SRC"]};
allowedTagsBasic["IMG"] = { attrs: ["SRC"] };
allowedTagsExtended["A"] = {"attrs": ["HREF"]};
allowedTagsExtended["TR"] = {"attrs": ["ROWSPAN"]};
allowedTagsExtended["TD"] = {"attrs": ["COLSPAN", "ROWSPAN"]};
allowedTagsExtended["TH"] = {"attrs": ["COLSPAN", "ROWSPAN"]};
allowedTagsExtended["FONT"] = {"attrs": ["COLOR"]};
allowedTagsExtended["A"] = { attrs: ["HREF"] };
allowedTagsExtended["TR"] = { attrs: ["ROWSPAN"] };
allowedTagsExtended["TD"] = { attrs: ["COLSPAN", "ROWSPAN"] };
allowedTagsExtended["TH"] = { attrs: ["COLSPAN", "ROWSPAN"] };
allowedTagsExtended["FONT"] = { attrs: ["COLOR"] };
const allowedStyling = {
'color': true,
'background-color': true,
'font-weight': true,
'font-style': true,
'text-decoration-line': true,
color: true,
"background-color": true,
"font-weight": true,
"font-style": true,
"text-decoration-line": true,
};
var filterExternalSpan = function(node) {
@ -429,7 +464,7 @@ var filterExternalSpan = function(node) {
for (i = 0; i < node.attributes.length; i++) {
var attr = node.attributes[i];
var attrName = attr.name.toUpperCase();
if (attrName !== 'STYLE') {
if (attrName !== "STYLE") {
toRemove.push(attr);
}
}
@ -443,7 +478,7 @@ var filterExternalSpan = function(node) {
if (!allowedStyling.hasOwnProperty(name)) {
toRemove.push(name);
}
if (name === 'background-color' && node.style[name] === "transparent") {
if (name === "background-color" && node.style[name] === "transparent") {
// google docs adds this unnecessarily
toRemove.push(name);
}
@ -451,7 +486,6 @@ var filterExternalSpan = function(node) {
for (let name of toRemove) {
node.style.removeProperty(name);
}
};
allowedTagsExtended["SPAN"] = filterExternalSpan;
@ -502,13 +536,13 @@ var filterNode = function (node, extendedMode) {
tag = allowedTagsBasic[node.tagName];
}
if (!tag) {
if (!node.innerHTML || node.tagName === 'TITLE') {
if (!node.innerHTML || node.tagName === "TITLE") {
node.parentNode.removeChild(node);
} else {
node.outerHTML = node.innerHTML;
}
} else {
if (typeof(tag) === 'function') {
if (typeof tag === "function") {
// filtering function provided
tag(node);
} else {
@ -550,7 +584,7 @@ $(function () {
if (src.tagName === "IMG") {
// image clicked; find contenteditable parent
var p = src;
while (p = p.parentNode as Element) {
while ((p = p.parentNode as Element)) {
if (p.className === "field") {
$("#" + p.id).focus();
break;

View file

@ -1,4 +1,6 @@
/* Copyright: Ankitects Pty Ltd and contributors
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
$(function () { $("#study").focus(); });
$(function() {
$("#study").focus();
});

View file

@ -9,7 +9,7 @@ $(function () {
updateTime();
setInterval(function() {
time += 1;
updateTime()
updateTime();
}, 1000);
});

View file

@ -21,7 +21,9 @@ function _updateQA(html, fadeTime, onupdate, onshown) {
// if a request to update q/a comes in before the previous content
// has been loaded, wait a while and try again
if (_updatingQA) {
setTimeout(function () { _updateQA(html, fadeTime, onupdate, onshown) }, 50);
setTimeout(function() {
_updateQA(html, fadeTime, onupdate, onshown);
}, 50);
return;
}
@ -58,22 +60,30 @@ function _updateQA(html, fadeTime, onupdate, onshown) {
}
function _showQuestion(q, bodyclass) {
_updateQA(q, qFade, function() {
_updateQA(
q,
qFade,
function() {
// return to top of window
window.scrollTo(0, 0);
document.body.className = bodyclass;
}, function() {
},
function() {
// focus typing area if visible
typeans = document.getElementById("typeans");
if (typeans) {
typeans.focus();
}
});
}
);
}
function _showAnswer(a, bodyclass) {
_updateQA(a, aFade, function() {
_updateQA(
a,
aFade,
function() {
if (bodyclass) {
// when previewing
document.body.className = bodyclass;
@ -84,15 +94,16 @@ function _showAnswer(a, bodyclass) {
if (e[0]) {
e[0].scrollIntoView();
}
}, function() {
});
},
function() {}
);
}
const _flagColours = {
1: "#ff6666",
2: "#ff9900",
3: "#77ff77",
4: "#77aaff"
4: "#77aaff",
};
function _drawFlag(flag) {