1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
<?php
/*
* This file is part of the symfony package.
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* sfWidgetFormTextareaTinyMCE represents a Tiny MCE widget.
*
* You must include the Tiny MCE JavaScript file by yourself.
*
* @package symfony
* @subpackage widget
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: sfWidgetFormTextareaTinyMCE.class.php 11894 2008-10-01 16:36:53Z fabien $
*/
class sfWidgetFormTextareaTinyMCE extends sfWidgetFormTextarea
{
/**
* Constructor.
*
* Available options:
*
* * theme: The Tiny MCE theme
* * width: Width
* * height: Height
* * config: The javascript configuration
*
* @param array $options An array of options
* @param array $attributes An array of default HTML attributes
*
* @see sfWidgetForm
*/
protected function configure($options = array(), $attributes = array())
{
$this->addOption('theme', 'advanced');
$this->addOption('width');
$this->addOption('height');
$this->addOption('config', '');
}
/**
* @param string $name The element name
* @param string $value The value selected in this widget
* @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
* @param array $errors An array of errors for the field
*
* @return string An HTML tag string
*
* @see sfWidgetForm
*/
public function render($name, $value = null, $attributes = array(), $errors = array())
{
if (!isset($attributes['class']))
{
throw new InvalidArgumentException(sprintf('You must pass a "class" attribute for a TinyMCE widget (%s).', $name));
}
$textarea = parent::render($name, $value, $attributes, $errors);
// take the first class
$classes = explode(' ', $attributes['class']);
$class = trim($classes[0]);
$js = sprintf(<<<EOF
<script type="text/javascript">
tinyMCE.init({
mode: "textareas",
theme: "%s",
editor_selector: "%s",
%s
%s
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
theme_advanced_resizing: true
%s
});
</script>
EOF
,
$this->getOption('theme'),
$class,
$this->getOption('width') ? sprintf('width: "%spx",', $this->getOption('width')) : '',
$this->getOption('height') ? sprintf('height: "%spx",', $this->getOption('height')) : '',
$this->getOption('config') ? ",\n".$this->getOption('config') : ''
);
return $textarea.$js;
}
}
|