/*
Responsive Mobile Menu v1.0
Plugin URI: responsivemobilemenu.com
Author: Sergio Vitov
Author URI: http://xmacros.com
License: CC BY 3.0 http://creativecommons.org/licenses/by/3.0/
*/
function responsiveMobileMenu() {
//console.log("Initialising menu...");
$('.rmm').each(function() {
$(this).children('ul').addClass('rmm-main-list'); // mark main menu list
var $style = $(this).attr('data-menu-style'); // get menu style
if ( typeof $style == 'undefined' || $style == false )
{
$(this).addClass('graphite'); // set graphite style if style is not defined
}
else {
$(this).addClass($style);
}
/* width of menu list (non-toggled) */
var $width = 0;
$(this).find('ul li').each(function() {
$width += $(this).outerWidth();
//console.log($width);
});
// Do this instead to maintain my styling for normal menu
$(this).attr('data-ul-width' , $width*1.05);
// ...and not this! if modern browser
/*
if ($.support.leadingWhitespace) {
$(this).css('max-width' , $width*1.05+'px');
}
//
else {
$(this).css('width' , $width*1.05+'px');
}
*/
});
}
function getMobileMenu() {
/* build toggled dropdown menu list */
//console.log("Building mobile menu...");
$('.rmm').each(function() {
var menutitle = $(this).attr("data-menu-title");
if ( menutitle == "" ) {
menutitle = "Menu";
}
else if ( menutitle == undefined ) {
menutitle = "Menu";
}
var $menulist = $(this).children('.rmm-main-list').html();
var $menucontrols ="
";
$(this).prepend("");
//console.log("Finished creating extra html");
});
}
function adaptMenu() {
/* toggle menu on resize */
//console.log("Adpating menu...");
$('.rmm').each(function() {
//console.log($(this).attr('style'));
var $width = $(this).attr('data-ul-width');
//$width = $width.replace('px', '');
//console.log("Width grabbed from max-width css: " + $width);
//console.log($(this).parent().width());
var main_list = $(this).children('.rmm-main-list');
var toggled = $(this).children('.rmm-toggled');
var parent_width = $(this).parent().width();
if ( parent_width < $width*1.0 ) {
main_list.hide(0);
toggled.show(0);
if ( $(this).attr("id") == 'main-nav' ) $("#sub-nav").css("border-radius", 0);
}
else {
main_list.css('display', 'table');
toggled.hide(0);
if ( $(this).attr("id") == 'main-nav' ) $("#sub-nav").css("border-radius", "10px 10px 0 0");
}
});
}
$(function() {
responsiveMobileMenu();
getMobileMenu();
adaptMenu();
// logging in and out functions - ridiculous to have to put this here, but only way to get it to kick in!
$("#login_popup").dialog({ width: 280, autoOpen: false, modal: true, position: 'center', title: 'Enter login details' });
$("a.login").on("click", function(li)
{
li.preventDefault();
$("#login_popup").dialog('open');
});
$("a.logout").on("click", function(lo)
{
lo.preventDefault();
$("#login_popup").dialog('open');
$.ajax({
url: "../login_process/logout",
cache: false,
type: "POST",
success : function() {
$("#login_span").html('Login');
$("#login_errors").html('You are now logged out.
');
$('#login_popup').dialog({
close: function(event, ui) { location.reload(true); }
});
}
});
});
/* slide down mobile menu on click */
$('.rmm-toggled, .rmm-toggled .rmm-button').click(function(e){
console.log("here!");
if ( $(this).is(".rmm-closed")) {
$(this).find('ul').stop().show(300);
$(this).removeClass("rmm-closed");
}
else {
$(this).find('ul').stop().hide(300);
$(this).addClass("rmm-closed");
}
});
});
/* hide mobile menu on resize */
$(window).resize(function() {
adaptMenu();
});