YiiWheels
  • Package
  • Class
  • Tree

Packages

  • None
  • yiiwheels
    • behaviors
    • widgets
    • widgets
      • ace
      • box
      • datepicker
      • daterangepicker
      • datetimepicker
      • detail
      • fileupload
      • fileuploader
      • 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     public function init()
 46     {
 47     
 48         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
 49     
 50         if (!$style = TbArray::popValue('style', $this->htmlOptions, '')) {
 51             $this->htmlOptions['style'] = $style;
 52         }
 53     
 54         $width                      = TbArray::getValue('width', $this->htmlOptions, '100%');
 55         $height                     = TbArray::popValue('height', $this->htmlOptions, '450px');
 56         $this->htmlOptions['style'] = "width:{$width};height:{$height};" . $this->htmlOptions['style'];
 57     }
 58 
 59     /**
 60      * Display editor
 61      */
 62     public function run()
 63     {
 64 
 65         list($name, $id) = $this->resolveNameID();
 66 
 67         $this->htmlOptions['id'] = $id;
 68 
 69         $this->registerClientScript();
 70 
 71         if (!array_key_exists('style', $this->htmlOptions))
 72             $this->htmlOptions['style'] = "width:{$this->width};height:{$this->height};";
 73         // Do we have a model?
 74         if ($this->hasModel())
 75             echo CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
 76         else
 77             echo CHtml::textArea($name, $this->value, $this->htmlOptions);
 78     }
 79 
 80     /**
 81      * Register required script files
 82      */
 83     public function registerClientScript()
 84     {
 85         /* publish assets dir */
 86         $path      = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
 87         $assetsUrl = $this->getAssetsUrl($path);
 88 
 89         /* @var $cs CClientScript */
 90         $cs = Yii::app()->getClientScript();
 91 
 92         $cs->registerCssFile($assetsUrl . '/css/bootstrap-wysihtml5.css');
 93         if (isset($this->pluginOptions['color'])) {
 94             $cs->registerCssFile($assetsUrl . '/css/wysiwyg-color.css');
 95         }
 96 
 97         $cs->registerScriptFile($assetsUrl . '/js/wysihtml5-0.3.0.js');
 98         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-wysihtml5.js');
 99 
100         if (in_array(@$this->pluginOptions['locale'], array('de-DE', 'es-ES', 'fr', 'fr-NL', 'pt-BR', 'sv-SE'))) {
101             $cs->registerScriptFile(
102                 $assetsUrl . '/js/locale/bootstrap-wysihtml5.' . $this->pluginOptions['locale'] . '.js'
103             );
104         } elseif (in_array($this->lang, array('de-DE', 'es-ES', 'fr', 'fr-NL', 'pt-BR', 'sv-SE'))) {
105             $cs->registerScriptFile($assetsUrl . '/js/locale/bootstrap-wysihtml5.' . $this->lang . '.js');
106             $this->pluginOptions['locale'] = $this->lang;
107         }
108 
109         $this->normalizeStylesheetsProperty();
110 
111         /* initialize plugin */
112         $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
113 
114         $this->getApi()->registerPlugin('wysihtml5', $selector, $this->pluginOptions);
115 
116     }
117 
118     /**
119      * Normalizes stylesheet property
120      */
121     private function normalizeStylesheetsProperty()
122     {
123         if (empty($this->pluginOptions['stylesheets']))
124             $this->pluginOptions['stylesheets'] = array();
125         else if (is_array($this->pluginOptions['stylesheets']))
126             $this->pluginOptions['stylesheets'] = array_filter($this->pluginOptions['stylesheets'], 'is_string');
127         else if (is_string($this->pluginOptions['stylesheets']))
128             $this->pluginOptions['stylesheets'] = array($this->pluginOptions['stylesheets']);
129         else
130             $this->pluginOptions['stylesheets'] = array();
131     }
132 }
133 
YiiWheels API documentation generated by ApiGen 2.8.0