1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Licensed under The GPL-3.0 License |
4
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
5
|
|
|
* Redistributions of files must retain the above copyright notice. |
6
|
|
|
* |
7
|
|
|
* @since 2.0.0 |
8
|
|
|
* @author Christopher Castro <[email protected]> |
9
|
|
|
* @link http://www.quickappscms.org |
10
|
|
|
* @license http://opensource.org/licenses/gpl-3.0.html GPL-3.0 License |
11
|
|
|
*/ |
12
|
|
|
namespace CMS\View\Widget; |
13
|
|
|
|
14
|
|
|
use Cake\View\Form\ContextInterface; |
15
|
|
|
use Cake\View\Widget\WidgetInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Color picker input class. |
19
|
|
|
* |
20
|
|
|
* Provides a JavaScript color wheel for picking colors. |
21
|
|
|
*/ |
22
|
|
|
class FontPanelWidget implements WidgetInterface |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* StringTemplate instance. |
27
|
|
|
* |
28
|
|
|
* @var \Cake\View\StringTemplate |
29
|
|
|
*/ |
30
|
|
|
protected $_templates; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Instance of View. |
34
|
|
|
* |
35
|
|
|
* @var \Cake\View\View |
36
|
|
|
*/ |
37
|
|
|
protected $_View = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Constructor. |
41
|
|
|
* |
42
|
|
|
* @param \Cake\View\StringTemplate $templates Templates list. |
43
|
|
|
* @param \Cake\View\View $view Instance of View |
44
|
|
|
*/ |
45
|
|
|
public function __construct($templates, $view) |
46
|
|
|
{ |
47
|
|
|
$this->_templates = $templates; |
48
|
|
|
$this->_View = $view; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Render a color picker widget. |
53
|
|
|
* |
54
|
|
|
* @param array $data The data to build an input with. |
55
|
|
|
* @param \Cake\View\Form\ContextInterface $context The current form context. |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function render(array $data, ContextInterface $context) |
59
|
|
|
{ |
60
|
|
|
$data += [ |
61
|
|
|
'name' => '', |
62
|
|
|
'val' => null, |
63
|
|
|
'type' => 'text', |
64
|
|
|
'escape' => true, |
65
|
|
|
]; |
66
|
|
|
$data['value'] = $data['val']; |
67
|
|
|
$data['readonly'] = 'readonly'; |
68
|
|
|
unset($data['val']); |
69
|
|
|
$this->_loadAssets(); |
70
|
|
|
|
71
|
|
|
$data['class'] = !empty($data['class']) ? "{$data['class']} fontselector" : 'fontselector'; |
72
|
|
|
|
73
|
|
|
return $this->_templates->format('input', [ |
74
|
|
|
'name' => $data['name'], |
75
|
|
|
'type' => 'text', |
76
|
|
|
'attrs' => $this->_templates->formatAttributes( |
77
|
|
|
$data, |
78
|
|
|
['name', 'type'] |
79
|
|
|
), |
80
|
|
|
]) . '<p id="' . $data['id'] . '-preview" style="font:' . $data['value'] . ';">Example text</p>'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritDoc} |
85
|
|
|
*/ |
86
|
|
|
public function secureFields(array $data) |
87
|
|
|
{ |
88
|
|
|
return [$data['name']]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Load all CSS and JS assets required for this widget. |
93
|
|
|
* |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
protected function _loadAssets() |
97
|
|
|
{ |
98
|
|
|
$this->_View->Html->css('System./font-panel/fontpanel.css', ['block' => true]); |
99
|
|
|
$this->_View->Html->script('System./font-panel/fontpanel.js', ['block' => true]); |
100
|
|
|
$this->_View->Html->script('System./font-panel/font-panel-init.js', ['block' => true]); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|