暫無描述

WebviewMessageHandler.js 5.2KB

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