Skip to content

Commit 78e5636

Browse files
authored
Merge pull request wix-incubator#4 from wix/onChangeContent
onChange content listeners; toggle, hide and show methods for title
2 parents e58d462 + 0cc8248 commit 78e5636

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

src/RichTextEditor.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export default class RichTextEditor extends Component {
1919
titlePlaceholder: PropTypes.string,
2020
contentPlaceholder: PropTypes.string,
2121
editorInitializedCallback: PropTypes.func,
22-
customCSS: PropTypes.string
22+
customCSS: PropTypes.string,
23+
hiddenTitle: PropTypes.bool,
24+
enableOnChange: PropTypes.bool
2325
};
2426

2527
constructor(props) {
@@ -31,6 +33,7 @@ export default class RichTextEditor extends Component {
3133
this._onKeyboardWillHide = this._onKeyboardWillHide.bind(this);
3234
this.state = {
3335
listeners: [],
36+
onChange: [],
3437
showLinkDialog: false,
3538
linkInitialUrl: '',
3639
linkTitle: '',
@@ -127,6 +130,10 @@ export default class RichTextEditor extends Component {
127130
this.setContentPlaceholder(this.props.contentPlaceholder);
128131
this.setTitleHTML(this.props.initialTitleHTML);
129132
this.setContentHTML(this.props.initialContentHTML);
133+
134+
this.props.hiddenTitle && this.hideTitle();
135+
this.props.enableOnChange && this.enableOnChange();
136+
130137
this.props.editorInitializedCallback && this.props.editorInitializedCallback();
131138

132139
break;
@@ -151,6 +158,10 @@ export default class RichTextEditor extends Component {
151158
const items = message.data.items;
152159
this.state.listeners.map((listener) => listener(items));
153160
break
161+
case messages.CONTENT_CHANGE:
162+
const content = message.data.content;
163+
this.state.onChange.map((listener) => listener(content));
164+
break
154165
}
155166
} catch(e) {
156167
//alert('NON JSON MESSAGE');
@@ -311,11 +322,29 @@ export default class RichTextEditor extends Component {
311322
listeners: [...this.state.listeners, listener]
312323
});
313324
}
325+
326+
enableOnChange() {
327+
this._sendAction(actions.enableOnChange);
328+
}
329+
330+
registerContentChangeListener(listener) {
331+
this.setState({
332+
onChange: [...this.state.onChange, listener]
333+
});
334+
}
314335

315336
setTitleHTML(html) {
316337
this._sendAction(actions.setTitleHtml, html);
317338
}
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+
}
319348
setContentHTML(html) {
320349
this._sendAction(actions.setContentHtml, html);
321350
}

src/WebviewMessageHandler.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@ export const InjectedMessageHandler = `
77
const action = JSON.parse(message);
88
99
switch(action.type) {
10+
case '${actions.enableOnChange}':
11+
zss_editor.enableOnChange();
12+
break;
1013
case '${actions.setTitleHtml}':
1114
zss_editor.setTitleHTML(action.data);
1215
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;
1325
case '${actions.setContentHtml}':
1426
zss_editor.setContentHTML(action.data);
1527
break;

src/const.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
export const actions = {
2+
enableOnChange: 'ENABLE_ON_CHANGE',
23
setTitleHtml: 'SET_TITLE_HTML',
34
setContentHtml: 'SET_CONTENT_HTML',
45
getTitleHtml: 'GET_TITLE_HTML',
56
getTitleText: 'GET_TITLE_TEXT',
7+
toggleTitle: 'TOGGLE_TITLE',
8+
hideTitle: 'HIDE_TITLE',
9+
showTitle: 'SHOW_TITLE',
610
getContentHtml: 'GET_CONTENT_HTML',
711
getSelectedText: 'GET_SELECTED_TEXT',
812
blurTitleEditor: 'BLUR_TITLE_EDITOR',
@@ -59,6 +63,7 @@ export const messages = {
5963
TITLE_FOCUSED: 'TITLE_FOCUSED',
6064
CONTENT_FOCUSED: 'CONTENT_FOCUSED',
6165
SELECTION_CHANGE: 'SELECTION_CHANGE',
66+
CONTENT_CHANGE: 'CONTENT_CHANGE',
6267
SELECTED_TEXT_RESPONSE: 'SELECTED_TEXT_RESPONSE',
6368
LINK_TOUCHED: 'LINK_TOUCHED'
6469
};

src/editor.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,30 @@
13521352
setHTML('zss_editor_title', html);
13531353
}
13541354

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+
13551379
zss_editor.setContentHTML = function(html) {
13561380
setHTML('zss_editor_content', html);
13571381
}

0 commit comments

Comments
 (0)