function triggerChartsResize(){ try { if (window.onresize){ window.onresize(); } } catch (e){ //just swallow it } $(window).trigger('resize'); } $(function(){ //settings var $settings = $("#settings"), $sidebarSettings = $("#sidebar-settings"), settingsState = JSON.parse(localStorage.getItem("settings-state")) || { sidebar: 'left', background: 'dark', sidebarState: 'auto', displaySidebar: true }, $pageHeader = $(".page-header"), $body = $("body"), popoverReallyHide = function(){ $settings.data('bs.popover').hoverState = 'out'; //yeah. cool BS3 fix. popover programmatic APi works only on HOVER $settings.popover('hide'); }, popoverClose = function(e){ var $popover = $settings.siblings(".popover"); if(!$.contains($popover[0], e.target)){ popoverReallyHide(); $(document).off("click", popoverClose); } }, sidebarSide = function(side){ if (side == "right"){ $body.addClass("sidebar-on-right") } else { $body.removeClass("sidebar-on-right") } }, backgroundStyle = function(style){ if (style == "dark"){ $body.addClass("background-dark"); } else { $body.removeClass("background-dark"); } }, sidebarState = function(state, triggerResize){ var $template = $('#sidebar-settings-template'); triggerResize = triggerResize == undefined ? true : false; if (!$template[0]){ return; } $sidebarSettings.html(_.template($template.html(), {sidebarState: state})); if (state == "auto"){ $(".sidebar, .side-nav, .wrap, .logo").removeClass("sidebar-icons"); } else { $(".sidebar, .side-nav, .wrap, .logo").addClass("sidebar-icons"); } if (triggerResize){ triggerChartsResize(); } }, displaySidebar = function(display, triggerResize){ triggerResize = triggerResize == undefined ? true : false; if (display == true){ $body.removeClass("sidebar-hidden") } else { $body.addClass("sidebar-hidden") } if (triggerResize){ triggerChartsResize(); } }; sidebarSide(settingsState.sidebar); backgroundStyle(settingsState.background); sidebarState(settingsState.sidebarState, false); displaySidebar(settingsState.displaySidebar, false); if (!$settings[0]){ return; } $settings.popover({ template: '