| 1: | <?php | 
| 2: | /** | 
| 3: | * XoopsFormColorPicker component class file | 
| 4: | * | 
| 5: | * You may not change or alter any portion of this comment or credits | 
| 6: | * of supporting developers from this source code or any supporting source code | 
| 7: | * which is considered copyrighted (c) material of the original comment or credit authors. | 
| 8: | * This program is distributed in the hope that it will be useful, | 
| 9: | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 10: | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
| 11: | * | 
| 12: | * @copyright (c) 2000-2017 XOOPS Project (www.xoops.org) | 
| 13: | * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) | 
| 14: | * @package kernel | 
| 15: | * @subpackage form | 
| 16: | * @since 2.0.0 | 
| 17: | * @author Zoullou <webmaster@zoullou.org> | 
| 18: | */ | 
| 19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access'); | 
| 20: | |
| 21: | /** | 
| 22: | * Color Selection Field | 
| 23: | * | 
| 24: | * @author Zoullou <webmaster@zoullou.org> | 
| 25: | * @author John Neill <catzwolf@xoops.org> | 
| 26: | * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) | 
| 27: | * @package Kernel | 
| 28: | * @access public | 
| 29: | */ | 
| 30: | class XoopsFormColorPicker extends XoopsFormText | 
| 31: | { | 
| 32: | /** | 
| 33: | * XoopsFormColorPicker::XoopsFormColorPicker() | 
| 34: | * | 
| 35: | * @param mixed $caption | 
| 36: | * @param mixed $name | 
| 37: | * @param string $value | 
| 38: | */ | 
| 39: | public function __construct($caption, $name, $value = '#FFFFFF') | 
| 40: | { | 
| 41: | parent::__construct($caption, $name, 9, 7, $value); | 
| 42: | } | 
| 43: | |
| 44: | /** | 
| 45: | * XoopsFormColorPicker::render() | 
| 46: | * | 
| 47: | * @return string | 
| 48: | */ | 
| 49: | public function render() | 
| 50: | { | 
| 51: | return XoopsFormRenderer::getInstance()->get()->renderFormColorPicker($this); | 
| 52: | } | 
| 53: | |
| 54: | /** | 
| 55: | * Returns custom validation Javascript | 
| 56: | * | 
| 57: | * @return string Element validation Javascript | 
| 58: | */ | 
| 59: | public function renderValidationJS() | 
| 60: | { | 
| 61: | $eltname = $this->getName(); | 
| 62: | $eltcaption = $this->getCaption(); | 
| 63: | $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); | 
| 64: | |
| 65: | return "if ( !(new RegExp(\"^#[0-9a-fA-F]{6}\",\"i\").test(myform.{$eltname}.value)) ) { window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }"; | 
| 66: | } | 
| 67: | } | 
| 68: |