XOOPS  2.6.0
ColorPicker.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
12 namespace Xoops\Form;
13 
26 class ColorPicker extends Text
27 {
35  public function __construct($caption, $name, $value = '#FFFFFF')
36  {
37  parent::__construct($caption, $name, 2, 7, $value, '');
38  }
39 
45  public function render()
46  {
48  if ($xoops->theme()) {
49  $xoops->theme()->addScript('include/color-picker.js');
50  } else {
51  echo '<script type="text/javascript" src="' . \XoopsBaseConfig::get('url') . '/include/color-picker.js"></script>';
52  }
53  $this->setExtra(' style="background-color:' . $this->getValue() . ';"');
54  return parent::render() . "<button class='btn' type='button' onclick=\"return TCP.popup('"
55  . \XoopsBaseConfig::get('url') . "/include/',document.getElementById('" . $this->getName() . "'));\"> ... </button>";
56 
57  }
58 
64  public function renderValidationJS()
65  {
66  $eltname = $this->getName();
67  $eltcaption = $this->getCaption();
68  $eltmsg = empty($eltcaption)
69  ? sprintf(\XoopsLocale::F_ENTER, $eltname)
70  : sprintf(\XoopsLocale::F_ENTER, $eltcaption);
71 
72  return "if ( !(new RegExp(\"^#[0-9a-fA-F]{6}\",\"i\").test(myform.{$eltname}.value)) )"
73  . " { window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }";
74  }
75 }
static getInstance()
Definition: Xoops.php:160
getValue($encode=false)
Definition: Element.php:180
const F_ENTER
Definition: en_US.php:408
$xoops
Definition: admin.php:25
static get($name)
setExtra($extra, $replace=false)
Definition: Element.php:522
__construct($caption, $name, $value= '#FFFFFF')
Definition: ColorPicker.php:35