ZSSRichTextEditor.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //
  2. // ZSSRichTextEditorViewController.h
  3. // ZSSRichTextEditor
  4. //
  5. // Created by Nicholas Hubbard on 11/30/13.
  6. // Copyright (c) 2013 Zed Said Studio. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import <WebKit/WebKit.h>
  10. #import "HRColorPickerViewController.h"
  11. #import "ZSSFontsViewController.h"
  12. /**
  13. * The types of toolbar items that can be added
  14. */
  15. static NSString * const ZSSRichTextEditorToolbarBold = @"com.zedsaid.toolbaritem.bold";
  16. static NSString * const ZSSRichTextEditorToolbarItalic = @"com.zedsaid.toolbaritem.italic";
  17. static NSString * const ZSSRichTextEditorToolbarSubscript = @"com.zedsaid.toolbaritem.subscript";
  18. static NSString * const ZSSRichTextEditorToolbarSuperscript = @"com.zedsaid.toolbaritem.superscript";
  19. static NSString * const ZSSRichTextEditorToolbarStrikeThrough = @"com.zedsaid.toolbaritem.strikeThrough";
  20. static NSString * const ZSSRichTextEditorToolbarUnderline = @"com.zedsaid.toolbaritem.underline";
  21. static NSString * const ZSSRichTextEditorToolbarRemoveFormat = @"com.zedsaid.toolbaritem.removeFormat";
  22. static NSString * const ZSSRichTextEditorToolbarJustifyLeft = @"com.zedsaid.toolbaritem.justifyLeft";
  23. static NSString * const ZSSRichTextEditorToolbarJustifyCenter = @"com.zedsaid.toolbaritem.justifyCenter";
  24. static NSString * const ZSSRichTextEditorToolbarJustifyRight = @"com.zedsaid.toolbaritem.justifyRight";
  25. static NSString * const ZSSRichTextEditorToolbarJustifyFull = @"com.zedsaid.toolbaritem.justifyFull";
  26. static NSString * const ZSSRichTextEditorToolbarH1 = @"com.zedsaid.toolbaritem.h1";
  27. static NSString * const ZSSRichTextEditorToolbarH2 = @"com.zedsaid.toolbaritem.h2";
  28. static NSString * const ZSSRichTextEditorToolbarH3 = @"com.zedsaid.toolbaritem.h3";
  29. static NSString * const ZSSRichTextEditorToolbarH4 = @"com.zedsaid.toolbaritem.h4";
  30. static NSString * const ZSSRichTextEditorToolbarH5 = @"com.zedsaid.toolbaritem.h5";
  31. static NSString * const ZSSRichTextEditorToolbarH6 = @"com.zedsaid.toolbaritem.h6";
  32. static NSString * const ZSSRichTextEditorToolbarTextColor = @"com.zedsaid.toolbaritem.textColor";
  33. static NSString * const ZSSRichTextEditorToolbarBackgroundColor = @"com.zedsaid.toolbaritem.backgroundColor";
  34. static NSString * const ZSSRichTextEditorToolbarUnorderedList = @"com.zedsaid.toolbaritem.unorderedList";
  35. static NSString * const ZSSRichTextEditorToolbarOrderedList = @"com.zedsaid.toolbaritem.orderedList";
  36. static NSString * const ZSSRichTextEditorToolbarHorizontalRule = @"com.zedsaid.toolbaritem.horizontalRule";
  37. static NSString * const ZSSRichTextEditorToolbarIndent = @"com.zedsaid.toolbaritem.indent";
  38. static NSString * const ZSSRichTextEditorToolbarOutdent = @"com.zedsaid.toolbaritem.outdent";
  39. static NSString * const ZSSRichTextEditorToolbarInsertImage = @"com.zedsaid.toolbaritem.insertImage";
  40. static NSString * const ZSSRichTextEditorToolbarInsertImageFromDevice = @"com.zedsaid.toolbaritem.insertImageFromDevice";
  41. static NSString * const ZSSRichTextEditorToolbarInsertLink = @"com.zedsaid.toolbaritem.insertLink";
  42. static NSString * const ZSSRichTextEditorToolbarRemoveLink = @"com.zedsaid.toolbaritem.removeLink";
  43. static NSString * const ZSSRichTextEditorToolbarQuickLink = @"com.zedsaid.toolbaritem.quickLink";
  44. static NSString * const ZSSRichTextEditorToolbarUndo = @"com.zedsaid.toolbaritem.undo";
  45. static NSString * const ZSSRichTextEditorToolbarRedo = @"com.zedsaid.toolbaritem.redo";
  46. static NSString * const ZSSRichTextEditorToolbarViewSource = @"com.zedsaid.toolbaritem.viewSource";
  47. static NSString * const ZSSRichTextEditorToolbarParagraph = @"com.zedsaid.toolbaritem.paragraph";
  48. static NSString * const ZSSRichTextEditorToolbarAll = @"com.zedsaid.toolbaritem.all";
  49. static NSString * const ZSSRichTextEditorToolbarNone = @"com.zedsaid.toolbaritem.none";
  50. static NSString * const ZSSRichTextEditorToolbarFonts = @"com.zedsaid.toolbaritem.fonts";
  51. // source string for parsing JSON
  52. static NSString * const ZSSEditorHTML = @"zss_editor.getHTML();";
  53. static NSString * const ZSSEditorText = @"zss_editor.getText();";
  54. static NSString * const ZSSEditorContent = @"document.activeElement.id=='zss_editor_content'";
  55. @class ZSSBarButtonItem;
  56. /**
  57. * The viewController used with ZSSRichTextEditor
  58. */
  59. @interface ZSSRichTextEditor : UIViewController <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, HRColorPickerViewControllerDelegate, UITextViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate,ZSSFontsViewControllerDelegate>
  60. /**
  61. * The base URL to use for the webView
  62. */
  63. @property (nonatomic, strong) NSURL *baseURL;
  64. /**
  65. * If the HTML should be formatted to be pretty
  66. */
  67. @property (nonatomic) BOOL formatHTML;
  68. /**
  69. * If the keyboard should be shown when the editor loads
  70. */
  71. @property (nonatomic) BOOL shouldShowKeyboard;
  72. /**
  73. * If the toolbar should always be shown or not
  74. */
  75. @property (nonatomic) BOOL alwaysShowToolbar;
  76. /**
  77. * If the sub class recieves text did change events or not
  78. */
  79. @property (nonatomic) BOOL receiveEditorDidChangeEvents;
  80. /**
  81. * The placeholder text to use if there is no editor content
  82. */
  83. @property (nonatomic, strong) NSString *placeholder;
  84. /**
  85. * Toolbar items to include
  86. */
  87. @property (nonatomic, strong) NSArray *enabledToolbarItems;
  88. /**
  89. * Color to tint the toolbar items
  90. */
  91. @property (nonatomic, strong) UIColor *toolbarItemTintColor;
  92. /**
  93. * Color to tint selected items
  94. */
  95. @property (nonatomic, strong) UIColor *toolbarItemSelectedTintColor;
  96. /**
  97. * Sets the HTML for the entire editor
  98. *
  99. * @param html HTML string to set for the editor
  100. *
  101. */
  102. - (void)setHTML:(NSString *)html;
  103. /**
  104. * Returns the HTML from the Rich Text Editor
  105. *
  106. */
  107. - (void)getHTML:(void (^ _Nullable)(_Nullable id, NSError * _Nullable error))completionHandler;
  108. /**
  109. * Returns the plain text from the Rich Text Editor
  110. *
  111. */
  112. - (void)getText:(void (^ _Nullable)(_Nullable id, NSError * _Nullable error))completionHandler;
  113. /**
  114. * Inserts HTML at the caret position
  115. *
  116. * @param html HTML string to insert
  117. *
  118. */
  119. - (void)insertHTML:(NSString *)html;
  120. /**
  121. * Manually focuses on the text editor
  122. */
  123. - (void)focusTextEditor;
  124. /**
  125. * Manually dismisses on the text editor
  126. */
  127. - (void)blurTextEditor;
  128. /**
  129. * Shows the insert image dialog with optinal inputs
  130. *
  131. * @param url The URL for the image
  132. * @param alt The alt for the image
  133. */
  134. - (void)showInsertImageDialogWithLink:(NSString *)url alt:(NSString *)alt;
  135. /**
  136. * Inserts an image
  137. *
  138. * @param url The URL for the image
  139. * @param alt The alt attribute for the image
  140. */
  141. - (void)insertImage:(NSString *)url alt:(NSString *)alt;
  142. /**
  143. * Shows the insert link dialog with optional inputs
  144. *
  145. * @param url The URL for the link
  146. * @param title The tile for the link
  147. */
  148. - (void)showInsertLinkDialogWithLink:(NSString *)url title:(NSString *)title;
  149. /**
  150. * Inserts a link
  151. *
  152. * @param url The URL for the link
  153. * @param title The title for the link
  154. */
  155. - (void)insertLink:(NSString *)url title:(NSString *)title;
  156. /**
  157. * Gets called when the insert URL picker button is tapped in an alertView
  158. *
  159. * @warning The default implementation of this method is blank and does nothing
  160. */
  161. - (void)showInsertURLAlternatePicker;
  162. /**
  163. * Gets called when the insert Image picker button is tapped in an alertView
  164. *
  165. * @warning The default implementation of this method is blank and does nothing
  166. */
  167. - (void)showInsertImageAlternatePicker;
  168. /**
  169. * Dismisses the current AlertView
  170. */
  171. - (void)dismissAlertView;
  172. /**
  173. * Add a custom UIBarButtonItem by using a UIButton
  174. */
  175. - (void)addCustomToolbarItemWithButton:(UIButton*)button;
  176. /**
  177. * Add a custom ZSSBarButtonItem
  178. */
  179. - (void)addCustomToolbarItem:(ZSSBarButtonItem *)item;
  180. /**
  181. * Scroll event callback with position
  182. */
  183. - (void)editorDidScrollWithPosition:(NSInteger)position;
  184. /**
  185. * Text change callback with text and html
  186. */
  187. - (void)editorDidChangeWithText:(NSString *)text andHTML:(NSString *)html;
  188. /**
  189. * Hashtag callback with word
  190. */
  191. - (void)hashtagRecognizedWithWord:(NSString *)word;
  192. /**
  193. * Mention callback with word
  194. */
  195. - (void)mentionRecognizedWithWord:(NSString *)word;
  196. /**
  197. * Set custom css
  198. */
  199. - (void)setCSS:(NSString *)css;
  200. @end