Няма описание

WebviewMessageHandler.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import {actions, messages} from './const';
  2. export const InjectedMessageHandler = `
  3. if (WebViewBridge) {
  4. WebViewBridge.onMessage = function (message) {
  5. console.log(message)
  6. const action = JSON.parse(message);
  7. switch(action.type) {
  8. case '${actions.enableOnChange}':
  9. zss_editor.enableOnChange();
  10. break;
  11. case '${actions.setTitleHtml}':
  12. zss_editor.setTitleHTML(action.data);
  13. break;
  14. case '${actions.toggleTitle}':
  15. zss_editor.toggleTitle(action.data);
  16. break;
  17. case '${actions.hideTitle}':
  18. zss_editor.hideTitle(action.data);
  19. break;
  20. case '${actions.showTitle}':
  21. zss_editor.showTitle(action.data);
  22. break;
  23. case '${actions.setContentHtml}':
  24. zss_editor.setContentHTML(action.data);
  25. break;
  26. case '${actions.blurTitleEditor}':
  27. zss_editor.blurTitleEditor();
  28. break;
  29. case '${actions.blurContentEditor}':
  30. zss_editor.blurContentEditor();
  31. break;
  32. case '${actions.setBold}':
  33. zss_editor.setBold();
  34. window.wixRichTextInstance.execCommand('bold');
  35. break;
  36. case '${actions.setItalic}':
  37. zss_editor.setItalic();
  38. window.wixRichTextInstance.execCommand('italic');
  39. break;
  40. case '${actions.setUnderline}':
  41. zss_editor.setUnderline();
  42. window.wixRichTextInstance.execCommand('underline');
  43. break;
  44. case '${actions.heading1}':
  45. zss_editor.setHeading('h1');
  46. break;
  47. case '${actions.heading2}':
  48. zss_editor.setHeading('h2');
  49. break;
  50. case '${actions.heading3}':
  51. zss_editor.setHeading('h3');
  52. break;
  53. case '${actions.heading4}':
  54. zss_editor.setHeading('h4');
  55. break;
  56. case '${actions.heading5}':
  57. zss_editor.setHeading('h5');
  58. break;
  59. case '${actions.heading6}':
  60. zss_editor.setHeading('h6');
  61. break;
  62. case '${actions.setParagraph}':
  63. zss_editor.setParagraph();
  64. break;
  65. case '${actions.removeFormat}':
  66. zss_editor.removeFormating();
  67. break;
  68. case '${actions.alignLeft}':
  69. zss_editor.setJustifyLeft();
  70. break;
  71. case '${actions.alignCenter}':
  72. zss_editor.setJustifyCenter();
  73. break;
  74. case '${actions.alignRight}':
  75. zss_editor.setJustifyRight();
  76. break;
  77. case '${actions.alignFull}':
  78. zss_editor.setJustifyFull();
  79. break;
  80. case '${actions.insertBulletsList}':
  81. zss_editor.setUnorderedList();
  82. window.wixRichTextInstance.execCommand('bulletedlist');
  83. break;
  84. case '${actions.insertOrderedList}':
  85. zss_editor.setOrderedList();
  86. window.wixRichTextInstance.execCommand('numberedlist');
  87. break;
  88. case '${actions.insertLink}':
  89. zss_editor.insertLink(action.data.url, action.data.title);
  90. break;
  91. case '${actions.updateLink}':
  92. zss_editor.updateLink(action.data.url, action.data.title);
  93. break;
  94. case '${actions.insertImage}':
  95. zss_editor.insertImage(action.data);
  96. break;
  97. case '${actions.setSubscript}':
  98. zss_editor.setSubscript();
  99. break;
  100. case '${actions.setSuperscript}':
  101. zss_editor.setSuperscript();
  102. break;
  103. case '${actions.setStrikethrough}':
  104. zss_editor.setStrikeThrough();
  105. break;
  106. case '${actions.setHR}':
  107. zss_editor.setHorizontalRule();
  108. break;
  109. case '${actions.setIndent}':
  110. zss_editor.setIndent();
  111. break;
  112. case '${actions.setOutdent}':
  113. zss_editor.setOutdent();
  114. break;
  115. case '${actions.setTitlePlaceholder}':
  116. zss_editor.setTitlePlaceholder(action.data);
  117. break;
  118. case '${actions.setContentPlaceholder}':
  119. zss_editor.setContentPlaceholder(action.data);
  120. break;
  121. case '${actions.getTitleHtml}':
  122. var html = zss_editor.getTitleHTML();
  123. WebViewBridge.send(JSON.stringify({type: '${messages.TITLE_HTML_RESPONSE}', data: html}));
  124. break;
  125. case '${actions.getTitleText}':
  126. var html = zss_editor.getTitleText();
  127. WebViewBridge.send(JSON.stringify({type: '${messages.TITLE_TEXT_RESPONSE}', data: html}));
  128. break;
  129. case '${actions.getContentHtml}':
  130. var html = zss_editor.getContentHTML();
  131. WebViewBridge.send(JSON.stringify({type: '${messages.CONTENT_HTML_RESPONSE}', data: html}));
  132. break;
  133. case '${actions.setTitleFocusHandler}':
  134. zss_editor.setTitleFocusHandler();
  135. break;
  136. case '${actions.setContentFocusHandler}':
  137. zss_editor.setContentFocusHandler();
  138. break;
  139. case '${actions.getSelectedText}':
  140. var selectedText = getSelection().toString();
  141. WebViewBridge.send(JSON.stringify({type: '${messages.SELECTED_TEXT_RESPONSE}', data: selectedText}));
  142. break;
  143. case '${actions.focusContent}':
  144. zss_editor.focusContent();
  145. break;
  146. case '${actions.focusTitle}':
  147. zss_editor.focusTitle();
  148. break;
  149. case '${actions.prepareInsert}':
  150. zss_editor.prepareInsert();
  151. break;
  152. case '${actions.restoreSelection}':
  153. zss_editor.restorerange();
  154. break;
  155. case '${actions.setCustomCSS}':
  156. zss_editor.setCustomCSS(action.data);
  157. break;
  158. case '${actions.setTextColor}':
  159. zss_editor.setTextColor(action.data);
  160. break;
  161. case '${actions.setBackgroundColor}':
  162. zss_editor.setBackgroundColor(action.data);
  163. break;
  164. case '${actions.init}':
  165. zss_editor.init();
  166. break;
  167. case '${actions.setEditorHeight}':
  168. zss_editor.setEditorHeight(action.data);
  169. break;
  170. case '${actions.setFooterHeight}':
  171. zss_editor.setFooterHeight(action.data);
  172. break;
  173. case '${actions.setPlatform}':
  174. zss_editor.setPlatform(action.data);
  175. break;
  176. }
  177. };
  178. }
  179. `;