Browse Source

Add getTitleText method

ihork 8 years ago
parent
commit
ac5cdeded2
3 changed files with 31 additions and 0 deletions
  1. 25
    0
      src/RichTextEditor.js
  2. 4
    0
      src/WebviewMessageHandler.js
  3. 2
    0
      src/const.js

+ 25
- 0
src/RichTextEditor.js View File

85
             }
85
             }
86
           }
86
           }
87
           break;
87
           break;
88
+        case messages.TITLE_TEXT_RESPONSE:
89
+          if (this.titleTextResolve) {
90
+            this.titleTextResolve(message.data);
91
+            this.titleTextResolve = undefined;
92
+            this.titleTextReject = undefined;
93
+            if (this.pendingTitleText) {
94
+              clearTimeout(this.pendingTitleText);
95
+              this.pendingTitleText = undefined;
96
+            }
97
+          }
98
+          break;
88
         case messages.CONTENT_HTML_RESPONSE:
99
         case messages.CONTENT_HTML_RESPONSE:
89
           if (this.contentResolve) {
100
           if (this.contentResolve) {
90
             this.contentResolve(message.data);
101
             this.contentResolve(message.data);
440
     });
451
     });
441
   }
452
   }
442
 
453
 
454
+  async getTitleText() {
455
+    return new Promise((resolve, reject) => {
456
+      this.titleTextResolve = resolve;
457
+      this.titleTextReject = reject;
458
+      this._sendAction(actions.getTitleText);
459
+
460
+      this.pendingTitleText = setTimeout(() => {
461
+        if (this.titleTextReject) {
462
+          this.titleTextReject('timeout');
463
+        }
464
+      }, 5000);
465
+    });
466
+  }
467
+
443
   async getContentHtml() {
468
   async getContentHtml() {
444
     return new Promise((resolve, reject) => {
469
     return new Promise((resolve, reject) => {
445
       this.contentResolve = resolve;
470
       this.contentResolve = resolve;

+ 4
- 0
src/WebviewMessageHandler.js View File

104
           var html = zss_editor.getTitleHTML();
104
           var html = zss_editor.getTitleHTML();
105
           WebViewBridge.send(JSON.stringify({type: '${messages.TITLE_HTML_RESPONSE}', data: html}));
105
           WebViewBridge.send(JSON.stringify({type: '${messages.TITLE_HTML_RESPONSE}', data: html}));
106
           break;
106
           break;
107
+        case '${actions.getTitleText}':
108
+          var html = zss_editor.getTitleText();
109
+          WebViewBridge.send(JSON.stringify({type: '${messages.TITLE_TEXT_RESPONSE}', data: html}));
110
+          break;
107
         case '${actions.getContentHtml}':
111
         case '${actions.getContentHtml}':
108
           var html = zss_editor.getContentHTML();
112
           var html = zss_editor.getContentHTML();
109
           WebViewBridge.send(JSON.stringify({type: '${messages.CONTENT_HTML_RESPONSE}', data: html}));
113
           WebViewBridge.send(JSON.stringify({type: '${messages.CONTENT_HTML_RESPONSE}', data: html}));

+ 2
- 0
src/const.js View File

2
   setTitleHtml: 'SET_TITLE_HTML',
2
   setTitleHtml: 'SET_TITLE_HTML',
3
   setContentHtml: 'SET_CONTENT_HTML',
3
   setContentHtml: 'SET_CONTENT_HTML',
4
   getTitleHtml: 'GET_TITLE_HTML',
4
   getTitleHtml: 'GET_TITLE_HTML',
5
+  getTitleText: 'GET_TITLE_TEXT',
5
   getContentHtml: 'GET_CONTENT_HTML',
6
   getContentHtml: 'GET_CONTENT_HTML',
6
   blurTitleEditor: 'BLUR_TITLE_EDITOR',
7
   blurTitleEditor: 'BLUR_TITLE_EDITOR',
7
   blurContentEditor: 'BLUR_CONTENT_EDITOR',
8
   blurContentEditor: 'BLUR_CONTENT_EDITOR',
48
 
49
 
49
 export const messages = {
50
 export const messages = {
50
   TITLE_HTML_RESPONSE: 'TITLE_HTML_RESPONSE',
51
   TITLE_HTML_RESPONSE: 'TITLE_HTML_RESPONSE',
52
+  TITLE_TEXT_RESPONSE: 'TITLE_TEXT_RESPONSE',
51
   CONTENT_HTML_RESPONSE: 'CONTENT_HTML_RESPONSE',
53
   CONTENT_HTML_RESPONSE: 'CONTENT_HTML_RESPONSE',
52
   ZSS_INITIALIZED: 'ZSS_INITIALIZED',
54
   ZSS_INITIALIZED: 'ZSS_INITIALIZED',
53
   SCROLL: 'SCROLL',
55
   SCROLL: 'SCROLL',