7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Editor.php 16971 2009-07-22 18:05:45Z mikaelkael $
23 /** Zend_Dojo_View_Helper_Textarea */
24 require_once 'Zend/Dojo/View/Helper/Textarea.php';
27 require_once 'Zend/Json.php';
32 * @uses Zend_Dojo_View_Helper_Textarea
35 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
36 * @license http://framework.zend.com/license/new-bsd New BSD License
38 class Zend_Dojo_View_Helper_Editor
extends Zend_Dojo_View_Helper_Textarea
41 * @param string Dijit type
43 protected $_dijit = 'dijit.Editor';
46 * @var string Dijit module to load
48 protected $_module = 'dijit.Editor';
51 * JSON-encoded parameters
54 protected $_jsonParams = array('captureEvents', 'events', 'plugins');
60 * @param string $value
61 * @param array $params
62 * @param array $attribs
65 public function editor($id, $value = null, $params = array(), $attribs = array())
68 if (array_key_exists('id', $attribs)) {
69 $hiddenId = $attribs['id'];
71 $hiddenId = $hiddenName;
73 $hiddenId = $this->_normalizeId($hiddenId);
75 $textareaName = $this->_normalizeEditorName($hiddenName);
76 $textareaId = $hiddenId . '-Editor';
78 $hiddenAttribs = array(
80 'name' => $hiddenName,
84 $attribs['id'] = $textareaId;
86 $this->_createGetParentFormFunction();
87 $this->_createEditorOnSubmit($hiddenId, $textareaId);
89 $html = '<input' . $this->_htmlAttribs($hiddenAttribs) . $this->getClosingBracket()
90 . $this->textarea($textareaName, $value, $params, $attribs);
96 * Normalize editor element name
101 protected function _normalizeEditorName($name)
103 if ('[]' == substr($name, -2)) {
104 $name = substr($name, 0, strlen($name) - 2);
105 $name .= '[Editor][]';
113 * Create onSubmit binding for element
115 * @param string $hiddenId
116 * @param string $editorId
119 protected function _createEditorOnSubmit($hiddenId, $editorId)
121 $this->dojo
->onLoadCaptureStart();
124 var form = zend.findParentForm(dojo.byId('$hiddenId'));
125 dojo.connect(form, 'onsubmit', function () {
126 dojo.byId('$hiddenId').value = dijit.byId('$editorId').getValue(false);
130 $this->dojo
->onLoadCaptureEnd();