HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbRedactorJs.php
Go to the documentation of this file.
1 <?php
20 class TbRedactorJS extends CInputWidget
21 {
25  public $editorOptions = array();
26 
32  public $selector;
33 
37  public $width = '100%';
38 
42  public $height = '400px';
43 
44  public function init()
45  {
46  parent::init();
47 
48  if (!isset($this->editorOptions['lang'])) {
49  $this->editorOptions['lang'] = substr(Yii::app()->getLanguage(), 0, 2);
50  }
51 
52  if ($this->selector === null) {
53  list($this->name, $this->id) = $this->resolveNameID();
54  $this->htmlOptions['id'] = $this->id;
55  $this->selector = '#' . $this->id;
56  if (!array_key_exists('style', $this->htmlOptions)) {
57  $this->htmlOptions['style'] = "width:{$this->width};height:{$this->height};";
58  }
59  if ($this->hasModel()) {
60  echo CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
61  } else {
62  echo CHtml::textArea($this->name, $this->value, $this->htmlOptions);
63  }
64  }
65  $this->registerClientScript($this->id);
66  }
67 
71  public function registerClientScript()
72  {
73  $assets = Booster::getBooster()->cs;
74 
75  $assets->registerPackage('redactor');
76 
77  $baseUrl = $assets->packages['redactor']['baseUrl'];
78 
79  // Prepend language file to scripts package.
80  if ($this->editorOptions['lang'] != 'en') {
81  $assets->registerScriptFile($baseUrl . '/lang/' . $this->editorOptions['lang'] . '.js');
82  }
83 
84  if (isset($this->editorOptions['plugins'])) {
85  foreach ($this->editorOptions['plugins'] as $name) {
86  $filepath = Yii::getPathOfAlias('booster.assets.redactor.plugins') . '/' . $name . '/' . $name;
87  $url = $baseUrl . '/plugins/' . $name . '/' . $name;
88 
89  if (file_exists($filepath . '.css'))
90  $assets->registerCssFile($url.'.css');
91 
92  if (file_exists($filepath . '.js'))
93  $assets->registerScriptFile($url.'.js');
94  }
95  }
96 
97  $options = $this->editorOptions
98  ? CJavaScript::encode($this->editorOptions)
99  : '';
100 
101  $assets->registerScript(
102  uniqid(__CLASS__ . '#', true),
103  "jQuery('{$this->selector}').redactor({$options});"
104  );
105  }
106 }