diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-02-05 16:39:40 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-02-05 16:39:40 -0800 |
commit | 4e3792aba319b52f957c70347e859f677972e4e2 (patch) | |
tree | 3ea382513378f852f2126d1113e21061c61adec8 /ext/fg/js/frame.js | |
parent | 5076b80f9690a12fda23d06b2c3ddd1df08cff56 (diff) |
handle content script and background script desync on version update1.0.9
Diffstat (limited to 'ext/fg/js/frame.js')
-rw-r--r-- | ext/fg/js/frame.js | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js index 66fa131d..dba59000 100644 --- a/ext/fg/js/frame.js +++ b/ext/fg/js/frame.js @@ -44,7 +44,7 @@ class Frame { window.scrollTo(0, 0); renderText(context, 'terms.html').then(content => { - $('.content').html(content); + $('#content').html(content); $('.action-add-note').click(this.onAddNote.bind(this)); $('.kanji-link').click(e => { @@ -59,6 +59,8 @@ class Frame { }); this.updateAddNoteButtons(['term_kanji', 'term_kana'], sequence); + }).catch(error => { + this.handleError(error); }); } @@ -74,13 +76,20 @@ class Frame { window.scrollTo(0, 0); renderText(context, 'kanji.html').then(content => { - $('.content').html(content); + $('#content').html(content); $('.action-add-note').click(this.onAddNote.bind(this)); this.updateAddNoteButtons(['kanji'], sequence); + }).catch(error => { + this.handleError(error); }); } + api_showOrphaned() { + $('#content').hide(); + $('#orphan').show(); + } + findAddNoteButton(index, mode) { return $(`.action-add-note[data-index="${index}"][data-mode="${mode}"]`); } @@ -98,10 +107,10 @@ class Frame { const button = this.findAddNoteButton(index, mode); button.addClass('disabled'); } else { - window.alert('Note could not be added'); + showError('note could not be added'); } }).catch(error => { - window.alert('Error: ' + error); + this.handleError(error); }).then(() => { this.showSpinner(false); }); @@ -129,6 +138,8 @@ class Frame { button.removeClass('pending'); } }); + }).catch(error => { + this.handleError(error); }); } @@ -155,6 +166,14 @@ class Frame { audio.currentTime = 0; audio.play(); } + + handleError(error) { + if (window.orphaned) { + this.api_showOrphaned(); + } else { + showError(error); + } + } } window.frame = new Frame(); |