Skip to content

Commit

Permalink
Update stable.js
Browse files Browse the repository at this point in the history
allow custom methods for showing card and answer akrivka#17
  • Loading branch information
hungriesthippo committed Feb 18, 2021
1 parent c9dc2b3 commit 2951f96
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions js/stable.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ roamsr.goToCurrentCard = async () => {
await roamsr.sleep(50);
roamsr.addContainer();
roamsr.addShowAnswerButton();
if (typeof window.roamsrUserSettings.onShowCard === "function") {
window.roamsrUserSettings.onShowCard(roamsr.getCurrentCard());
// TODO: receive signal from this function while the card is still active
}
}

await doStuff();
Expand Down Expand Up @@ -728,13 +732,22 @@ roamsr.addShowAnswerButton = () => {
var showAnswerAndClozeButton = Object.assign(document.createElement("button"), {
className: "bp3-button roamsr-container__response-area__show-answer-button",
innerHTML: "Show answer.",
onclick: () => { roamsr.showAnswerAndCloze(false); roamsr.addResponseButtons(); }
onclick: roamsr.requestAnswer
})
showAnswerAndClozeButton.style.cssText = "margin: 5px;";

responseArea.append(showAnswerAndClozeButton);
};

roamsr.requestAnswer = () => {
roamsr.showAnswerAndCloze(false);
roamsr.addResponseButtons();
if (typeof window.roamsrUserSettings.onShowAnswer === "function") {
window.roamsrUserSettings.onShowAnswer();
// TODO: receive signal from this function while the card is still active
}
}

roamsr.addResponseButtons = () => {
var responseArea = roamsr.clearAndGetResponseArea();

Expand Down Expand Up @@ -871,7 +884,7 @@ roamsr.processKey = (e) => {
}

if (e.code == "Space") {
roamsr.showAnswerAndCloze(false); roamsr.addResponseButtons();
roamsr.requestAnswer();
return;
}

Expand Down

0 comments on commit 2951f96

Please sign in to comment.