Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / superfish / superfish.module
1 <?php
2
3 /**
4  * @file
5  * The jQuery Superfish plugin for Drupal menus.
6  */
7
8 use Drupal\Core\Block\BlockPluginInterface;
9 use Drupal\Core\Routing\RouteMatchInterface;
10
11 /**
12  * Implements hook_block_view_BASE_BLOCK_ID_alter().
13  */
14 function superfish_block_view_superfish_alter(array &$build, BlockPluginInterface $block) {
15   $menu_name = $block->getDerivativeId();
16   $build['#contextual_links']['menu'] = [
17     'route_parameters' => ['menu' => $menu_name],
18   ];
19 }
20
21 /**
22  * Implements hook_libraries_info().
23  */
24 function superfish_libraries_info() {
25   $libraries['superfish'] = [
26     'name' => 'superfish',
27     'vendor url' => 'http://github.com/mehrpadin/Superfish-for-Drupal',
28     'download url' => 'https://github.com/mehrpadin/Superfish-for-Drupal/zipball/2.x',
29     'version callback' => 'superfish_library_version',
30     'files' => [
31       'js' => [
32         'superfish.js',
33         'jquery.hoverIntent.minified.js',
34         'sfsmallscreen.js',
35         'sftouchscreen.js',
36         'supersubs.js',
37         'supposition.js',
38       ],
39       'css' => [
40         'css/superfish.css',
41         'style/black/black.css',
42         'style/blue/blue.css',
43         'style/coffee/coffee.css',
44         'style/default/default.css',
45         'style/white/white.css',
46       ],
47     ],
48   ];
49   return $libraries;
50 }
51
52 /**
53  * Implements hook_library_info_build().
54  */
55 function superfish_library_info_build() {
56   $libraries = [];
57   if ($superfish_library_path = superfish_library_path()) {
58     $superfish_library_path = '/' . $superfish_library_path;
59     $libraries = [
60       'superfish' => [
61         'remote' => 'http://github.com/mehrpadin/Superfish-for-Drupal',
62         'version' => '2.0',
63         'license' => [
64           'name' => 'MIT',
65           'gpl-compatible' => FALSE,
66         ],
67         'js' => [
68           'js/superfish.js' => [],
69         ],
70         'dependencies' => [
71           'core/jquery',
72           'core/drupal',
73           'core/drupalSettings',
74           'core/jquery.once',
75         ],
76       ],
77       'init' => [
78         'js' => [
79           $superfish_library_path . '/superfish.js' => [],
80         ],
81         'css' => [
82           'base' => [
83             $superfish_library_path . '/css/superfish.css' => [],
84           ],
85         ],
86       ],
87       'superfish_hoverintent' => [
88         'js' => [
89           $superfish_library_path . '/jquery.hoverIntent.minified.js' => [
90             'minified' => TRUE,
91           ],
92         ],
93         'dependencies' => [
94           'superfish/init',
95         ],
96       ],
97       'superfish_smallscreen' => [
98         'js' => [
99           $superfish_library_path . '/sfsmallscreen.js' => [],
100         ],
101         'dependencies' => [
102           'superfish/init',
103         ],
104       ],
105       'superfish_touchscreen' => [
106         'js' => [
107           $superfish_library_path . '/sftouchscreen.js' => [],
108         ],
109         'dependencies' => [
110           'superfish/init',
111         ],
112       ],
113       'superfish_supersubs' => [
114         'js' => [
115           $superfish_library_path . '/supersubs.js' => [],
116         ],
117         'dependencies' => [
118           'superfish/init',
119         ],
120       ],
121       'superfish_supposition' => [
122         'js' => [
123           $superfish_library_path . '/supposition.js' => [],
124         ],
125         'dependencies' => [
126           'superfish/init',
127         ],
128       ],
129       'superfish_style_black' => [
130         'css' => [
131           'theme' => [
132             $superfish_library_path . '/style/black/black.css' => [],
133           ],
134         ],
135         'dependencies' => [
136           'superfish/init',
137         ],
138       ],
139       'superfish_style_blue' => [
140         'css' => [
141           'theme' => [
142             $superfish_library_path . '/style/blue/blue.css' => [],
143           ],
144         ],
145         'dependencies' => [
146           'superfish/init',
147         ],
148       ],
149       'superfish_style_coffee' => [
150         'css' => [
151           'theme' => [
152             $superfish_library_path . '/style/coffee/coffee.css' => [],
153           ],
154         ],
155         'dependencies' => [
156           'superfish/init',
157         ],
158       ],
159       'superfish_style_default' => [
160         'css' => [
161           'theme' => [
162             $superfish_library_path . '/style/default/default.css' => [],
163           ],
164         ],
165         'dependencies' => [
166           'superfish/init',
167         ],
168       ],
169       'superfish_style_white' => [
170         'css' => [
171           'theme' => [
172             $superfish_library_path . '/style/white/white.css' => [],
173           ],
174         ],
175         'dependencies' => [
176           'superfish/init',
177         ],
178       ],
179     ];
180     if ($easing_library_path = superfish_library_path('easing')) {
181       $easing_library_path = '/' . $easing_library_path;
182       $libraries += [
183         'superfish_easing' => [
184           'js' => [
185             $easing_library_path . '/jquery.easing.js' => [],
186           ],
187         ],
188       ];
189     }
190   }
191   return $libraries;
192 }
193
194 /**
195  * Returns the Superfish library folder location.
196  */
197 function superfish_library_path($library = 'superfish') {
198   $directory = FALSE;
199   // Ensure the Libraries API module is installed and working.
200   if (function_exists('libraries_get_path') && ($directory = libraries_get_path($library))) {
201     return $directory;
202   }
203   // Otherwise use the default directory.
204   if (file_exists('profiles/' . drupal_get_profile() . '/libraries/' . $library)) {
205     $directory = 'profiles/' . drupal_get_profile() . '/libraries/' . $library;
206   }
207   elseif (file_exists('libraries/' . $library)) {
208     $directory = 'libraries/' . $library;
209   }
210   elseif (file_exists('sites/all/libraries/' . $library)) {
211     $directory = 'sites/all/libraries/' . $library;
212   }
213   elseif (file_exists('sites/default/libraries/' . $library)) {
214     $directory = 'sites/default/libraries/' . $library;
215   }
216   return $directory;
217 }
218
219 /**
220  * Verifies Superfish library is present.
221  */
222 function superfish_library_check() {
223   if (function_exists('libraries_get_libraries')) {
224     $library = libraries_get_libraries();
225     if (isset($library['superfish'])) {
226       return TRUE;
227     }
228   }
229   elseif (($directory = superfish_library_path()) && file_exists($directory . '/superfish.js')) {
230     return TRUE;
231   }
232   return FALSE;
233 }
234
235 /**
236  * Checks Superfish library version.
237  */
238 function superfish_library_version() {
239   // Get the library version.
240   if (($directory = superfish_library_path()) && file_exists($directory . '/VERSION')) {
241     $version = file_get_contents($directory . '/VERSION');
242     // Removing blank lines and white spaces.
243     $version = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", trim($version));
244     if (!empty($version)) {
245       return $version;
246     }
247     return FALSE;
248   }
249   return FALSE;
250 }
251
252 /**
253  * Generate a list of available slide-in effects.
254  */
255 function superfish_effects() {
256   $output = [
257     'none' => '- ' . t('None') . ' -',
258     'vertical' => t('Vertical'),
259     'horizontal' => t('Horizontal'),
260     'diagonal' => t('Diagonal'),
261   ];
262
263   if (superfish_library_path('easing')) {
264     $easing_types = [
265       'easeInSine_vertical' => 'easeInSine (' . t('Vertical') . ')',
266       'easeInSine_horizontal' => 'easeInSine (' . t('Horizontal') . ')',
267       'easeInSine_diagonal' => 'easeInSine (' . t('Diagonal') . ')',
268       'easeInQuint_vertical' => 'easeInQuint (' . t('Vertical') . ')',
269       'easeInQuint_horizontal' => 'easeInQuint (' . t('Horizontal') . ')',
270       'easeInQuint_diagonal' => 'easeInQuint (' . t('Diagonal') . ')',
271       'easeInQuart_vertical' => 'easeInQuart (' . t('Vertical') . ')',
272       'easeInQuart_horizontal' => 'easeInQuart (' . t('Horizontal') . ')',
273       'easeInQuart_diagonal' => 'easeInQuart (' . t('Diagonal') . ')',
274       'easeInQuad_vertical' => 'easeInQuad (' . t('Vertical') . ')',
275       'easeInQuad_horizontal' => 'easeInQuad (' . t('Horizontal') . ')',
276       'easeInQuad_diagonal' => 'easeInQuad (' . t('Diagonal') . ')',
277       'easeInExpo_vertical' => 'easeInExpo (' . t('Vertical') . ')',
278       'easeInExpo_horizontal' => 'easeInExpo (' . t('Horizontal') . ')',
279       'easeInExpo_diagonal' => 'easeInExpo (' . t('Diagonal') . ')',
280       'easeInElastic_vertical' => 'easeInElastic (' . t('Vertical') . ')',
281       'easeInElastic_horizontal' => 'easeInElastic (' . t('Horizontal') . ')',
282       'easeInElastic_diagonal' => 'easeInElastic (' . t('Diagonal') . ')',
283       'easeInCubic_vertical' => 'easeInCubic (' . t('Vertical') . ')',
284       'easeInCubic_horizontal' => 'easeInCubic (' . t('Horizontal') . ')',
285       'easeInCubic_diagonal' => 'easeInCubic (' . t('Diagonal') . ')',
286       'easeInCirc_vertical' => 'easeInCirc (' . t('Vertical') . ')',
287       'easeInCirc_horizontal' => 'easeInCirc (' . t('Horizontal') . ')',
288       'easeInCirc_diagonal' => 'easeInCirc (' . t('Diagonal') . ')',
289       'easeInBounce_vertical' => 'easeInBounce (' . t('Vertical') . ')',
290       'easeInBounce_horizontal' => 'easeInBounce (' . t('Horizontal') . ')',
291       'easeInBounce_diagonal' => 'easeInBounce (' . t('Diagonal') . ')',
292       'easeInBack_vertical' => 'easeInBack (' . t('Vertical') . ')',
293       'easeInBack_horizontal' => 'easeInBack (' . t('Horizontal') . ')',
294       'easeInBack_diagonal' => 'easeInBack (' . t('Diagonal') . ')',
295     ];
296     $output = array_merge($output, $easing_types);
297   }
298   return $output;
299 }
300
301 /**
302  * Helper function to clean up arrays.
303  */
304 function sf_array_filter($haystack) {
305   foreach ($haystack as $key => $value) {
306     if (is_array($value)) {
307       $haystack[$key] = sf_array_filter($haystack[$key]);
308     }
309     elseif (empty($value) && is_bool($value) !== TRUE) {
310       if ($haystack[$key] != '0') {
311         unset($haystack[$key]);
312       }
313     }
314   }
315   return $haystack;
316 }
317
318 /**
319  * Implements hook_theme().
320  */
321 function superfish_theme($existing, $type, $theme, $path) {
322   return [
323     'superfish' => [
324       'render element' => 'element',
325       'file' => 'superfish.theme.inc',
326     ],
327     'superfish_menu_items' => [
328       'render element' => 'element',
329       'file' => 'superfish.theme.inc',
330     ],
331     'superfish_help' => [
332       'variables' => [
333         'title' => NULL,
334         'content' => NULL,
335       ],
336       'template' => 'superfish--help',
337     ],
338   ];
339 }
340
341 /**
342  * Implements hook_help().
343  */
344 function superfish_help($route_name, RouteMatchInterface $route_match) {
345   switch ($route_name) {
346     case 'help.page.superfish':
347       $output = [
348         '#theme' => 'superfish_help',
349         '#title' => t('About Superfish'),
350         '#content' => t('<a href="@url_module">Superfish module</a> integrates <a href="@url_library">jQuery Superfish</a> plugin to your Drupal menu blocks. Please refer to the module <a href="@url_documentation">documentation</a> for more information.',
351       [
352         '@url_library' => 'https://github.com/mehrpadin/Superfish-for-Drupal',
353         '@url_module' => 'https://www.drupal.org/project/superfish',
354         '@url_documentation' => 'https://www.drupal.org/node/1125896',
355       ]
356         ),
357       ];
358       return $output;
359   }
360 }