YiiWheels
  • Package
  • Class
  • Tree

Packages

  • yiiwheels
    • behaviors
    • widgets
    • widgets
      • ace
      • box
      • datepicker
      • daterangepicker
      • datetimepicker
      • detail
      • editable
      • fileupload
      • fileuploader
      • formhelpers
      • gallery
      • google
      • grid
        • behaviors
        • operations
      • highcharts
      • maskInput
      • maskmoney
      • modal
      • multiselect
      • rangeslider
      • redactor
      • select2
      • sparklines
      • switch
      • timeago
      • timepicker
      • toggle
      • typeahead

Classes

  • WhHighCharts
  • WhHtml5Editor
  1 <?php
  2 /**
  3  * WhHtml5Editor widget
  4  *
  5  * Implements the bootstrap-wysihtml5 editor
  6  *
  7  * @see https://github.com/jhollingworth/bootstrap-wysihtml5
  8  *
  9  * @author Antonio Ramirez <amigo.cobos@gmail.com>
 10  * @copyright Copyright &copy; 2amigos.us 2013-
 11  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 12  * @package YiiWheels.widgets.highcharts
 13  * @uses YiiStrap.helpers.TbArray
 14  */
 15 Yii::import('bootstrap.helpers.TbArray');
 16 
 17 class WhHtml5Editor extends CInputWidget
 18 {
 19     /**
 20      * Editor language
 21      * Supports: de-DE, es-ES, fr-FR, pt-BR, sv-SE
 22      */
 23     public $lang = 'en';
 24 
 25     /**
 26      * Html options that will be assigned to the text area
 27      */
 28     public $htmlOptions = array();
 29 
 30     /**
 31      * Editor options that will be passed to the editor
 32      */
 33     public $pluginOptions = array();
 34 
 35     /**
 36      * Editor width
 37      */
 38     public $width = '100%';
 39 
 40     /**
 41      * Editor height
 42      */
 43     public $height = '400px';
 44 
 45     /**
 46      * Display editor
 47      */
 48     public function run()
 49     {
 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         // Do we have a model?
 60         if ($this->hasModel())
 61             echo CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
 62         else
 63             echo CHtml::textArea($name, $this->value, $this->htmlOptions);
 64     }
 65 
 66     /**
 67      * Register required script files
 68      * @param string $id
 69      */
 70     public function registerClientScript($id)
 71     {
 72         /* publish assets dir */
 73         $path      = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
 74         $assetsUrl = $this->getAssetsUrl($path);
 75 
 76         /* @var $cs CClientScript */
 77         $cs = Yii::app()->getClientScript();
 78 
 79         $cs->registerCssFile($assetsUrl . '/css/bootstrap-wysihtml5.css');
 80         if (isset($this->pluginOptions['color'])) {
 81             $cs->registerCssFile($assetsUrl . '/css/wysiwyg-color.css');
 82         }
 83 
 84         $cs->registerScriptFile($assetsUrl . '/js/wysihtml5-0.3.0.js');
 85         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-wysihtml5.js');
 86 
 87         if (in_array(@$this->pluginOptions['locale'], array('de-DE', 'es-ES', 'fr', 'fr-NL', 'pt-BR', 'sv-SE'))) {
 88             $cs->registerScriptFile(
 89                 $assetsUrl . '/js/locale/bootstrap-wysihtml5.' . $this->pluginOptions['locale'] . '.js'
 90             );
 91         } elseif (in_array($this->lang, array('de-DE', 'es-ES', 'fr', 'fr-NL', 'pt-BR', 'sv-SE'))) {
 92             $cs->registerScriptFile($assetsUrl . '/js/locale/bootstrap-wysihtml5.' . $this->lang . '.js');
 93             $this->pluginOptions['locale'] = $this->lang;
 94         }
 95 
 96         $this->normalizeStylesheetsProperty();
 97 
 98         /* initialize plugin */
 99         $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
100 
101         $this->getApi()->registerPlugin('wysihtml5', $selector, $this->pluginOptions);
102 
103     }
104 
105     /**
106      * Normalizes stylesheet property
107      */
108     private function normalizeStylesheetsProperty()
109     {
110         if (empty($this->pluginOptions['stylesheets']))
111             $this->pluginOptions['stylesheets'] = array();
112         else if (is_array($this->pluginOptions['stylesheets']))
113             $this->pluginOptions['stylesheets'] = array_filter($this->pluginOptions['stylesheets'], 'is_string');
114         else if (is_string($this->pluginOptions['stylesheets']))
115             $this->pluginOptions['stylesheets'] = array($this->pluginOptions['stylesheets']);
116         else
117             $this->pluginOptions['stylesheets'] = array();
118     }
119 }
120 
YiiWheels API documentation generated by ApiGen 2.8.0