forked from baumrock/RockAwesome
-
Notifications
You must be signed in to change notification settings - Fork 1
/
InputfieldRockAwesome.module.php
79 lines (66 loc) · 2.36 KB
/
InputfieldRockAwesome.module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php namespace ProcessWire;
/**
* Inputfield for selecting Fontawesome Icons
*
* @author Bernhard Baumrock, 20.11.2019
* @license Licensed under MIT
* @link https://www.baumrock.com
*/
class InputfieldRockAwesome extends InputfieldText {
public static function getModuleInfo() {
return [
'title' => 'RockAwesome', // Module Title
'summary' => 'FontAwesome Icon Chooser', // Module Summary
'version' => '0.0.6',
'icon' => 'star-o',
'requires' => ['FieldtypeRockAwesome'],
];
}
/**
* Init module
*/
public function init() {
$this->stylesheet = $this->config->paths->root . $this->stylesheet;
if(!is_file($this->stylesheet)) return;
$style = str_replace($this->config->paths->root, $this->config->urls->root, $this->stylesheet);
$this->config->styles->add($style);
// Versionsinfos und gewünschte Icon-Styles in JS bekannt machen
$this->config->js('RockAwesomeVersion', $this->fa_version);
$this->config->js('RockAwesomeMembership', $this->fa_membership);
$this->config->js('RockAwesomeRegular', $this->far);
$this->config->js('RockAwesomeSolid', $this->fas);
$this->config->js('RockAwesomeLight', $this->fal);
$this->config->js('RockAwesomeThin', $this->fat);
$this->config->js('RockAwesomeDuotone', $this->fad);
$this->config->js('RockAwesomeBrands', $this->fab);
$this->addHookBefore("render", function($event) {
$n = $event->object->notes ? "\n" : "";
$notes = $n.__("Start typing to find icons");
$orgoto = __("or go to the icon cheatsheet");
$notes .= $this->link
? " [$orgoto]({$this->link})."
: "...";
$event->object->notes .= $notes;
});
}
/**
* Render Inputfield
*
* @return string
*
*/
public function ___render() {
$attrStr = $this->getAttributesString();
$id = uniqid();
$out = "<div class='RockAwesome ra_$id'>"
."<div class='uk-inline uk-width-1-1'>"
."<span class='uk-form-icon'><i></i></span>"
// ."<span class='uk-form-icon uk-spinner'><i class='fa fa-spinner'></i></span>"
."<input $attrStr />"
."</div>"
."<div class='icons uk-margin-small-top uk-child-width-1-2 uk-child-width-1-3@s uk-child-width-1-4@m uk-child-width-1-6@l uk-grid-small' uk-grid></div>"
."</div>"
."<script>$('.ra_$id input').change();</script>";
return $out;
}
}