*/ if (!class_exists('patForms_Element_Text', false)) { WBClass::load('patForms_Element_Text'); } /** * patForms Elemenbt: Xinha * * Xinha WYSIWYG Editor derived from Text * * @version 0.2.0 * @package Wombat * @subpackage patForms */ class patForms_Element_Xinha extends patForms_Element_Text { /** * Stores the name of the element - this is used mainly by the patForms * error management and should be set in every element class. * @var string */ public $elementName = 'Xinha'; /** * constructor * * call parent constructor and add filter to transform Xinha HTML to and * from XML * * @param $format */ public function __construct($format = false) { $this->attributeDefinition['features'] = array( 'required' => false, 'format' => 'string', 'default' => '', 'outputFormats' => array(), ); $this->attributeDefinition['toolbar'] = array( 'required' => false, 'format' => 'string', 'default' => 'bold,italic,underline,strikethrough,insertorderedlist,insertunorderedlist,outdent,indent', 'outputFormats' => array(), ); $this->attributeDefinition['plugins'] = array( 'required' => false, 'format' => 'string', 'default' => '', 'outputFormats' => array(), ); parent::__construct($format); $filter = patForms::createFilter('XmlXinha'); $this->applyFilter($filter); } /** * element creation method for the 'HTML' format in the 'default' form mode. * * @access public * @param mixed value of the element * @return mixed $element The element, or false if failed. */ public function serializeHtmlDefault( $value ) { $html = array(); $html[] = parent::serializeHtmlDefault($value); $id = $this->attributes['id']; WBClass::load('WBHtml_JS'); /* * Load Xinha and XinhaCore beforehand * * Dynamic loading does not work with Xinha */ WBHtml_JS::add('WB/Xinha'); WBHtml_JS::add('WB/XinhaCore/XinhaCore'); $features = ''; if (!empty($this->attributes['features'])) { $features = explode(',', $this->attributes['features']); $features = '"' . implode('", "', $features) . '"'; } WBHtml_JS::add(sprintf('WB.Xinha.tmpConf = WB.Xinha.createConfig(%s);', $features), WBHtml_JS::AREA_FOOT); $toolbar = ''; if (!empty($this->attributes['toolbar'])) { $toolbar = explode(',', $this->attributes['toolbar']); $toolbar = '"' . implode('", "', $toolbar) . '"'; } WBHtml_JS::add(sprintf('WB.Xinha.tmpConf.toolbar[0] = [%s];', $toolbar), WBHtml_JS::AREA_FOOT); $plugins = array(); if (!empty($this->attributes['plugins'])) { $plugins = explode(',', $this->attributes['plugins']); foreach ($plugins as $p) { WBHtml_JS::add(sprintf('WB.Xinha.tmpConf.usePlugins.push("%s");', $p), WBHtml_JS::AREA_FOOT); } } WBHtml_JS::add('WB.Xinha.start("'. $id . '", WB.Xinha.tmpConf);', WBHtml_JS::AREA_FOOT); return implode("\n", $html); } } ?>