web/lib/Zend/Dojo/Form/Element/Editor.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Dojo
    16  * @package    Zend_Dojo
    17  * @subpackage Form_Element
    17  * @subpackage Form_Element
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Editor.php 20096 2010-01-06 02:05:09Z bkarwin $
    20  * @version    $Id: Editor.php 24593 2012-01-05 20:35:02Z matthew $
    21  */
    21  */
    22 
    22 
    23 /** Zend_Dojo_Form_Element_Dijit */
    23 /** Zend_Dojo_Form_Element_Dijit */
    24 require_once 'Zend/Dojo/Form/Element/Dijit.php';
    24 require_once 'Zend/Dojo/Form/Element/Dijit.php';
    25 
    25 
    28  *
    28  *
    29  * @uses       Zend_Dojo_Form_Element_Dijit
    29  * @uses       Zend_Dojo_Form_Element_Dijit
    30  * @category   Zend
    30  * @category   Zend
    31  * @package    Zend_Dojo
    31  * @package    Zend_Dojo
    32  * @subpackage Form_Element
    32  * @subpackage Form_Element
    33  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    35  */
    35  */
    36 class Zend_Dojo_Form_Element_Editor extends Zend_Dojo_Form_Element_Dijit
    36 class Zend_Dojo_Form_Element_Editor extends Zend_Dojo_Form_Element_Dijit
    37 {
    37 {
    38     /**
    38     /**
   245      */
   245      */
   246     public function addPlugin($plugin)
   246     public function addPlugin($plugin)
   247     {
   247     {
   248         $plugin = (string) $plugin;
   248         $plugin = (string) $plugin;
   249         $plugins = $this->getPlugins();
   249         $plugins = $this->getPlugins();
   250         if (in_array($plugin, $plugins)) {
   250         if (in_array($plugin, $plugins) && $plugin !== '|') {
   251             return $this;
   251             return $this;
   252         }
   252         }
   253 
   253 
   254         $plugins[] = (string) $plugin;
   254         $plugins[] = (string) $plugin;
   255         $this->setDijitParam('plugins', $plugins);
   255         $this->setDijitParam('plugins', $plugins);
   444      * @param  string|int $minHeight
   444      * @param  string|int $minHeight
   445      * @return Zend_Dojo_Form_Element_Editor
   445      * @return Zend_Dojo_Form_Element_Editor
   446      */
   446      */
   447     public function setMinHeight($minHeight)
   447     public function setMinHeight($minHeight)
   448     {
   448     {
   449         if (!preg_match('/^\d+(em)?$/i', $minHeight)) {
   449         if (!preg_match('/^\d+(em|px|%)?$/i', $minHeight)) {
   450             require_once 'Zend/Form/Element/Exception.php';
   450             require_once 'Zend/Form/Element/Exception.php';
   451             throw new Zend_Form_Element_Exception('Invalid minHeight provided; must be integer or CSS measurement');
   451             throw new Zend_Form_Element_Exception('Invalid minHeight provided; must be integer or CSS measurement');
   452         }
   452         }
   453         if ('em' != substr($minHeight, -2)) {
   453         if (!preg_match('/(em|px|%)$/', $minHeight)) {
   454             $minHeight .= 'em';
   454             $minHeight .= 'em';
   455         }
   455         }
   456         return $this->setDijitParam('minHeight', $minHeight);
   456         return $this->setDijitParam('minHeight', $minHeight);
   457     }
   457     }
   458 
   458 
   594         if (!$this->hasDijitParam('updateInterval')) {
   594         if (!$this->hasDijitParam('updateInterval')) {
   595              return 200;
   595              return 200;
   596         }
   596         }
   597         return $this->getDijitParam('updateInterval');
   597         return $this->getDijitParam('updateInterval');
   598     }
   598     }
       
   599 
       
   600     /**
       
   601      * Add a single editor extra plugin.
       
   602      *
       
   603      * @param  string $plugin
       
   604      * @return Zend_Dojo_Form_Element_Editor
       
   605      */
       
   606     public function addExtraPlugin($plugin)
       
   607     {
       
   608         $plugin = (string) $plugin;
       
   609         $extraPlugins = $this->getExtraPlugins();
       
   610         if (in_array($plugin, $extraPlugins)) {
       
   611             return $this;
       
   612         }
       
   613     
       
   614         $extraPlugins[] = (string) $plugin;
       
   615         $this->setDijitParam('extraPlugins', $extraPlugins);
       
   616         return $this;
       
   617     }
       
   618     
       
   619     /**
       
   620      * Add multiple extra plugins.
       
   621      *
       
   622      * @param  array $extraPlugins
       
   623      * @return Zend_Dojo_Form_Element_Editor
       
   624      */
       
   625     public function addExtraPlugins(array $plugins)
       
   626     {
       
   627         foreach ($plugins as $plugin) {
       
   628             $this->addExtraPlugin($plugin);
       
   629         }
       
   630         return $this;
       
   631     }
       
   632     
       
   633     /**
       
   634      * Overwrite many extra plugins at once.
       
   635      *
       
   636      * @param  array $plugins
       
   637      * @return Zend_Dojo_Form_Element_Editor
       
   638      */
       
   639     public function setExtraPlugins(array $plugins)
       
   640     {
       
   641         $this->clearExtraPlugins();
       
   642         $this->addExtraPlugins($plugins);
       
   643         return $this;
       
   644     }
       
   645     
       
   646     /**
       
   647      * Get all extra plugins.
       
   648      *
       
   649      * @return array
       
   650      */
       
   651     public function getExtraPlugins()
       
   652     {
       
   653         if (!$this->hasDijitParam('extraPlugins')) {
       
   654             return array();
       
   655         }
       
   656         return $this->getDijitParam('extraPlugins');
       
   657     }
       
   658     
       
   659     /**
       
   660      * Is a given extra plugin registered?
       
   661      *
       
   662      * @param  string $plugin
       
   663      * @return bool
       
   664      */
       
   665     public function hasExtraPlugin($plugin)
       
   666     {
       
   667         $extraPlugins = $this->getExtraPlugins();
       
   668         return in_array((string) $plugin, $extraPlugins);
       
   669     }
       
   670     
       
   671     /**
       
   672      * Remove a given extra plugin.
       
   673      *
       
   674      * @param  string $plugin
       
   675      * @return Zend_Dojo_Form_Element_Editor
       
   676      */
       
   677     public function removeExtraPlugin($plugin)
       
   678     {
       
   679         $extraPlugins = $this->getExtraPlugins();
       
   680         if (false === ($index = array_search($plugin, $extraPlugins))) {
       
   681             return $this;
       
   682         }
       
   683         unset($extraPlugins[$index]);
       
   684         $this->setDijitParam('extraPlugins', $extraPlugins);
       
   685         return $this;
       
   686     }
       
   687     
       
   688     /**
       
   689      * Clear all extra plugins.
       
   690      *
       
   691      * @return Zend_Dojo_Form_Element_Editor
       
   692      */
       
   693     public function clearExtraPlugins()
       
   694     {
       
   695         return $this->removeDijitParam('extraPlugins');
       
   696     }
   599 }
   697 }