// global variables for the sidemenu var module_vars = { $portalcontainer: {}, $modulecontainer: {}, $modulebeltcontainer: {}, $modulebelt: {}, $sidemenufooter: {}, $button_up: {}, $button_down: {}, modulecount: 0, modulewidth: 0, moduletotalwidth: 0, moduleheight: 0, moduletotalheight: 0, mc_offset: 0, mc_width: 0, mc_height: 0, ft_width: 0, ft_height: 0, space_from_right: 0, space_from_bottom: 0, mc_width_adjustment: 0, mc_height_adjustment: 0, mc_item_multiplier: 0, sidemenuscrollactive: false } // load click bindings and styles $(document).ready(function () { var eventtype = is_TouchDevice ? "touchstart" : "click"; var $closebutton = $("#env-sidemenu-button-close"); // wire bar panel close button $closebutton.on(eventtype, function () { ClosePanel(); }); // wire footer panel close button $("#env-sidemenu-footer-button-close").on(eventtype, function () { CloseFooterPanel(); }); // keep close button in place in case there's a scrollbar $("#env-sidemenu-slidepanel-scroll-inner").scroll(function () { $closebutton.css("top", $(this).scrollTop()); }); }); $(window).load(function () { InitModuleContainer(); }); $(window).resize(function () { if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { var footerpanelheight = $(this).height() - 100; $("div.full").height(footerpanelheight); if (module_vars.sidemenuscrollactive) AdjustModuleContainer(module_vars.$portalcontainer.outerWidth(), module_vars.$portalcontainer.outerHeight()); } else { var footerpanelwidth = $(this).width() - 100; $("div.full").width(footerpanelwidth); if (module_vars.sidemenuscrollactive) AdjustModuleContainer(module_vars.$portalcontainer.outerWidth(), module_vars.$portalcontainer.outerHeight()); } }) function InitModuleContainer() { //make sure the container exists first! module_vars.$modulecontainer = $("#env-sidemenu-module-container"); if (module_vars.$modulecontainer.length > 0) module_vars.sidemenuscrollactive = true; else return; //wire the variables up for the sidemenu module_vars.$portalcontainer = $("#env-dashboard-content"); module_vars.$modulebeltcontainer = $("#env-sidemenu-module-belt-container"); module_vars.$modulebelt = $("#env-sidemenu-module-belt"); module_vars.$button_up = module_vars.$modulecontainer.find("a.module-up"); module_vars.$button_down = module_vars.$modulecontainer.find("a.module-down"); module_vars.modulecount = module_vars.$modulebeltcontainer.find(".portal-sidemenu-item").length; module_vars.modulewidth = module_vars.$modulebeltcontainer.find(".portal-sidemenu-item").outerWidth(true); module_vars.moduletotalwidth = (module_vars.modulecount * module_vars.modulewidth + 18); module_vars.moduleheight = module_vars.$modulebeltcontainer.find(".portal-sidemenu-item").outerHeight(true); module_vars.moduletotalheight = (module_vars.modulecount * module_vars.moduleheight + 18); module_vars.$sidemenufooter = $("#env-sidemenu-footer"); if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") module_vars.mc_offset = module_vars.$modulebeltcontainer.offset().left; else module_vars.mc_offset = module_vars.$modulebeltcontainer.offset().top; module_vars.ft_width = module_vars.$sidemenufooter.outerWidth(); module_vars.ft_height = module_vars.$sidemenufooter.outerHeight(); // for the horizontal direction module_vars.$modulebelt.width(module_vars.moduletotalwidth); // add extra classes depending on where the nav bar is if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { module_vars.$modulecontainer.addClass("animate-width"); module_vars.$modulebeltcontainer.addClass("animate-width"); module_vars.$modulebelt.addClass("animate-left"); } else { module_vars.$modulecontainer.addClass("animate-height"); module_vars.$modulebeltcontainer.addClass("animate-height"); module_vars.$modulebelt.addClass("animate-top"); } //Bind the tabbing buttons module_vars.$button_up.on("click", function () { if (!$(this).hasClass("disabled")) TabModules("up"); }); module_vars.$button_down.on("click", function () { if (!$(this).hasClass("disabled")) TabModules("down"); }); //Now that you have the one-time values, fire the adjust method AdjustModuleContainer($("#env-dashboard-content").width(), $("#env-dashboard-content").height()); } function AdjustModuleContainer(w, h) { //Get all the widths/heights and offsets module_vars.mc_width = module_vars.$modulebeltcontainer.outerWidth(); module_vars.space_from_right = w - (module_vars.mc_offset + module_vars.moduletotalwidth + module_vars.ft_width); module_vars.mc_height = module_vars.$modulebeltcontainer.outerHeight(); module_vars.space_from_bottom = h - (module_vars.mc_offset + module_vars.moduletotalheight + module_vars.ft_height); if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { //Reset back to left if belt is not at 0 if (module_vars.$modulebelt.css("left") != "0px") { module_vars.$modulebelt.css({ left: 0 }); module_vars.$button_down.removeClass("disabled"); module_vars.$button_up.addClass("disabled"); } } else { //Reset back to top if belt is not at 0 if (module_vars.$modulebelt.css("top") != "0px") { module_vars.$modulebelt.css({ top: 0 }); module_vars.$button_down.removeClass("disabled"); module_vars.$button_up.addClass("disabled"); } } //If space from right/bottom is less than 0, there's no more room for the modules to all show so the container must shrink with tabbing navigation if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { if (module_vars.space_from_right < 0) { if (!module_vars.$modulecontainer.hasClass("tab_active")) module_vars.$modulecontainer.addClass("tab_active"); module_vars.mc_width_adjustment = Math.ceil(Math.abs(module_vars.space_from_right) / module_vars.modulewidth); module_vars.$modulebeltcontainer.width(module_vars.modulewidth * (module_vars.modulecount - module_vars.mc_width_adjustment)); } else { if (module_vars.$modulecontainer.hasClass("tab_active")) module_vars.$modulecontainer.removeClass("tab_active"); module_vars.$modulebeltcontainer.width(module_vars.modulewidth * module_vars.modulecount); } } else { if (module_vars.space_from_bottom < 0) { if (!module_vars.$modulecontainer.hasClass("tab_active")) module_vars.$modulecontainer.addClass("tab_active"); module_vars.mc_height_adjustment = Math.ceil(Math.abs(module_vars.space_from_bottom) / module_vars.moduleheight); module_vars.$modulebeltcontainer.height(module_vars.moduleheight * (module_vars.modulecount - module_vars.mc_height_adjustment)); } else { if (module_vars.$modulecontainer.hasClass("tab_active")) module_vars.$modulecontainer.removeClass("tab_active"); module_vars.$modulebeltcontainer.height(module_vars.moduleheight * module_vars.modulecount); } } } function TabModules(direction) { //1. First, find out how many visible/hidden modules there are var hiddenmodules = (env_portal_mode == "page" || env_portal_mode == "topnavwindow") ? module_vars.mc_width_adjustment : module_vars.mc_height_adjustment; var visiblemodules = module_vars.modulecount - hiddenmodules; //2. Next, find where the current position of the first module is (negative value) var startposition = ((env_portal_mode == "page" || env_portal_mode == "topnavwindow") ? parseInt(module_vars.$modulebelt.css("left")) : parseInt(module_vars.$modulebelt.css("top"))) || 0; //3. Find the maximum/minimum position the belt is allowed to scroll (negative values) var minstartposition = (env_portal_mode == "page" || env_portal_mode == "topnavwindow") ? -(module_vars.modulecount - visiblemodules) * module_vars.modulewidth : -(module_vars.modulecount - visiblemodules) * module_vars.moduleheight; var maxstartposition = 0; //4. Scroll as many spots as there are hidden modules, UP TO the number of visible modules (therefore making it a smart slider!) var maxscrollspots = Math.min(hiddenmodules, visiblemodules); //5. Find the distance the belt needs to travel (positive value!) var modulevariance = (env_portal_mode == "page" || env_portal_mode == "topnavwindow") ? module_vars.modulewidth : module_vars.moduleheight; var scrolldistance = maxscrollspots * modulevariance; //6. Find the NEW start position where the belt should scroll var newposition = direction == "up" ? Math.min(maxstartposition, startposition + scrolldistance) : Math.max(minstartposition, startposition - scrolldistance); if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") module_vars.$modulebelt.css({ left: newposition }); else module_vars.$modulebelt.css({ top: newposition }); if (newposition >= maxstartposition) module_vars.$button_up.addClass("disabled"); else module_vars.$button_up.removeClass("disabled"); if (newposition <= minstartposition) module_vars.$button_down.addClass("disabled"); else module_vars.$button_down.removeClass("disabled"); } // panel calls function InitializePanel(title, contenturl, panelwidth, panelheight, paneltop, reload) { var parent = $('#env-sidemenu-slidepanel'); var container = $('#env-sidemenu-slidepanel-container'); var paneltitle = $('#env-sidemenu-slidepanel-container h2').text(); var titlereload = reload || false; if (($(parent).hasClass("open")) && (title == paneltitle) && (!titlereload)) ClosePanel(); else { //Close footer panel if it's open CloseFooterPanel(); //Set local variables var p_width = panelwidth || 420; if (p_width == 0) p_width = 420; var p_height = panelheight || "100%"; if (p_height == 0) p_height = "100%"; var p_top = paneltop; if (paneltop == null) p_top = (env_portal_mode == "page" || env_portal_mode == "topnavwindow" ? 86 : 0); // turn on slim loading bar RevealLoading(); // set up the panel if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { if (panelheight !== null) $(parent).width(p_height); if (paneltop !== null) $(parent).css({ top: p_top + 'px' }); } else { //if (panelheight !== null) $(parent).height(p_height); //if (paneltop !== null) $(parent).css({ top: p_top + 'px' }); } $('#env-sidemenu-slidepanel-section').load(contenturl, function () { var titledisplay = title; if (titlereload) titledisplay = "" + title + ""; $('#env-sidemenu-slidepanel-title').html(titledisplay); setTimeout(function(){RevealBarContent()}, 50); }); //Center the header if the width is shorter than 160px if (p_width < 160 && env_portal_mode != "page" && env_portal_mode != "topnavwindow") $('#env-sidemenu-slidepanel-container h2').addClass("textcenter"); else $('#env-sidemenu-slidepanel-container h2').removeClass("textcenter") //Animate the width of the parent container and slide the child container out the same width if (!$(parent).hasClass("open")) { $(parent).addClass("open"); if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { $(container).css({ top: "-" + p_width + "px" }).height(p_width); $(parent).stop().animate({ height: p_width }); $(container).stop().animate({ top: 0 }); } else { $(container).css({ left: "-" + p_width + "px" }).width(p_width); $(parent).stop().animate({ width: p_width }); $(container).stop().animate({ left: 0 }); } } else { if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { $(container).stop().animate({ height: p_width }); $(parent).stop().animate({ height: p_width }); } else { $(container).stop().animate({ width: p_width }); $(parent).stop().animate({ width: p_width }); } } } } function SyncLabData(contenturl) { // activate sidepanel button $('#env-sidemenu-labsync a').addClass("selected"); // pop up a panel to show the data being synced $.colorbox({ inline: true, overlayClose: false, href: "#LabSyncContent", title: "Syncing Latest Lab Data", width: 550, height: 180, maxHeight: "90%", onComplete: function () { // load in lab syncer content $.post(contenturl); } }); } function InitializeFooterPanel(contenturl, panelwidth, panelheight, panelbottom) { var parent = $('#env-sidemenu-footerpanel'); var container = $('#env-sidemenu-footerpanel-container'); if ($(parent).hasClass("open")) CloseFooterPanel(); else { //Close main panel if it's open ClosePanel(); //Set local variables var p_width = panelwidth || ((env_portal_mode == "page" || env_portal_mode == "topnavwindow") ? 100 : ($(window).width() - 100)); var p_height = panelheight || 100; var p_bottom = panelbottom || 0; // set up the panel if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { if (panelheight !== null) $(parent).height(p_height); if (panelwidth !== null) { $(parent).width("100%"); } } else { if (panelheight !== null) $(parent).height(p_height); if (panelbottom !== null) $(parent).css({ bottom: p_bottom + 'px' }); if (panelwidth !== null) { $(parent).width(p_width); $(parent).addClass("full"); $(container).addClass("full"); } } //$('#env-sidemenu-footerpanel-content').load(contenturl); $(parent).addClass("open"); //Animate the width of the parent container and slide the child container out the same width if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { $(container).css({ top: "-" + p_width + "px" }); $(parent).stop().animate({ height: p_width }); $(container).stop().animate({ top: 0 }); } else { $(container).css({ left: "-" + p_width + "px" }).width(p_width); $(parent).stop().animate({ width: p_width }); $(container).stop().animate({ left: 0 }); } //Activate sidepanel button $('#env-sidemenu-footerinfo a').addClass("selected"); } } function LoadingBarPanel(show) { if (show) $("#env-sidemenu-slidepanel-loading").removeClass("hide"); else $("#env-sidemenu-slidepanel-loading").addClass("hide"); } function ClosePanel() { $('#env-sidemenu-slidepanel').removeClass("open"); $(".portal-sidemenu-item a").removeClass("selected"); if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { var h = $("#env-sidemenu-slidepanel-container").height(); $('#env-sidemenu-slidepanel').stop().animate({ height: 0 }); $('#env-sidemenu-slidepanel-container').stop().animate({ top: -h }, function () { ResetBarContent(); }); } else { var w = $("#env-sidemenu-slidepanel-container").width(); $('#env-sidemenu-slidepanel').removeClass("open"); $('#env-sidemenu-slidepanel').stop().animate({ width: 0 }); $('#env-sidemenu-slidepanel-container').stop().animate({ left: -w }, function () { ResetBarContent(); }); } } function CloseFooterPanel() { $('#env-sidemenu-footerpanel').removeClass("open full"); $('#env-sidemenu-footerinfo a').removeClass("selected"); if (env_portal_mode == "page" || env_portal_mode == "topnavwindow") { var h = $("#env-sidemenu-footerpanel-container").height(); $('#env-sidemenu-footerpanel').stop().animate({ height: 0 }); $('#env-sidemenu-footerpanel-container').stop().animate({ top: -h }); } else { var w = $("#env-sidemenu-footerpanel-container").width(); $('#env-sidemenu-footerpanel').stop().animate({ width: 0 }); $('#env-sidemenu-footerpanel-container').stop().animate({ left: -w }); } } function RevealBarContent() { //Fade out loading, then fade in content $("#env-sidemenu-slidepanel-loading").fadeOut(250, function () { $("#env-sidemenu-slidepanel-content").fadeIn(250); }); } function RevealLoading() { //Fade in loading and fade out content simultaneously $("#env-sidemenu-slidepanel-loading").removeClass("hide"); $('#env-sidemenu-slidepanel-section, #env-sidemenu-slidepanel-title').empty(); $("#env-sidemenu-slidepanel-content").hide(); $("#env-sidemenu-slidepanel-loading").fadeIn(250); } function ResetBarContent() { //Remove all inline display styles (recommended when bar is not visible) $("#env-sidemenu-slidepanel-loading").css("display", ""); $("#env-sidemenu-slidepanel-content").css("display", ""); }