Skip to content

Commit

Permalink
Adds beep on error setting on the example.
Browse files Browse the repository at this point in the history
  • Loading branch information
zonble committed Mar 13, 2024
1 parent efb548c commit 648b99a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
3 changes: 3 additions & 0 deletions output/example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
<tr>
<td class="option_title">其他:</td>
<td>
<input type="checkbox" name="beep_on_error" id="beep_on_error"><label for="beep_on_error">錯誤時發出<a
onclick="beep(); return false;">
嗶聲</a></label><br />
<a href="#" id="fullscreen">全螢幕編輯</a><br />
<!-- <a href="#" id="dump_user_phrases">印出使用者詞彙</a><br /> -->
</td>
Expand Down
33 changes: 33 additions & 0 deletions output/example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ function resetUI() {
composingBuffer = "";
}

function beep() {
var snd = new Audio(
"data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3/94gcJ3w+o5/5eIAIAAAVwWgQAVQ2ORaIQwEMAJiDg95G4nQL7mQVWI6GwRcfsZAcsKkJvxgxEjzFUgfHoSQ9Qq7KNwqHwuB13MA4a1q/DmBrHgPcmjiGoh//EwC5nGPEmS4RcfkVKOhJf+WOgoxJclFz3kgn//dBA+ya1GhurNn8zb//9NNutNuhz31f////9vt///z+IdAEAAAK4LQIAKobHItEIYCGAExBwe8jcToF9zIKrEdDYIuP2MgOWFSE34wYiR5iqQPj0JIeoVdlG4VD4XA67mAcNa1fhzA1jwHuTRxDUQ//iYBczjHiTJcIuPyKlHQkv/LHQUYkuSi57yQT//uggfZNajQ3Vmz+Zt//+mm3Wm3Q576v////+32///5/EOgAAADVghQAAAAA//uQZAUAB1WI0PZugAAAAAoQwAAA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Q5GC7DqPQCgbbJUAoRSUj+NIEig0YfyWUho1VBBBA//uQZB4ABZx5zfMakeAAAAmwAAAAF5F3P0w9GtAAACfAAAAAwLhMDmAYWMgVEG1U0FIGCBgXBXAtfMH10000EEEEEECUBYln03TTTdNBDZopopYvrTTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+IDGid/9aaaZTGMuj9mpu9Mpio1dXrr5HERTZSmqU36A3CumzN/9Robv/Xx4v9ijkSRSNLQhAWumap82WRSBUqXStV/YcS+XVLnSS+WLDroqArFkMEsAS+eWmrUzrO0oEmE40RlMZ5+ODIkAyKAGUwZ3mVKmcamcJnMW26MRPgUw6j+LkhyHGVGYjSUUKNpuJUQoOIAyDvEyG8S5yfK6dhZc0Tx1KI/gviKL6qvvFs1+bWtaz58uUNnryq6kt5RzOCkPWlVqVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqKiwkNBVmoWFSJkWFxX4FFRQWR+LsS4W/rFRb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU="
);
snd.play();
}

let ui = (function () {
let that = {};
that.reset = resetUI;
Expand Down Expand Up @@ -84,6 +91,13 @@ let controller = new InputController(ui);
controller.setOnOpenUrl(function (url) {
window.open(url);
});
controller.setOnError(function () {
// console.log("on error");
if (settings.beep_on_error) {
beep();
}
});

let defaultSettings = {
trad_mode: false,
chinese_conversion: false,
Expand All @@ -97,6 +111,7 @@ let defaultSettings = {
letter_mode: "upper",
ctrl_enter_option: 0,
use_jk_key_to_move_cursor: false,
beep_on_error: true,
};
let settings = {};

Expand All @@ -107,6 +122,13 @@ function loadSettings() {
if (!obj) {
return defaultSettings;
}

for (let key in defaultSettings) {
if (!(key in obj)) {
obj[key] = defaultSettings[key];
}
}

return obj;
} catch (e) {}
return defaultSettings;
Expand Down Expand Up @@ -206,6 +228,10 @@ function applySettings(settings) {
document.getElementById("jk_key").checked =
settings.use_jk_key_to_move_cursor;
}
{
document.getElementById("beep_on_error").checked =
settings.use_jk_key_to_move_cursor;
}
{
document.getElementById("move_cursor").checked = settings.move_cursor;
controller.setMoveCursorAfterSelection(settings.move_cursor);
Expand Down Expand Up @@ -420,6 +446,13 @@ document.getElementById("ctrl_enter_option").onchange = function (event) {
document.getElementById("text_area").focus();
};

document.getElementById("beep_on_error").onchange = function (event) {
let value = document.getElementById("beep_on_error").checked;
settings.beep_on_error = value;
saveSettings(settings);
document.getElementById("text_area").focus();
};

document.getElementById("fullscreen").onclick = function (event) {
let elem = document.getElementById("edit_area");
if (elem.requestFullscreen) {
Expand Down
19 changes: 8 additions & 11 deletions src/McBopomofo/InputController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,16 @@ export class InputController {
this.state_ instanceof SelectingDateMacro ||
this.state_ instanceof SelectingDictionary
) {
this.ui_.reset();
this.handleCandidateKeyEvent(
key,
(newState) => this.enterNewState(newState),
(newState) => {
this.enterNewState(newState);
},
() => {
this.onError_?.();
}
);

if (this.state_ instanceof NotEmpty) {
this.updatePreedit(this.state_);
} else {
Expand All @@ -394,11 +396,14 @@ export class InputController {
let accepted = this.keyHandler_.handle(
key,
this.state_,
(newState) => this.enterNewState(newState),
(newState) => {
this.enterNewState(newState);
},
() => {
this.onError_?.();
}
);

if (this.state_ instanceof NotEmpty) {
this.updatePreedit(this.state_);
} else {
Expand All @@ -425,7 +430,6 @@ export class InputController {
let cursor = this.keyHandler_.cursor;
if (cursor === 0) {
errorCallback();
this.enterNewState(this.state_);
return;
}
let newIndex = cursor - 1;
Expand All @@ -442,7 +446,6 @@ export class InputController {
let max = this.keyHandler_.gridLength;
if (cursor >= max) {
errorCallback();
this.enterNewState(this.state_);
return;
}
let newIndex = cursor + 1;
Expand Down Expand Up @@ -722,12 +725,6 @@ export class InputController {
let totalPageCount = this.candidateController_.totalPageCount;
let pageIndex = this.candidateController_.currentPageIndex;
this.ui_.setPageIndex(pageIndex + 1, totalPageCount);

if (state instanceof NotEmpty) {
this.updatePreedit(state);
} else {
this.ui_.update();
}
}

private handleMarking(prev: InputState, state: Marking) {
Expand Down

0 comments on commit 648b99a

Please sign in to comment.