1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Dash - Form element for color picker.
|
|
|
19 |
*
|
|
|
20 |
* @package block_dash
|
|
|
21 |
* @copyright 2021 bdecent gmbh <https://bdecent.de>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
require_once('HTML/QuickForm/input.php');
|
|
|
28 |
require_once($CFG->dirroot.'/lib/form/templatable_form_element.php');
|
|
|
29 |
require_once($CFG->dirroot.'/lib/form/text.php');
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Form element for color picker.
|
|
|
33 |
*
|
|
|
34 |
* @package block_dash
|
|
|
35 |
* @copyright 2021 bdecent gmbh <https://bdecent.de>
|
|
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
37 |
*/
|
|
|
38 |
class moodlequickform_dashgradientpicker extends MoodleQuickForm_text implements templatable {
|
|
|
39 |
|
|
|
40 |
use templatable_form_element {
|
|
|
41 |
export_for_template as export_for_template_base;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Constructor.
|
|
|
46 |
*
|
|
|
47 |
* @param string $elementname (optional) Name of the text field.
|
|
|
48 |
* @param string $elementlabel (optional) Text field label.
|
|
|
49 |
* @param string $attributes (optional) Either a typical HTML attribute string or an associative array.
|
|
|
50 |
*/
|
|
|
51 |
public function __construct($elementname=null, $elementlabel=null, $attributes=null) {
|
|
|
52 |
parent::__construct($elementname, $elementlabel, $attributes);
|
|
|
53 |
$this->setType('text');
|
|
|
54 |
|
|
|
55 |
// Add a CSS class for styling the color picker.
|
|
|
56 |
$class = $this->getAttribute('class');
|
|
|
57 |
if (empty($class)) {
|
|
|
58 |
$class = '';
|
|
|
59 |
}
|
|
|
60 |
$this->updateAttributes(['class' => $class.' block_dash-form-gradient-picker']);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Export for template.
|
|
|
65 |
*
|
|
|
66 |
* @param renderer_base $output
|
|
|
67 |
* @return array|stdClass
|
|
|
68 |
*/
|
|
|
69 |
public function export_for_template(renderer_base $output) {
|
|
|
70 |
global $PAGE;
|
|
|
71 |
|
|
|
72 |
// Compose template context for the mform element.
|
|
|
73 |
$context = $this->export_for_template_base($output);
|
|
|
74 |
|
|
|
75 |
$PAGE->requires->js_amd_inline('require(["jquery", "block_dash/gradient"], function($) {
|
|
|
76 |
var background = document.querySelectorAll("input[name=config_backgroundgradient]")[0];
|
|
|
77 |
if (background) {
|
|
|
78 |
new lc_color_picker(background, {
|
|
|
79 |
modes : ["linear-gradient", "solid"],
|
|
|
80 |
});
|
|
|
81 |
}
|
|
|
82 |
})'
|
|
|
83 |
);
|
|
|
84 |
|
|
|
85 |
return $context;
|
|
|
86 |
}
|
|
|
87 |
}
|