3 require_once('HTML/QuickForm/textarea.php');
6 * HTML Quickform element for CKeditor
8 * CKeditor is a WYSIWYG HTML editor which can be obtained from
9 * http://ckeditor.com. I tried to resemble the integration instructions
10 * as much as possible, so the examples from the docs should work with this one.
12 * @author Kurund Jalmi
15 class HTML_QuickForm_CKeditor
extends HTML_QuickForm_textarea
18 * The width of the editor in pixels or percent
26 * The height of the editor in pixels or percent
36 * @param string FCKeditor instance name
37 * @param string FCKeditor instance label
38 * @param array Config settings for FCKeditor
39 * @param string Attributes for the textarea
43 function HTML_QuickForm_ckeditor($elementName=null, $elementLabel=null, $attributes=null, $options=array())
45 HTML_QuickForm_element
::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
46 $this->_persistantFreeze
= true;
47 $this->_type
= 'CKeditor';
48 // set editor height smaller if schema defines rows as 4 or less
49 if ( is_array($attributes) && array_key_exists( 'rows', $attributes ) && $attributes['rows'] <= 4 ) {
55 * Add js to to convert normal textarea to ckeditor
62 if ($this->_flagFrozen
) {
63 return $this->getFrozenHtml();
64 } elseif (!$this->getAttribute('click_wysiwyg')) {
65 $elementId = $this->getAttribute('id');
66 $config = CRM_Core_Config
::singleton( );
67 $browseUrl = $config->userFrameworkResourceURL
. 'packages/kcfinder/browse.php';
68 $uploadUrl = $config->userFrameworkResourceURL
. 'packages/kcfinder/upload.php';
70 $html = parent
::toHtml() . "<script type='text/javascript'>
72 cj('#{$elementId}').removeClass();
73 if ( CKEDITOR.instances['{$elementId}'] ) {
74 CKEDITOR.remove(CKEDITOR.instances['{$elementId}']);
76 if ( cj('#{$elementId}').val( ) == '' ) cj('#{$elementId}').val(' ');
77 CKEDITOR.replace( '{$elementId}' );
78 var editor = CKEDITOR.instances['{$elementId}'];
80 editor.config.width = '".$this->width
."';
81 editor.config.height = '".$this->height
."';
82 editor.config.filebrowserBrowseUrl = '".$browseUrl."?cms=civicrm&type=files';
83 editor.config.filebrowserImageBrowseUrl = '".$browseUrl."?cms=civicrm&type=images';
84 editor.config.filebrowserFlashBrowseUrl = '".$browseUrl."?cms=civicrm&type=flash';
85 editor.config.filebrowserUploadUrl = '".$uploadUrl."?cms=civicrm&type=files';
86 editor.config.filebrowserImageUploadUrl = '".$uploadUrl."?cms=civicrm&type=images';
87 editor.config.filebrowserFlashUploadUrl = '".$uploadUrl."?cms=civicrm&type=flash';
94 $elementId = $this->getAttribute('id');
95 $plain = '<div id="' . $elementId .'-plain" class="replace-plain" tabindex="0" title="'. ts('Click to edit') .'">' . $this->getFrozenHtml() . '</div>' . parent
::toHtml();
96 $config = CRM_Core_Config
::singleton( );
97 $browseUrl = $config->userFrameworkResourceURL
. 'packages/kcfinder/browse.php';
98 $uploadUrl = $config->userFrameworkResourceURL
. 'packages/kcfinder/upload.php';
100 $html = $plain . "<script type='text/javascript'>
102 $('#{$elementId}').hide();
103 var openWysiwyg = function() {
104 var restorePlain = $('#{$elementId}-plain').detach();
105 $('#{$elementId}').removeClass();
106 if ( CKEDITOR.instances['{$elementId}'] ) {
107 CKEDITOR.remove(CKEDITOR.instances['{$elementId}']);
109 if ( $('#{$elementId}').val( ) == '' ) $('#{$elementId}').val(' ');
110 CKEDITOR.replace( '{$elementId}' );
111 var editor = CKEDITOR.instances['{$elementId}'];
113 editor.config.width = '".$this->width
."';
114 editor.config.height = '".$this->height
."';
115 editor.config.filebrowserBrowseUrl = '".$browseUrl."?cms=civicrm&type=files';
116 editor.config.filebrowserImageBrowseUrl = '".$browseUrl."?cms=civicrm&type=images';
117 editor.config.filebrowserFlashBrowseUrl = '".$browseUrl."?cms=civicrm&type=flash';
118 editor.config.filebrowserUploadUrl = '".$uploadUrl."?cms=civicrm&type=files';
119 editor.config.filebrowserImageUploadUrl = '".$uploadUrl."?cms=civicrm&type=images';
120 editor.config.filebrowserFlashUploadUrl = '".$uploadUrl."?cms=civicrm&type=flash';
121 editor.on( 'blur', function( e ) {
122 this.updateElement();
124 $('#{$elementId}').before(restorePlain);
125 $('#{$elementId}-plain').html($('#{$elementId}').val());
126 $('#{$elementId}').hide();
130 $('#{$elementId}-plain').click(openWysiwyg);
131 $('#{$elementId}-plain').keypress(openWysiwyg);
139 * Returns the htmlarea content in HTML
144 function getFrozenHtml()
146 return $this->getValue();