HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbMarkdownEditor.php
Go to the documentation of this file.
1 <?php
21 class TbMarkdownEditor extends CInputWidget {
22 
27  public $options = array();
28 
32  public $width = '100%';
33 
37  public $height = '400px';
38 
42  public function run() {
43 
44  list($name, $id) = $this->resolveNameID();
45 
46  $this->htmlOptions['id'] = $id;
47 
48  $this->registerClientScript($id);
49 
50  if (!array_key_exists('style', $this->htmlOptions)) {
51  $this->htmlOptions['style'] = "width:{$this->width};height:{$this->height};";
52  }
53 
54  if ($this->hasModel()) { // Do we have a model?
55  echo CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
56  } else {
57  echo CHtml::textArea($name, $this->value, $this->htmlOptions);
58  }
59  }
60 
66  public function registerClientScript($id) {
67 
68  $booster = Booster::getBooster();
69  $booster->registerPackage('markdown');
70 
71  $id = $this->htmlOptions['id'];
72  $options = CJSON::encode($this->options);
73 
74  Yii::app()->clientScript->registerScript(__CLASS__ . '#' . $id, "
75  $('#$id').markdown({$options})
76  ", CClientScript::POS_END
77  );
78  }
79 }