-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSelect2Plugin.php
72 lines (61 loc) · 1.62 KB
/
Select2Plugin.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
<?php
/**
* @file
* Select2 plugin main file.
*/
/**
* Select2 plugin main class.
*/
class Select2Plugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = array(
'install',
'uninstall',
'initialize',
'admin_head',
'config_form',
'config',
);
protected $_options = array(
'select2_css_selector' => 'body.item-types select.existing-element-drop-down, body.advanced-search select.advanced-search-element',
);
public function hookInstall()
{
$this->_installOptions();
}
public function hookUninstall()
{
$this->_uninstallOptions();
}
/**
* Set up plugins, translations, and filters
*/
public function hookInitialize()
{
add_translation_source(dirname(__FILE__) . '/languages');
}
public function hookAdminHead()
{
$selector = get_option('select2_css_selector');
if ($selector) {
queue_js_file('select2.min');
queue_css_file('select2.min');
$selector = preg_replace('/\s+/', ' ', $selector);
$selector = json_encode($selector);
queue_js_string("
Omeka.Select2 = {};
Omeka.Select2.CssSelector = $selector;
");
queue_js_file('select2_apply');
}
}
public function hookConfigForm()
{
require dirname(__FILE__) . '/config_form.php';
}
public function hookConfig($args)
{
$select2_css_selector = $args['post']['select2_css_selector'];
set_option('select2_css_selector', $select2_css_selector);
}
}