-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery_ui.module
149 lines (129 loc) · 4.1 KB
/
jquery_ui.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* @file
* Provides the jQuery UI plug-in to other Drupal modules.
*
* This module doesn't do too much, but it is a central location for any other
* modules that implement the JQuery UI library. It ensures that multiple
* modules will all include the same library script just once on any given page.
*/
/**
* Add the specified jQuery UI library files to this page.
*
* The ui.core file is always included automatically, as well as the
* effects.core file if any of the effects libraries are used.
*
* @param $files
* An array of what additional files (other than UI core) should be loaded
* on the page, or a string with a single file name.
*/
function jquery_ui_add($files = array()) {
static $loaded_files, $dependencies = array();
$jquery_ui_path = jquery_ui_get_path();
if ($jquery_ui_path === FALSE) {
return FALSE;
}
$jquery_ui_path .= '/ui';
$compression = variable_get('jquery_update_compression_type', 'mini');
$jquery_ui_version = version_compare(jquery_ui_get_version(), '1.8', '>=') ? 'jquery.' : '';
if (empty($dependencies)) {
$cache_dependencies = cache_get('jquery_ui_dependencies');
if ($cache_dependencies->data) {
$dependencies = $cache_dependencies->data;
}
}
// Convert file to an array if it's not one already, to compensate for
// lazy developers. ;)
if (!is_array($files)) {
$files = array($files);
}
// Loop through list of files to include and add them to the page.
foreach ($files as $file) {
$file = $jquery_ui_version . $file;
// Load other files.
if (!isset($loaded_files[$file])) {
switch ($compression) {
case 'none':
$file_path = "$file.js";
break;
case 'pack':
$file_path = "packed/$file.packed.js";
break;
case 'mini':
default:
$file_path = "minified/$file.min.js";
break;
}
$js_path = $jquery_ui_path . '/' . $file_path;
if (!isset($dependencies[$file])) {
$file_contents = file_get_contents($js_path);
preg_match('/^\/\*.*Depends:(.*?)\*\//ismu', $file_contents, $matches);
preg_match_all('/\s*\*\s*(jquery\.)?(.+)\n/miu', $matches[1], $depends);
$dependencies[$file] = $depends[2];
foreach ($dependencies[$file] as &$depend) {
$depend = basename(trim($depend), '.js');
}
}
if (!empty($dependencies[$file])) {
jquery_ui_add($dependencies[$file]);
}
drupal_add_js($js_path);
$loaded_files[$file] = $js_path;
}
}
cache_set('jquery_ui_dependencies', $dependencies);
}
/**
* Returns the path to the jQuery UI library or FALSE if not found.
*/
function jquery_ui_get_path() {
static $path;
if (isset($path)) {
return $path;
}
$path = FALSE;
// Libraries API integration.
if (function_exists('libraries_get_path')) {
$path = libraries_get_path('jquery.ui');
// Earlier/current versions of Libraries API return a default path; only
// later versions return FALSE.
if ($path !== FALSE && !file_exists($path)) {
$path = FALSE;
}
}
// Manually check sites/all/libraries in case Libraries API is not available.
elseif (file_exists('./sites/all/libraries/jquery.ui')) {
$path = 'sites/all/libraries/jquery.ui';
}
// Check the module directory for backwards compatibility.
else {
// drupal_get_path() is not available during Drupal installation.
if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install') {
$path = drupal_substr(dirname(__FILE__), drupal_strlen(getcwd()) + 1);
$path = strtr($path, '\\', '/');
$path .= '/jquery.ui';
}
else {
$path = drupal_get_path('module', 'jquery_ui') . '/jquery.ui';
}
if (!file_exists($path)) {
$path = FALSE;
}
}
return $path;
}
/**
* Return the version of jQuery UI installed.
*/
function jquery_ui_get_version() {
$version = 0;
$path = jquery_ui_get_path();
if ($path === FALSE) {
return $version;
}
$file = $path . '/version.txt';
if (file_exists($file)) {
$version = file_get_contents($file);
}
return $version;
}