HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbHtml5Editor.php
Go to the documentation of this file.
1 <?php
18 class TbHtml5Editor extends CInputWidget {
19 
24  public $lang = 'en';
25 
29  public $htmlOptions = array();
30 
34  public $editorOptions = array();
35 
39  public $width = '100%';
40 
44  public $height = '400px';
45 
49  public function run() {
50 
51  list($name, $id) = $this->resolveNameID();
52 
53  $this->registerClientScript($id);
54 
55  $this->htmlOptions['id'] = $id;
56 
57  if (!array_key_exists('style', $this->htmlOptions)) {
58  $this->htmlOptions['style'] = "width:{$this->width};height:{$this->height};";
59  }
60  // Do we have a model?
61  if ($this->hasModel()) {
62  echo CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
63  } else {
64  echo CHtml::textArea($name, $this->value, $this->htmlOptions);
65  }
66  }
67 
73  public function registerClientScript($id) {
74 
75  $booster = Booster::getBooster();
76  $booster->registerPackage('wysihtml5');
77  //$booster->registerAssetCss('bootstrap-wysihtml5.css');
78  //$booster->registerAssetJs('wysihtml5-0.3.0.js');
79  //$booster->registerAssetJs('bootstrap-wysihtml5.js');
80 
81  if (isset($this->editorOptions['locale'])) {
82  $booster->registerAssetJs(
83  'locales/bootstrap-wysihtml5.' . $this->editorOptions['locale'] . '.js'
84  );
85  } elseif (in_array($this->lang, array('de-DE', 'es-ES', 'fr', 'fr-NL', 'pt-BR', 'sv-SE', 'it-IT'))) {
86  $booster->registerAssetJs('locales/bootstrap-wysihtml5.' . $this->lang . '.js');
87  $this->editorOptions['locale'] = $this->lang;
88  }
89 
92 
93  $options = CJSON::encode($this->editorOptions);
94 
95  $script = array();
102  $script[] = "$.fn.wysihtml5.defaultOptions.stylesheets = [];";
103 
107  if (isset($this->editorOptions['deepExtend']) && $this->editorOptions['deepExtend'] === true) {
108  $script[] = "$('#{$id}').wysihtml5('deepExtend', {$options});";
109  } else {
110  $script[] = "$('#{$id}').wysihtml5({$options});";
111  }
112 
113  Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, implode("\n", $script));
114  }
115 
117  {
118  if (empty($this->editorOptions['color'])) {
119  return;
120  }
121 
122  $defaultStyleSheetUrl = Booster::getBooster()->getAssetsUrl() . '/css/wysiwyg-color.css';
123  array_unshift($this->editorOptions['stylesheets'], $defaultStyleSheetUrl); // we want default css to be first
124  }
125 
126  private function normalizeStylesheetsProperty()
127  {
128  if (empty($this->editorOptions['stylesheets'])) {
129  $this->editorOptions['stylesheets'] = array();
130  } else if (is_array($this->editorOptions['stylesheets'])) {
131  $this->editorOptions['stylesheets'] = array_filter(
132  $this->editorOptions['stylesheets'],
133  'is_string'
134  );
135  } else if (is_string($this->editorOptions['stylesheets'])) {
136  $this->editorOptions['stylesheets'] = array($this->editorOptions['stylesheets']);
137  } else // presumably if this option is neither an array or string then it's some erroneous value; clean it
138  {
139  $this->editorOptions['stylesheets'] = array();
140  }
141  }
142 }