wysiwyg.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. Integrating a Rich Text Editor
  2. ##############################
  3. Build your own wysiwyg plugin.
  4. Elgg is bundled with a plugin for CKEditor_, and previously shipped with TinyMCE_ support.
  5. However, if you have a wysiwyg that you prefer, you could use this tutorial to help you build your own.
  6. .. _CKEditor: http://ckeditor.com/
  7. .. _TinyMCE: http://www.tinymce.com/
  8. All forms in Elgg should try to use the provided input views located in ``views/default/input``.
  9. If these views are used, then it is simple for plugin authors to replace a view,
  10. in this case longtext.php, with their wysiwyg.
  11. Create your plugin skeleton
  12. ---------------------------
  13. You will need to create your plugin and give it a start.php file where the plugin gets initialized,
  14. as well as a manifest.xml file to tell the Elgg engine about your plugin.
  15. Read more in the guide about :doc:`/guides/plugins`.
  16. Add the WYSIWYG library code
  17. ----------------------------
  18. Now you need to upload TinyMCE into a directory in your plugin.
  19. We strongly encourage you to put third party libraries in a “vendors” directory,
  20. as that is standard practice in Elgg plugins and will make
  21. your plugin much more approachable by other developers::
  22. mod/tinymce/vendors/tinymce/
  23. Tell Elgg when and how to load TinyMCE
  24. --------------------------------------
  25. Now that you have:
  26. * created your start file
  27. * intialized the plugin
  28. * uploaded the wysiwyg code
  29. It is time to tell Elgg how to apply TinyMCE to longtext fields.
  30. We're going to do that by extending the input/longtext view and including some javascript.
  31. Create a view tinymce/longtext and add the following code:
  32. .. code:: php
  33. <?php
  34. /**
  35. * Elgg long text input with the tinymce text editor intacts
  36. * Displays a long text input field
  37. *
  38. * @package ElggTinyMCE
  39. *
  40. *
  41. */
  42. ?>
  43. <!-- include tinymce -->
  44. <script language="javascript" type="text/javascript" src="<?php echo $vars['url']; ?>mod/tinymce/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
  45. <!-- intialise tinymce, you can find other configurations here http://wiki.moxiecode.com/examples/tinymce/installation_example_01.php -->
  46. <script language="javascript" type="text/javascript">
  47. tinyMCE.init({
  48. mode : "textareas",
  49. theme : "advanced",
  50. theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink,image,blockquote,code",
  51. theme_advanced_buttons2 : "",
  52. theme_advanced_buttons3 : "",
  53. theme_advanced_toolbar_location : "top",
  54. theme_advanced_toolbar_align : "left",
  55. theme_advanced_statusbar_location : "bottom",
  56. theme_advanced_resizing : true,
  57. extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],
  58. hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
  59. });
  60. </script>
  61. Then, in your plugin's init function, extend the input/longtext view
  62. .. code:: php
  63. function tinymce_init() {
  64. elgg_extend_view('input/longtext', 'tinymce/longtext');
  65. }
  66. That's it! Now every time someone uses input/longtext,
  67. TinyMCE will be loaded and applied to that textarea.