|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LeKoala\FormElements; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Forms\TextField; |
|
6
|
|
|
use SilverStripe\View\Requirements; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @link https://github.com/mdbassit/Coloris |
|
10
|
|
|
* @link https://gist.github.com/lekoala/233b0c6246170716c52dbfab342caf22 |
|
11
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color |
|
12
|
|
|
*/ |
|
13
|
|
|
class ColorField extends TextField implements LocalizableField |
|
14
|
|
|
{ |
|
15
|
|
|
use BaseElement; |
|
16
|
|
|
use Localize; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Override locale. If empty will default to current locale |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $locale = null; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @config |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
private static $default_config = []; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @config |
|
33
|
|
|
* @var boolean |
|
34
|
|
|
*/ |
|
35
|
|
|
private static $enable_requirements = true; |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
public function __construct($name, $title = null, $value = '', $maxLength = null, $form = null) |
|
38
|
|
|
{ |
|
39
|
|
|
parent::__construct($name, $title, $value, $maxLength, $form); |
|
40
|
|
|
$this->mergeDefaultConfig(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getInputType() |
|
44
|
|
|
{ |
|
45
|
|
|
return 'text'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function Type() |
|
49
|
|
|
{ |
|
50
|
|
|
return 'coloris'; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getSwatches() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getConfig('swatches'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function setSwatches($values) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->setConfig('swatches', $values); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function Field($properties = array()) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->wrapInElement('coloris-input', $properties); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public static function requirements() |
|
69
|
|
|
{ |
|
70
|
|
|
Requirements::javascript("lekoala/silverstripe-form-elements: client/custom-elements/coloris-input.min.js"); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|