-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputfieldFontIcon.module
113 lines (93 loc) · 3.5 KB
/
InputfieldFontIcon.module
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php namespace ProcessWire;
class InputfieldFontIcon extends Inputfield {
protected $libraryUrl;
public static function getModuleInfo() {
return array(
'title' => 'InputfieldFontIcon',
'summary' => 'Simplified version of input field font icons field type.',
'version' => 1,
'author' => 'Oluic Sasa',
'href' => 'http://olsa.me',
'icon' => 'flag',
'requires' => array(
'FieldtypeFontIcon',
)
);
}
// Construct and establish default settings
public function __construct() {
parent::__construct();
$this->libraryUrl = $this->config->urls->FieldtypeFontIcon . 'Libraries/fontIconPicker-2.0.0/';
$this->set('css_url', '');
$this->set('prefix', '');
$this->set('regex_pattern', '/\.(.*?):before/');
$this->set('exclude_list', '');
}
public function init() {
parent::init();
$this->config->styles->add($this->libraryUrl . "css/jquery.fonticonpicker.css");
$this->config->styles->add($this->libraryUrl . "themes/grey-theme/jquery.fonticonpicker.grey.min.css");
$this->config->scripts->add($this->libraryUrl . "jquery.fonticonpicker.js");
}
public function ___render() {
// load field css file.
$this->config->styles->add($this->config->urls->templates . $this->css_url);
$name = $this->attr('name');
$this->setAttribute('value', $this->attr('value'));
$icons = array();
$file_path = $this->config->paths->templates . $this->css_url;
$file_content = '';
if(file_exists($file_path))
{
$file = fopen($file_path, "r");
$file_content = fread($file, filesize($file_path));
fclose($file);
// parse icons css file
preg_match_all($this->regex_pattern, $file_content, $matches);
$icons = $matches[1];
}
// check and set prefix classes (if any)
$prefix = (trim($this->prefix) !== '') ? trim($this->prefix) . ' ' : '';
$f = $this->modules->get('InputfieldSelect');
foreach($icons as $opt) {
$f->addOption($prefix . $opt, $opt);
}
$f->attr('name', $this->attr('name'));
$f->attr('value', $this->attr('value'));
$output = $f->render();
$output.= "<script type='text/javascript'>
$(document).ready(function() {
$('#Inputfield_{$this->attr("name")}').fontIconPicker();
});
</script>";
return $output;
}
public function ___getConfigInputfields() {
$inputfields = parent::___getConfigInputfields();
// CSS file path
$field = $this->modules->get('InputfieldText');
$field->attr('name', 'css_url');
$field->attr('value', $this->css_url);
$field->label = __('Icons CSS file');
$field->description = __('Path relative to templates folder.');
$field->columnWidth = 50;
$inputfields->add($field);
// icons prefix classes
$field = $this->modules->get('InputfieldText');
$field->attr('name', 'prefix');
$field->attr('value', $this->prefix);
$field->label = __('Icon class prefix');
$field->description = __('Example: fa or ico, or multiple separated by single space.');
$field->columnWidth = 50;
$inputfields->add($field);
// regular expression pattern
$field = $this->modules->get('InputfieldText');
$field->attr('name', 'regex_pattern');
$field->attr('value', $this->regex_pattern);
$field->label = __('Regular expression pattern parser');
$field->description = __('Example: /\.(.*?):before/');
$field->columnWidth = 100;
$inputfields->add($field);
return $inputfields;
}
}