diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-07-16 12:48:27 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-07-16 12:48:27 -0700 |
commit | 516c7f5381700700dcfdfb06682f11de8205137b (patch) | |
tree | c8d15b000dfdd6ba066a0de6c517229865177d24 /ext/mixed | |
parent | 1ed8997240ba5d8ee4fe57062d2dbe8ba46436e2 (diff) |
refactor mixed/js/util.js
Diffstat (limited to 'ext/mixed')
-rw-r--r-- | ext/mixed/js/audio.js (renamed from ext/mixed/js/util.js) | 19 | ||||
-rw-r--r-- | ext/mixed/js/display.js | 18 |
2 files changed, 16 insertions, 21 deletions
diff --git a/ext/mixed/js/util.js b/ext/mixed/js/audio.js index 0a8c914d..451fe1d9 100644 --- a/ext/mixed/js/util.js +++ b/ext/mixed/js/audio.js @@ -18,25 +18,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 */ diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index da0cd351..e54bc0f9 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -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')); } |