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  * WhGoogleFonts 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 WhGoogleFonts extends CInputWidget
 16 {
 17     /**
 18      * Editor options that will be passed to the editor.
 19      *
 20      * - family
 21      * - subsets
 22      * - families
 23      * @see http://vincentlamanna.com/BootstrapFormHelpers/googlefont.html
 24      */
 25     public $pluginOptions = array();
 26 
 27     /**
 28      * @var bool whether to use bootstrap helper select Box widget
 29      */
 30     public $useHelperSelectBox = false;
 31 
 32     /**
 33      * @var array extra config options for helper select box
 34      */
 35     public $helperOptions = array();
 36 
 37 
 38     /**
 39      * Widget's initialization method
 40      * @throws CException
 41      */
 42     public function init()
 43     {
 44 
 45         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
 46 
 47         TbHtml::addCssClass('bfh-googlefonts', $this->htmlOptions);
 48     }
 49 
 50     /**
 51      * Runs the widget.
 52      */
 53     public function run()
 54     {
 55         $this->renderField();
 56         $this->registerClientScript();
 57     }
 58 
 59     /**
 60      * Renders the input file field
 61      */
 62     public function renderField()
 63     {
 64         list($name, $id) = $this->resolveNameID();
 65 
 66         TbArray::defaultValue('id', $id, $this->htmlOptions);
 67         TbArray::defaultValue('name', $name, $this->htmlOptions);
 68 
 69         if ($this->useHelperSelectBox) {
 70             $select = Yii::createComponent(CMap::mergeArray($this->helperOptions, array(
 71                 'class' => 'yiiwheels.widgets.formhelpers.WhSelectBox',
 72                 'htmlOptions' => $this->htmlOptions,
 73                 'model' => $this->model,
 74                 'attribute' => $this->attribute,
 75                 'name' => $this->name,
 76                 'value' => $this->value,
 77                 'wrapperOptions' => array(
 78                     'class' => 'bfh-googlefonts',
 79                     'data-family' => $this->hasModel() ? $this->model->{$this->attribute} : $this->value,
 80                     'data-subsets' => isset($this->pluginOptions['subsets'])
 81                         ? $this->pluginOptions['subsets']
 82                         : null,
 83                     'data-families' => isset($this->pluginOptions['families'])
 84                         ? $this->pluginOptions['families']
 85                         : null
 86                 )
 87             )));
 88             $select->init();
 89             $select->run();
 90         } else {
 91             $this->htmlOptions['data-family'] = $this->hasModel()
 92                 ? $this->model->{$this->attribute}
 93                 : $this->value;
 94             $this->htmlOptions['data-subsets'] = isset($this->pluginOptions['subsets'])
 95                 ? $this->pluginOptions['subsets']
 96                 : null;
 97             $this->htmlOptions['data-families'] = isset($this->pluginOptions['families'])
 98                 ? $this->pluginOptions['families']
 99                 : null;
100             if ($this->hasModel()) {
101                 echo CHtml::activeDropDownList($this->model, $this->attribute, array(), $this->htmlOptions);
102             } else {
103                 echo CHtml::dropDownList($name, $this->value, array(), $this->htmlOptions);
104             }
105         }
106     }
107 
108     /**
109      * Registers client script
110      */
111     public function registerClientScript()
112     {
113         /* publish assets dir */
114         $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
115         $assetsUrl = $this->getAssetsUrl($path);
116 
117         /* @var $cs CClientScript */
118         $cs = Yii::app()->getClientScript();
119 
120         $cs->registerCssFile($assetsUrl . '/css/bootstrap-formhelpers.css');
121 
122         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-googlefonts.codes.js');
123         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-googlefonts.js');
124 
125         /* initialize plugin */
126         if (!$this->useHelperSelectBox) {
127             $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
128             $this->getApi()->registerPlugin('bfhgooglefonts', $selector, $this->pluginOptions);
129         }
130     }
131 }
YiiWheels API documentation generated by ApiGen 2.8.0