-
Notifications
You must be signed in to change notification settings - Fork 1
/
e3_js.module
executable file
·101 lines (84 loc) · 2.76 KB
/
e3_js.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
<?php
/**
* @file e3_js.module
* Creates e3_js config, loads correct version of js
*/
/**
* Implements hook_init().
*/
function e3_js_init() {
$env = variable_get('e3_js_prod', '0');
// Decide whether to use the production version.
if(!is_null($env)) {
switch($env) {
case 0:
$script = 'e3_js.js';
break;
case 1:
$script = 'e3_js.min.js';
break;
}
} else {
watchdog('e3_js has not been configured.', WATCHDOG_ERROR);
// Assume we don't need debug mode
$script = 'e3_js.min.js';
}
// If not configured otherwise, only load script on front-end pages
if (variable_get('e3_js_admin') || arg(0) != 'admin') {
$js_path = drupal_get_path('module', 'e3_js') . '/' . $script;
drupal_add_js($js_path,
array(
'weight' => -50,
'scope' => 'header',
'preprocess' => true
), 'setting'
);
// Adds content of arg to e3 object.
drupal_add_js(array('e3' => array('arg' => arg())),
array('type' => 'setting'));
}
}
/**
* Implements hook_menu().
*/
function e3_js_menu(){
$items = array();
$items['admin/config/development/e3js'] = array(
'title' => 'e3_js',
'description' => 'Configuration for the e3_js library.',
'page callback' => 'drupal_get_form',
'page arguments' => array('e3_js_admin_form'),
'access arguments' => array('access devel information'),
);
return $items;
}
/**
* Creates the admin settings form.
* @return mixed
*/
function e3_js_admin_form() {
$form['header'] = array(
'#markup' => '<div style="padding:10px;border:1px solid #BEBFB9;margin-bottom:10px;"><p>This module loads the e3_js.js structure for modular javascript development into Drupal. For more information about implementation and usage, see the <a href="https://github.com/rgkimball/e3_js" target="_blank">e3_js GitHub repository</a>.</p></div>',
);
$form['e3_js_prod'] = array(
'#type' => 'checkbox',
'#title' => t('Use minified js'),
'#description' => t('If unchecked, the unminified version will be loaded to allow debugging. It is recommended to define this in settings.php to automatically configure site environments appropriately.'),
'#default_value' => variable_get('e3_js_prod', 0),
);
$form['e3_js_admin'] = array(
'#type' => 'checkbox',
'#title' => t('Load on admin pages.'),
'#default_value' => variable_get('e3_js_admin', 0),
'#description' => t('If checked, e3_js will be added to admin pages as well.')
);
return system_settings_form($form);
}
/**
* Implements hook_block_view_alter().
* Send block IDs to js for contextual operations.
*/
function e3_js_block_view_alter(&$data, $block) {
drupal_add_js(array('e3' => array('blocks' => array("$block->bid"))),
array('type' => 'setting'));
}