|
1 <?php |
|
2 /** |
|
3 * @file |
|
4 * Hooks provided by Masonry. |
|
5 */ |
|
6 |
|
7 /** |
|
8 * Alter Masonry's default options. |
|
9 * |
|
10 * @param $options |
|
11 * An associative array of option names and their default values. |
|
12 */ |
|
13 function hook_masonry_default_options_alter(&$options) { |
|
14 // Add default value for easing option |
|
15 $options['masonry_animation_easing'] = 'swing'; |
|
16 } |
|
17 |
|
18 /** |
|
19 * Alter the form that Masonry options are added to. |
|
20 * |
|
21 * @param $form |
|
22 * A form array. |
|
23 * @param $default_values |
|
24 * An array of default form values. |
|
25 */ |
|
26 function hook_masonry_options_form_alter(&$form, $default_values) { |
|
27 // Add form item for easing option |
|
28 $form['masonry_animation_easing'] = array( |
|
29 '#type' => 'select', |
|
30 '#title' => t('Animation easing'), |
|
31 '#description' => t("The easing function to use for animations."), |
|
32 '#options' => array( |
|
33 'linear' => t('Linear'), |
|
34 'swing' => t('Swing'), |
|
35 ), |
|
36 '#default_value' => $default_values['masonry_animation_easing'], |
|
37 '#states' => array( |
|
38 'visible' => array( |
|
39 'input.form-checkbox[name$="[masonry_resizable]"]' => array('checked' => TRUE), |
|
40 'input.form-checkbox[name$="[masonry_animated]"]' => array('checked' => TRUE), |
|
41 ), |
|
42 ), |
|
43 ); |
|
44 } |
|
45 |
|
46 /** |
|
47 * Alter the Masonry script. |
|
48 * |
|
49 * @param $masonry |
|
50 * An array of Masonry options to send to the script file. |
|
51 * @param $script_file |
|
52 * A path to the javascript file that triggers Masonry. |
|
53 * @param $context |
|
54 * An associative array of additional variables. |
|
55 * Contains: |
|
56 * - container: The CSS selector of the container element to apply Masonry to. |
|
57 * - options: An associative array of Masonry options. See masonry_apply(). |
|
58 */ |
|
59 function hook_masonry_script_alter(&$masonry, &$script_file, $context) { |
|
60 $container = $context['container']; |
|
61 $options = $context['options']; |
|
62 |
|
63 // Send easing option to the script file |
|
64 $masonry['masonry'][$container]['animation_easing'] = $options['masonry_animation_easing']; |
|
65 |
|
66 // Use a custom javascript file that includes easing in the animationOptions |
|
67 $script_file = drupal_get_path('module', '[MODULE_NAME]') . '/custom_masonry.js'; |
|
68 } |
|
69 |