// global variables for the sidemenu var mainnaviconids = "#env-sidemenu-options a, #env-sidemenu-windows a"; var footericonids = ""; var module_vars = { $portalcontainer: {}, $modulecontainer: {}, $modulebeltcontainer: {}, $modulebelt: {}, $sidemenufooter: {}, $button_up: {}, $button_down: {}, modulecount: 0, moduleheight: 0, moduletotalheight: 0, mc_offset: 0, mc_height: 0, ft_height: 0, space_from_bottom: 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()); }); //As soon as content is visible, see if a scrollbar needs to be added if (use_iscroll) { var panelname = "panelbar"; var panelscroll = "#env-sidemenu-slidepanel-scroll-inner"; window[panelname] = new IScroll(panelscroll, { scrollX: false, scrollY: true, scrollbars: true, click: true }); //iScroll } }); $(window).load(function () { InitModuleContainer(); }); $(window).resize(function () { //var footerpanelwidth = $(this).width() - 100; //$("div.full").width(footerpanelwidth); if (module_vars.sidemenuscrollactive) AdjustModuleContainer(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 && !handheldmode) 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.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"); module_vars.mc_offset = module_vars.$modulebeltcontainer.offset().top; module_vars.ft_height = module_vars.$sidemenufooter.outerHeight(); //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").height()); } function AdjustModuleContainer(h) { //Get all the heights and offsets 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); //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 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 (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 = 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 topposition = parseInt(module_vars.$modulebelt.css("top")) || 0; //3. Find the maximum/minimum position the belt is allowed to scroll (negative values) var mintopposition = -(module_vars.modulecount - visiblemodules) * module_vars.moduleheight; var maxtopposition = 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 scrolldistance = maxscrollspots * module_vars.moduleheight; //6. Find the NEW top position where the belt should scroll var newposition = direction === "up" ? Math.min(maxtopposition, topposition + scrolldistance) : Math.max(mintopposition, topposition - scrolldistance); module_vars.$modulebelt.css({ top: newposition }); if (newposition >= maxtopposition) module_vars.$button_up.addClass("disabled"); else module_vars.$button_up.removeClass("disabled"); if (newposition <= mintopposition) 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 asidewidth = $('#env-aside').width(); var paneltitle = $('#env-sidemenu-slidepanel-container h2').text(); var titlereload = reload || false; var desktopwidth = 400; var mobilewidth = "100%"; var defaultwidth = handheldmode ? mobilewidth : desktopwidth; if ($parent.hasClass("open") && title === paneltitle && !titlereload) ClosePanel(); else { //Close footer panel if it's open CloseFooterPanel(); //Set local variables var p_width = panelwidth || defaultwidth; if (p_width === 0) p_width = defaultwidth; var p_height = panelheight || "100%"; if (p_height === 0) p_height = "100%"; var p_top = paneltop || (env_portal_mode === "page" ? 76 : 0); // turn on slim loading bar RevealLoading(); // set up the panel //if (env_portal_mode === "page") //{ // 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-sidemenu-slidepanel-container h2').addClass("textcenter"); else $('#env-sidemenu-slidepanel-container h2').removeClass("textcenter"); //Set the max-width of the parent $parent.css({ "max-width": p_width + asidewidth }); //Open the panel $parent.addClass("open"); //Animate the width of the parent container and slide the child container out the same width //if (!$(parent).hasClass("open")) //{ // //$(parent).addClass("open"); // //$(container).css({ left: "-" + p_width + "px" }).width(p_width); // //$(parent).stop().animate({ width: p_width }); // //$(container).stop().animate({ left: 0 }); //} //else //{ // //$(container).stop().animate({ width: p_width }); // //$(parent).stop().animate({ width: p_width }); //} } } function InitializeFooterPanel(contenturl, panelwidth, panelheight, panelbottom) { var $parent = $('#env-sidemenu-footerpanel'); if ($parent.hasClass("open")) CloseFooterPanel(); else { //Close main panel if it's open ClosePanel(); $parent.addClass("open"); //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") //{ // 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"); } function RevealBarContent() { //Fade out loading, then fade in content $("#env-sidemenu-slidepanel-loading").fadeOut(250, function () { $("#env-sidemenu-slidepanel-content").fadeIn(250, function () { RecalibratePanelScroll(); }); }); } function RecalibratePanelScroll() { if (use_iscroll) { window["panelbar"].refresh(); } //iScroll } 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", ""); }