refactor mixed/js/util.js

This commit is contained in:
Alex Yatskov 2017-07-16 12:48:27 -07:00
parent 1ed8997240
commit 516c7f5381
5 changed files with 19 additions and 24 deletions

View File

@ -8,7 +8,7 @@
<script src="/mixed/lib/dexie.min.js"></script>
<script src="/mixed/lib/wanakana.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/util.js"></script>
<script src="/bg/js/anki-connect.js"></script>

View File

@ -34,7 +34,7 @@
<script src="/mixed/lib/jquery.min.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/lib/wanakana.min.js"></script>
<script src="/bg/js/display-window.js"></script>

View File

@ -33,7 +33,7 @@
<script src="/mixed/lib/jquery.min.js"></script>
<script src="/mixed/lib/wanakana.min.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="/fg/js/display-frame.js"></script>
</body>

View File

@ -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
*/

View File

@ -80,7 +80,7 @@ class Display {
if (context) {
for (const definition of definitions) {
if (context.sentence) {
definition.cloze = clozeBuild(context.sentence, definition.source);
definition.cloze = Display.clozeBuild(context.sentence, definition.source);
}
definition.url = context.url;
@ -119,7 +119,7 @@ class Display {
if (context) {
for (const definition of definitions) {
if (context.sentence) {
definition.cloze = clozeBuild(context.sentence);
definition.cloze = Display.clozeBuild(context.sentence);
}
definition.url = context.url;
@ -394,6 +394,20 @@ class Display {
}).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) {
return $('.entry').index(element.closest('.entry'));
}