Skip to content

Instantly share code, notes, and snippets.

@ccamara
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccamara/2fbf81ddf11c91c2190f to your computer and use it in GitHub Desktop.
Save ccamara/2fbf81ddf11c91c2190f to your computer and use it in GitHub Desktop.
Insert an external library to your drupal7 theme #mmenu
// We should add our js definition into our theme's js folder.
/**
* @file
* A JavaScript file for the Main Menu Responsive behaviour.
*/
(function ($, Drupal, window, document, undefined) {
"use strict";
// Reset ww value.
var ww = null;
Drupal.behaviors.fvfZenMaimenuResponsive= {
attach: function(context, settings) {
ww = document.body.clientWidth;
startMmenu();
// Check on resize page.
$(window).bind('resize orientationchange', function() {
ww = document.body.clientWidth;
startMmenu();
});
}
};
/**
* Start Mmenu element for left sliding Main menu only on mobile.
*/
var startMmenu = function() {
var mbreakpoint = 736;
if ((ww < mbreakpoint) && (!$('.mm-page').length) ) {
$('#navigation').mmenu({
slidingSubmenus: false,
isMenu: true,
}, {
listClass: 'menu',
});
$("#navigation-open").bind('click', function(e) {
e.preventDefault();
$("#navigation").trigger("open.mm");
});
$("#navigation-close").bind('click', function(e) {
e.preventDefault();
$("#navigation").trigger("close.mm");
});
}
else if (ww >= mbreakpoint && $('.mm-page').length ) {
$('#navigation').appendTo('#header .header__content').removeClass('mm-menu mm-vertical mm-offcanvas');
}
else if ((ww < mbreakpoint) && $('.mm-page').length) {
$('#navigation').prependTo('body').addClass('mm-menu mm-vertical mm-offcanvas');
}
}
})(jQuery, Drupal, this, this.document);
<?php
/**
* @file
* Contains the theme's functions to manipulate Drupal's default markup.
*
* Complete documentation for this file is available online.
* @see https://drupal.org/node/1728096
*/
function yourtheme_preprocess_html(&$variables, $hook) {
drupal_add_library('yourmodule', 'mmenu');
drupal_add_js(drupal_get_path('theme', 'yourtheme') . '/js/mainmenu-responsive.js', 'file');
}
<?php
/**
* Implements hook_library().
*/
function yourmodule_library() {
// Declares mmenu library.
$libraries['mmenu'] = array(
'title' => 'mmenu',
'website' => 'http://mmenu.frebsite.nl',
'version' => '4.5',
'js' => array(
libraries_get_path('mmenu') . '/src/js/jquery.mmenu.min.js' => array(),
),
'css' => array(
libraries_get_path('mmenu') . '/src/css/jquery.mmenu.css' => array(
'type' => 'file',
'media' => 'screen',
),
),
);
return $libraries;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment