refactor mixed/js/util.js
This commit is contained in:
parent
1ed8997240
commit
516c7f5381
@ -8,7 +8,7 @@
|
|||||||
<script src="/mixed/lib/dexie.min.js"></script>
|
<script src="/mixed/lib/dexie.min.js"></script>
|
||||||
<script src="/mixed/lib/wanakana.min.js"></script>
|
<script src="/mixed/lib/wanakana.min.js"></script>
|
||||||
<script src="/mixed/lib/jszip.min.js"></script>
|
<script src="/mixed/lib/jszip.min.js"></script>
|
||||||
<script src="/mixed/js/util.js"></script>
|
<script src="/mixed/js/audio.js"></script>
|
||||||
<script src="/bg/js/templates.js"></script>
|
<script src="/bg/js/templates.js"></script>
|
||||||
<script src="/bg/js/util.js"></script>
|
<script src="/bg/js/util.js"></script>
|
||||||
<script src="/bg/js/anki-connect.js"></script>
|
<script src="/bg/js/anki-connect.js"></script>
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
<script src="/mixed/lib/jquery.min.js"></script>
|
<script src="/mixed/lib/jquery.min.js"></script>
|
||||||
<script src="/bg/js/util.js"></script>
|
<script src="/bg/js/util.js"></script>
|
||||||
<script src="/mixed/js/util.js"></script>
|
<script src="/mixed/js/audio.js"></script>
|
||||||
<script src="/mixed/js/display.js"></script>
|
<script src="/mixed/js/display.js"></script>
|
||||||
<script src="/mixed/lib/wanakana.min.js"></script>
|
<script src="/mixed/lib/wanakana.min.js"></script>
|
||||||
<script src="/bg/js/display-window.js"></script>
|
<script src="/bg/js/display-window.js"></script>
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
<script src="/mixed/lib/jquery.min.js"></script>
|
<script src="/mixed/lib/jquery.min.js"></script>
|
||||||
<script src="/mixed/lib/wanakana.min.js"></script>
|
<script src="/mixed/lib/wanakana.min.js"></script>
|
||||||
<script src="/fg/js/util.js"></script>
|
<script src="/fg/js/util.js"></script>
|
||||||
<script src="/mixed/js/util.js"></script>
|
<script src="/mixed/js/audio.js"></script>
|
||||||
<script src="/mixed/js/display.js"></script>
|
<script src="/mixed/js/display.js"></script>
|
||||||
<script src="/fg/js/display-frame.js"></script>
|
<script src="/fg/js/display-frame.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -17,25 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Cloze
|
|
||||||
*/
|
|
||||||
|
|
||||||
function clozeBuild(sentence, source) {
|
|
||||||
const result = {
|
|
||||||
sentence: sentence.text.trim()
|
|
||||||
};
|
|
||||||
|
|
||||||
if (source) {
|
|
||||||
result.prefix = sentence.text.substring(0, sentence.offset).trim();
|
|
||||||
result.body = source.trim();
|
|
||||||
result.suffix = sentence.text.substring(sentence.offset + source.length).trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Audio
|
* Audio
|
||||||
*/
|
*/
|
@ -80,7 +80,7 @@ class Display {
|
|||||||
if (context) {
|
if (context) {
|
||||||
for (const definition of definitions) {
|
for (const definition of definitions) {
|
||||||
if (context.sentence) {
|
if (context.sentence) {
|
||||||
definition.cloze = clozeBuild(context.sentence, definition.source);
|
definition.cloze = Display.clozeBuild(context.sentence, definition.source);
|
||||||
}
|
}
|
||||||
|
|
||||||
definition.url = context.url;
|
definition.url = context.url;
|
||||||
@ -119,7 +119,7 @@ class Display {
|
|||||||
if (context) {
|
if (context) {
|
||||||
for (const definition of definitions) {
|
for (const definition of definitions) {
|
||||||
if (context.sentence) {
|
if (context.sentence) {
|
||||||
definition.cloze = clozeBuild(context.sentence);
|
definition.cloze = Display.clozeBuild(context.sentence);
|
||||||
}
|
}
|
||||||
|
|
||||||
definition.url = context.url;
|
definition.url = context.url;
|
||||||
@ -394,6 +394,20 @@ class Display {
|
|||||||
}).catch(this.handleError.bind(this)).then(() => this.spinner.hide());
|
}).catch(this.handleError.bind(this)).then(() => this.spinner.hide());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static clozeBuild(sentence, source) {
|
||||||
|
const result = {
|
||||||
|
sentence: sentence.text.trim()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (source) {
|
||||||
|
result.prefix = sentence.text.substring(0, sentence.offset).trim();
|
||||||
|
result.body = source.trim();
|
||||||
|
result.suffix = sentence.text.substring(sentence.offset + source.length).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static entryIndexFind(element) {
|
static entryIndexFind(element) {
|
||||||
return $('.entry').index(element.closest('.entry'));
|
return $('.entry').index(element.closest('.entry'));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user