-
Notifications
You must be signed in to change notification settings - Fork 2
/
breakpointsjs.module
68 lines (56 loc) · 1.93 KB
/
breakpointsjs.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
<?php
use Drupal\Component\Serialization\Json;
/**
* @file
* Breakpoints JS.
*/
/**
* Implements hook_page_attachments().
*/
function breakpointsjs_page_attachments(array &$attachments) {
$theme_name = \Drupal::theme()->getActiveTheme()->getName();
$attachments['#attached']['library'][] = 'breakpointsjs/breakpointsjs';
$theme_breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup($theme_name);
$settings = array();
foreach ($theme_breakpoints as $breakpoint) {
$settings[(string) $breakpoint->getLabel()]['name'] = (string) $breakpoint->getLabel();
$settings[(string) $breakpoint->getLabel()]['media_query'] = $breakpoint->getMediaQuery();
$settings[(string) $breakpoint->getLabel()]['multipliers'] = $breakpoint->getMultipliers();
}
$attachments['#attached']['drupalSettings']['breakpoints'] = $settings;
}
/**
* Implements hook_libraries_info().
*
* @todo: Keep track of libraries api, it us currently totally broken.
*/
function breakpointsjs_libraries_info() {
$libraries = array();
$libraries['enquire'] = array(
'name' => 'enquire.js',
'vendor url' => 'http://wicky.nillia.ms/enquire.js/',
'download url' => 'https://github.com/WickyNilliams/enquire.js/zipball/master',
'version callback' => 'breakpointsjs_libraries_enquire_version',
'files' => array(
'js' => array(
'dist/enquire.min.js' => array(
'every_page' => TRUE,
),
),
),
);
return $libraries;
}
/**
* Callback for enquire.js library version.
*
* @todo: Keep track of libraries api, it us currently totally broken.
*/
function breakpointsjs_libraries_enquire_version($library = array()) {
$package_json = libraries_get_path('enquire') . '/package.json';
if (!file_exists($package_json)) {
return NULL;
}
$decoded_json = JSON::decode(file_get_contents($package_json, TRUE));
return empty($decoded_json['version']) ? NULL : $decoded_json['version'];
}