function mmenu_add_js in Mobile sliding menu 7
Same name and namespace in other branches
- 7.3 mmenu.module \mmenu_add_js()
- 7.2 mmenu.module \mmenu_add_js()
Generates the mmenu js handler scripts and adds to Drupal.
Parameters
array $mmenu: An associative array of a mmenu.
1 call to mmenu_add_js()
- template_preprocess_mmenu in ./
mmenu.module - Processes variables for mmenu.tpl.php.
File
- ./
mmenu.module, line 712 - Primarily Drupal hooks and global API functions to manipulate mmenus.
Code
function mmenu_add_js($mmenu = array()) {
// Uses custom js handler if it is set.
if (isset($mmenu['custom']['js'])) {
foreach ($mmenu['custom']['js'] as $js) {
drupal_add_js($js);
}
return;
}
// Updates the value of the classes with the combination of
// classes and effects.
$mmenu['options']['classes'] = mmenu_get_all_classes($mmenu);
$options = drupal_json_encode($mmenu['options']);
$configurations = drupal_json_encode($mmenu['configurations']);
$selector_event = '';
if (isset($mmenu['options']['clickOpen']['selector'])) {
$selector = check_plain($mmenu['options']['clickOpen']['selector']);
$selector_event = '$("' . $selector . '").click(function(e) {
e.preventDefault();
$' . $mmenu['name'] . '.trigger("open.mm");
});';
}
$js = '(function ($) {
$(document).ready(function() {
var $' . $mmenu['name'] . ' = $("#' . $mmenu['name'] . '");
$' . $mmenu['name'] . '.mmenu(' . $options . ', ' . $configurations . ');
' . $selector_event . '
});
}(jQuery));';
// Adds inline javascript.
drupal_add_js($js, 'inline');
}