mirror of
https://github.com/skishore/makemeahanzi.git
synced 2025-10-28 04:55:56 +08:00
Move character lookup to a library
This commit is contained in:
@ -76,20 +76,8 @@ const refreshMetadata = (row) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const updateCharacter = () => {
|
const updateCharacter = () => {
|
||||||
const value = character.get();
|
makemeahanzi.lookupCharacter(character.get(), (row) => {
|
||||||
if (value == null) {
|
if (row.character === character.get()) refreshMetadata(row); });
|
||||||
return;
|
|
||||||
}
|
|
||||||
const part = Math.floor(value.charCodeAt(0) / 256);
|
|
||||||
$.get(`characters/part-${part}.txt`, (response, code) => {
|
|
||||||
if (code !== 'success') throw new Error(code);
|
|
||||||
const data = JSON.parse(response);
|
|
||||||
for (let row of data) {
|
|
||||||
if (row.character === character.get()) {
|
|
||||||
refreshMetadata(row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods for running the stroke-order animation.
|
// Methods for running the stroke-order animation.
|
||||||
|
|||||||
13
lib/character.js
Normal file
13
lib/character.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
this.makemeahanzi.lookupCharacter = (character, callback) => {
|
||||||
|
if (!character) return;
|
||||||
|
const part = Math.floor(character.charCodeAt(0) / 256);
|
||||||
|
$.get(`characters/part-${part}.txt`, (response, code) => {
|
||||||
|
if (code !== 'success') throw new Error(code);
|
||||||
|
const data = JSON.parse(response);
|
||||||
|
for (let row of data) {
|
||||||
|
if (row.character === character) {
|
||||||
|
callback(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user