Rewrite markdown editor in vanilla Javascript

This commit is contained in:
Frederic Guillot
2016-11-21 21:53:30 -05:00
parent ba900817b6
commit 5188ed8cfe
9 changed files with 262 additions and 180 deletions

View File

@@ -193,27 +193,18 @@ class FormHelper extends Base
*/
public function textEditor($name, $values = array(), array $errors = array(), array $attributes = array())
{
if (! isset($attributes['css'])) {
$attributes['css'] = '';
}
$attrHtml = '';
$attributes['css'] .= $this->errorClass($errors, $name);
foreach ($attributes as $attribute => $value) {
$attrHtml .= sprintf(' %s="%s"', $attribute, $value);
}
$html = sprintf(
'<texteditor name="%s" text="%s" label-preview="%s" label-write="%s" placeholder="%s" %s></texteditor>',
$name,
isset($values[$name]) ? $this->helper->text->e($values[$name]) : '',
t('Preview'),
t('Write'),
t('Write your text in Markdown'),
$attrHtml
$params = array(
'name' => $name,
'text' => isset($values[$name]) ? $this->helper->text->e($values[$name]) : '',
'css' => $this->errorClass($errors, $name),
'required' => isset($attributes['required']) && $attributes['required'],
'tabindex' => isset($attributes['tabindex']) ? $attributes['tabindex'] : '-1',
'labelPreview' => t('Preview'),
'labelWrite' => t('Write'),
'placeholder' => t('Write your text in Markdown'),
);
$html = '<div class="js-text-editor" data-params=\''.json_encode($params, JSON_HEX_APOS).'\'></div>';
$html .= $this->errorList($errors, $name);
return $html;