ColorpickerField   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 64
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A Field() 0 11 1
A setOptions() 0 4 1
A setColorMode() 0 4 1
1
<?php
2
3
class ColorpickerField extends TextField
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    /**
6
     * Spectrum Colorpicker Options
7
     *
8
     * 'color' => false,
9
     * 'flat' => false,
10
     * 'showInput' => false,
11
     * 'allowEmpty' => false,
12
     * 'showButtons' => true,
13
     * 'clickoutFiresChange' => true,
14
     * 'showInitial' => false,
15
     * 'showPalette' => false,
16
     * 'showPaletteOnly' => false,
17
     * 'hideAfterPaletteSelect' => false,
18
     * 'togglePaletteOnly' => false,
19
     * 'showSelectionPalette' => true,
20
     * 'localStorageKey' => false,
21
     * 'appendTo' => "body",
22
     * 'maxSelectionSize' => 7,
23
     * 'cancelText' => "cancel",
24
     * 'chooseText' => "choose",
25
     * 'togglePaletteMoreText' => "more",
26
     * 'togglePaletteLessText' => "less",
27
     * 'clearText' => "Clear Color Selection",
28
     * 'noColorSelectedText' => "No Color Selected",
29
     * 'preferredFormat' => false,
30
     * 'containerClassName' => "",
31
     * 'replacerClassName' => "",
32
     * 'showAlpha' => false,
33
     * 'theme' => "sp-light",
34
     * 'palette' => array("#ffffff", "#000000", "#ff0000", "#ff8000", "#ffff00", "#008000", "#0000ff", "#4b0082", "#9400d3"),
35
     * 'selectionPalette' => [],
36
     * 'disabled' => false,
37
     * 'offset' => null
38
     **/
39
 
40
  public function __construct($name, $title = null, $value = '', $form = null)
41
  {
42
      parent::__construct($name, $title, $value);
43
  }
44
45
    public function Field($properties = array())
46
    {
47
        $this->addExtraClass('spectrum-colorpickerfield');
48
49
        Requirements::css(SPECTRUM_COLORPICKER_DIR . '/bower_components/spectrum/spectrum.css');
50
        Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
51
        Requirements::javascript(SPECTRUM_COLORPICKER_DIR . '/bower_components/spectrum/spectrum.js');
52
        Requirements::javascript(SPECTRUM_COLORPICKER_DIR . '/javascript/colorpicker.js');
53
54
        return parent::Field($properties);
55
    }
56
57
    public function setOptions($options = array())
58
    {
59
        $this->setAttribute('data-spectrum-options', json_encode($options));
60
    }
61
62
    public function setColorMode()
63
    {
64
        $this->attributes['type'] = 'color';
65
    }
66
}
67