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

  • WhCountries
  • WhDatePickerHelper
  • WhFonts
  • WhFontSizes
  • WhGoogleFonts
  • WhLanguages
  • WhPhone
  • WhSelectBox
  • WhStates
  • WhTimePickerHelper
  • WhTimezones
  1 <?php
  2 /**
  3  * WhFontSizes widget class
  4  *
  5  * @author Antonio Ramirez <amigo.cobos@gmail.com>
  6  * @copyright Copyright &copy; 2amigos.us 2013-
  7  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  8  * @package YiiWheels.widgets.formhelpers
  9  * @uses YiiStrap.helpers.TbArray
 10  * @uses YiiStrap.helpers.TbHtml
 11  */
 12 Yii::import('bootstrap.helpers.TbArray');
 13 Yii::import('bootstrap.helpers.TbHtml');
 14 
 15 class WhFontSizes extends CInputWidget
 16 {
 17     /**
 18      * Editor options that will be passed to the editor.
 19      *
 20      * - family
 21      *
 22      * @see http://vincentlamanna.com/BootstrapFormHelpers/fontsize.html
 23      */
 24     public $pluginOptions = array();
 25 
 26     /**
 27      * @var bool whether to use bootstrap helper select Box widget
 28      */
 29     public $useHelperSelectBox = false;
 30 
 31     /**
 32      * @var array extra config options for helper select box
 33      */
 34     public $helperOptions = array();
 35 
 36 
 37     /**
 38      * Widget's initialization method
 39      * @throws CException
 40      */
 41     public function init()
 42     {
 43 
 44         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
 45 
 46         TbHtml::addCssClass('bfh-fontsizes', $this->htmlOptions);
 47     }
 48 
 49     /**
 50      * Runs the widget.
 51      */
 52     public function run()
 53     {
 54         $this->renderField();
 55         $this->registerClientScript();
 56     }
 57 
 58     /**
 59      * Renders the input file field
 60      */
 61     public function renderField()
 62     {
 63         list($name, $id) = $this->resolveNameID();
 64 
 65         TbArray::defaultValue('id', $id, $this->htmlOptions);
 66         TbArray::defaultValue('name', $name, $this->htmlOptions);
 67 
 68         if ($this->useHelperSelectBox) {
 69             $select = Yii::createComponent(CMap::mergeArray($this->helperOptions, array(
 70                 'class' => 'yiiwheels.widgets.formhelpers.WhSelectBox',
 71                 'htmlOptions' => $this->htmlOptions,
 72                 'model' => $this->model,
 73                 'attribute' => $this->attribute,
 74                 'name' => $this->name,
 75                 'value' => $this->value,
 76                 'wrapperOptions' => array(
 77                     'class' => 'bfh-fontsizes',
 78                     'data-size' => $this->hasModel() ? $this->model->{$this->attribute} : $this->value,
 79                 )
 80             )));
 81             $select->init();
 82             $select->run();
 83         } else {
 84             $this->htmlOptions['data-size'] = $this->hasModel()
 85                 ? $this->model->{$this->attribute}
 86                 : $this->value;
 87 
 88             if ($this->hasModel()) {
 89                 echo CHtml::activeDropDownList($this->model, $this->attribute, array(), $this->htmlOptions);
 90             } else {
 91                 echo CHtml::dropDownList($name, $this->value, array(), $this->htmlOptions);
 92             }
 93         }
 94     }
 95 
 96     /**
 97      * Registers client script
 98      */
 99     public function registerClientScript()
100     {
101         /* publish assets dir */
102         $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
103         $assetsUrl = $this->getAssetsUrl($path);
104 
105         /* @var $cs CClientScript */
106         $cs = Yii::app()->getClientScript();
107 
108         $cs->registerCssFile($assetsUrl . '/css/bootstrap-formhelpers.css');
109         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-fontsizes.codes.js');
110         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-fontsizes.js');
111 
112         /* initialize plugin */
113         if (!$this->useHelperSelectBox) {
114             $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
115             $this->getApi()->registerPlugin('bfhfontsizes', $selector, $this->pluginOptions);
116         }
117     }
118 }
YiiWheels API documentation generated by ApiGen 2.8.0