diff options
author | Yukai Huang | 2017-03-28 15:24:52 +0800 |
---|---|---|
committer | Yukai Huang | 2017-03-28 15:24:52 +0800 |
commit | 46ed658d8bd4fb916dd4964692aa23dc18c128ca (patch) | |
tree | 4b102e95bc6baf17a2e3786b1efa2b1d2170cb33 /public | |
parent | af5ef52f4b3f77326a97cf733f6bdb680d14f927 (diff) |
Promisify getStatusBarTemplate method
Diffstat (limited to '')
-rw-r--r-- | public/js/lib/editor/index.js | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/public/js/lib/editor/index.js b/public/js/lib/editor/index.js index 6eec34ad..a68092ff 100644 --- a/public/js/lib/editor/index.js +++ b/public/js/lib/editor/index.js @@ -131,38 +131,40 @@ export default class Editor { }) } - getStatusBarTemplate (callback) { - $.get(window.serverurl + '/views/statusbar.html', template => { - this.statusBarTemplate = template - if (callback) callback() + getStatusBarTemplate () { + return new Promise((resolve, reject) => { + $.get(window.serverurl + '/views/statusbar.html').done(template => { + this.statusBarTemplate = template + resolve() + }).fail(reject) }) } addStatusBar () { if (!this.statusBarTemplate) { - this.getStatusBarTemplate(this.addStatusBar) - return - } - this.statusBar = $(this.statusBarTemplate) - this.statusCursor = this.statusBar.find('.status-cursor > .status-line-column') - this.statusSelection = this.statusBar.find('.status-cursor > .status-selection') - this.statusFile = this.statusBar.find('.status-file') - this.statusIndicators = this.statusBar.find('.status-indicators') - this.statusIndent = this.statusBar.find('.status-indent') - this.statusKeymap = this.statusBar.find('.status-keymap') - this.statusLength = this.statusBar.find('.status-length') - this.statusTheme = this.statusBar.find('.status-theme') - this.statusSpellcheck = this.statusBar.find('.status-spellcheck') - this.statusPreferences = this.statusBar.find('.status-preferences') - this.statusPanel = this.editor.addPanel(this.statusBar[0], { - position: 'bottom' - }) + this.getStatusBarTemplate.then(this.addStatusBar) + } else { + this.statusBar = $(this.statusBarTemplate) + this.statusCursor = this.statusBar.find('.status-cursor > .status-line-column') + this.statusSelection = this.statusBar.find('.status-cursor > .status-selection') + this.statusFile = this.statusBar.find('.status-file') + this.statusIndicators = this.statusBar.find('.status-indicators') + this.statusIndent = this.statusBar.find('.status-indent') + this.statusKeymap = this.statusBar.find('.status-keymap') + this.statusLength = this.statusBar.find('.status-length') + this.statusTheme = this.statusBar.find('.status-theme') + this.statusSpellcheck = this.statusBar.find('.status-spellcheck') + this.statusPreferences = this.statusBar.find('.status-preferences') + this.statusPanel = this.editor.addPanel(this.statusBar[0], { + position: 'bottom' + }) - this.setIndent() - this.setKeymap() - this.setTheme() - this.setSpellcheck() - this.setPreferences() + this.setIndent() + this.setKeymap() + this.setTheme() + this.setSpellcheck() + this.setPreferences() + } } setIndent () { |