HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbMarkdownEditorJs.php
Go to the documentation of this file.
1 <?php
19 class TbMarkdownEditorJS extends CInputWidget
20 {
24  public $width = '100%';
25 
29  public $height = '400px';
30 
34  public function run()
35  {
36 
37  list($name, $id) = $this->resolveNameID();
38 
39  $this->registerClientScript($id);
40 
41  // Markdown Editor looks for an id of wmd-input...
42  $this->htmlOptions['id'] = $id;
43 
44  $this->htmlOptions['class'] = (isset($this->htmlOptions['class']))
45  ? $this->htmlOptions['class'] . ' wmd-input'
46  : 'wmd-input';
47 
48  if (!array_key_exists('style', $this->htmlOptions)) {
49  $this->htmlOptions['style'] = "width:{$this->width};height:{$this->height};";
50  }
51  // Do we have a model?
52  if ($this->hasModel()) {
53  echo CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
54  } else {
55  echo CHtml::textArea($name, $this->value, $this->htmlOptions);
56  }
57  }
58 
64  public function registerClientScript($id)
65  {
66  $booster = Booster::getBooster();
67  $booster->registerAssetCss('markdown.editor.css');
68  $booster->registerAssetJs('markdown.converter.js', CClientScript::POS_HEAD);
69  $booster->registerAssetJs('markdown.sanitizer.js', CClientScript::POS_HEAD);
70  $booster->registerAssetJs('markdown.editor.js', CClientScript::POS_HEAD);
71  Yii::app()->clientScript->registerScript(
72  $id,
73  "var converter = Markdown.getSanitizingConverter();
74  var editor = new Markdown.Editor(converter, '" . $id . "');
75  editor.run();",
76  CClientScript::POS_END
77  );
78  }
79 }