From 46ed658d8bd4fb916dd4964692aa23dc18c128ca Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Tue, 28 Mar 2017 15:24:52 +0800
Subject: Promisify getStatusBarTemplate method

---
 public/js/lib/editor/index.js | 54 ++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 26 deletions(-)

(limited to 'public/js/lib/editor')

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 () {
-- 
cgit v1.2.3