Просмотр исходного кода

onChange content listeners; toggle, hide and show methods for title

alexk wix 8 лет назад
Родитель
Сommit
0cc8248684
4 измененных файлов: 72 добавлений и 2 удалений
  1. 31
    2
      src/RichTextEditor.js
  2. 12
    0
      src/WebviewMessageHandler.js
  3. 5
    0
      src/const.js
  4. 24
    0
      src/editor.html

+ 31
- 2
src/RichTextEditor.js Просмотреть файл

@@ -19,7 +19,9 @@ export default class RichTextEditor extends Component {
19 19
     titlePlaceholder: PropTypes.string,
20 20
     contentPlaceholder: PropTypes.string,
21 21
     editorInitializedCallback: PropTypes.func,
22
-    customCSS: PropTypes.string
22
+    customCSS: PropTypes.string,
23
+    hiddenTitle: PropTypes.bool,
24
+    enableOnChange: PropTypes.bool
23 25
   };
24 26
 
25 27
   constructor(props) {
@@ -31,6 +33,7 @@ export default class RichTextEditor extends Component {
31 33
     this._onKeyboardWillHide = this._onKeyboardWillHide.bind(this);
32 34
     this.state = {
33 35
       listeners: [],
36
+      onChange: [],
34 37
       showLinkDialog: false,
35 38
       linkInitialUrl: '',
36 39
       linkTitle: '',
@@ -127,6 +130,10 @@ export default class RichTextEditor extends Component {
127 130
           this.setContentPlaceholder(this.props.contentPlaceholder);
128 131
           this.setTitleHTML(this.props.initialTitleHTML);
129 132
           this.setContentHTML(this.props.initialContentHTML);
133
+
134
+          this.props.hiddenTitle && this.hideTitle();
135
+          this.props.enableOnChange && this.enableOnChange();
136
+
130 137
           this.props.editorInitializedCallback && this.props.editorInitializedCallback();
131 138
 
132 139
           break;
@@ -151,6 +158,10 @@ export default class RichTextEditor extends Component {
151 158
           const items = message.data.items;
152 159
           this.state.listeners.map((listener) => listener(items));
153 160
           break
161
+        case messages.CONTENT_CHANGE:
162
+          const content = message.data.content;
163
+          this.state.onChange.map((listener) => listener(content));
164
+          break
154 165
       }
155 166
     } catch(e) {
156 167
       //alert('NON JSON MESSAGE');
@@ -311,11 +322,29 @@ export default class RichTextEditor extends Component {
311 322
       listeners: [...this.state.listeners, listener]
312 323
     });
313 324
   }
325
+  
326
+  enableOnChange() {
327
+    this._sendAction(actions.enableOnChange);
328
+  }
329
+
330
+  registerContentChangeListener(listener) {
331
+    this.setState({
332
+      onChange: [...this.state.onChange, listener]
333
+    });
334
+  }
314 335
 
315 336
   setTitleHTML(html) {
316 337
     this._sendAction(actions.setTitleHtml, html);
317 338
   }
318
-
339
+  hideTitle() {
340
+    this._sendAction(actions.hideTitle);
341
+  }
342
+  showTitle() {
343
+    this._sendAction(actions.showTitle);
344
+  }
345
+  toggleTitle() {
346
+    this._sendAction(actions.toggleTitle);
347
+  }
319 348
   setContentHTML(html) {
320 349
     this._sendAction(actions.setContentHtml, html);
321 350
   }

+ 12
- 0
src/WebviewMessageHandler.js Просмотреть файл

@@ -7,9 +7,21 @@ export const InjectedMessageHandler = `
7 7
       const action = JSON.parse(message);
8 8
 
9 9
       switch(action.type) {
10
+        case '${actions.enableOnChange}':
11
+          zss_editor.enableOnChange();
12
+          break;
10 13
         case '${actions.setTitleHtml}':
11 14
           zss_editor.setTitleHTML(action.data);
12 15
           break;
16
+        case '${actions.toggleTitle}':
17
+          zss_editor.toggleTitle(action.data);
18
+          break;
19
+        case '${actions.hideTitle}':
20
+          zss_editor.hideTitle(action.data);
21
+          break;
22
+        case '${actions.showTitle}':
23
+          zss_editor.showTitle(action.data);
24
+          break;
13 25
         case '${actions.setContentHtml}':
14 26
           zss_editor.setContentHTML(action.data);
15 27
           break;

+ 5
- 0
src/const.js Просмотреть файл

@@ -1,8 +1,12 @@
1 1
 export const actions = {
2
+  enableOnChange: 'ENABLE_ON_CHANGE',
2 3
   setTitleHtml: 'SET_TITLE_HTML',
3 4
   setContentHtml: 'SET_CONTENT_HTML',
4 5
   getTitleHtml: 'GET_TITLE_HTML',
5 6
   getTitleText: 'GET_TITLE_TEXT',
7
+  toggleTitle: 'TOGGLE_TITLE',
8
+  hideTitle: 'HIDE_TITLE',
9
+  showTitle: 'SHOW_TITLE',
6 10
   getContentHtml: 'GET_CONTENT_HTML',
7 11
   getSelectedText: 'GET_SELECTED_TEXT',
8 12
   blurTitleEditor: 'BLUR_TITLE_EDITOR',
@@ -59,6 +63,7 @@ export const messages = {
59 63
   TITLE_FOCUSED: 'TITLE_FOCUSED',
60 64
   CONTENT_FOCUSED: 'CONTENT_FOCUSED',
61 65
   SELECTION_CHANGE: 'SELECTION_CHANGE',
66
+  CONTENT_CHANGE: 'CONTENT_CHANGE',
62 67
   SELECTED_TEXT_RESPONSE: 'SELECTED_TEXT_RESPONSE',
63 68
   LINK_TOUCHED: 'LINK_TOUCHED'
64 69
 };

+ 24
- 0
src/editor.html Просмотреть файл

@@ -1352,6 +1352,30 @@
1352 1352
 				setHTML('zss_editor_title', html);
1353 1353
 			}
1354 1354
 
1355
+			zss_editor.toggleTitle = function() {
1356
+				$('#zss_editor_title').toggle();
1357
+				$('#separatorContainer').toggle();
1358
+			}
1359
+
1360
+			zss_editor.enableOnChange = function() {
1361
+				$('#zss_editor_content').on('input', function(){
1362
+					WebViewBridge.send(JSON.stringify({
1363
+						type: 'CONTENT_CHANGE',
1364
+						data: {content: getHtml("zss_editor_content")}
1365
+					}))
1366
+				});
1367
+			}
1368
+
1369
+			zss_editor.hideTitle = function() {
1370
+				$('#zss_editor_title').hide();
1371
+				$('#separatorContainer').hide();
1372
+			}
1373
+
1374
+			zss_editor.showTitle = function() {
1375
+				$('#zss_editor_title').show();
1376
+				$('#separatorContainer').show();
1377
+			}
1378
+
1355 1379
 			zss_editor.setContentHTML = function(html) {
1356 1380
 				setHTML('zss_editor_content', html);
1357 1381
 			}