mirror of
https://github.com/redmine/redmine.git
synced 2025-11-04 20:35:57 +01:00
Makes the sidebar collapsible and stateful (#21808).
Patch inspired from user:jkraemer. git-svn-id: https://svn.redmine.org/redmine/trunk@23218 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -1261,6 +1261,77 @@ function inlineAutoComplete(element) {
|
||||
tribute.attach(element);
|
||||
}
|
||||
|
||||
// collapsible sidebar jQuery plugin
|
||||
(function($) {
|
||||
// main container this is applied to
|
||||
var main;
|
||||
// triggers show/hide
|
||||
var button;
|
||||
// the key to use in local storage
|
||||
// this will later be expanded using the current controller and action to
|
||||
// allow for different sidebar states for different pages
|
||||
var localStorageKey = 'redmine-sidebar-state';
|
||||
// true if local storage is available
|
||||
var canUseLocalStorage = function(){
|
||||
try {
|
||||
if('localStorage' in window){
|
||||
localStorage.setItem('redmine.test.storage', 'ok');
|
||||
var item = localStorage.getItem('redmine.test.storage');
|
||||
localStorage.removeItem('redmine.test.storage');
|
||||
if(item === 'ok') return true;
|
||||
}
|
||||
} catch (err) {}
|
||||
return false;
|
||||
}();
|
||||
// function to set current sidebar state
|
||||
var setState = function(state){
|
||||
if(canUseLocalStorage){
|
||||
localStorage.setItem(localStorageKey, state);
|
||||
}
|
||||
};
|
||||
var applyState = function(){
|
||||
if(main.hasClass('collapsedsidebar')){
|
||||
updateSVGIcon(main[0], 'chevrons-left')
|
||||
setState('hidden');
|
||||
} else {
|
||||
updateSVGIcon(main[0], 'chevrons-right')
|
||||
setState('visible');
|
||||
}
|
||||
};
|
||||
var setupToggleButton = function(){
|
||||
button = $('#sidebar-switch-button');
|
||||
button.click(function(e){
|
||||
main.addClass("animate");
|
||||
main.toggleClass('collapsedsidebar');
|
||||
applyState();
|
||||
e.preventDefault();
|
||||
return false;
|
||||
});
|
||||
applyState();
|
||||
};
|
||||
$.fn.collapsibleSidebar = function() {
|
||||
main = this;
|
||||
// determine previously stored sidebar state for this page
|
||||
if(canUseLocalStorage) {
|
||||
// determine current controller/action pair and use them as storage key
|
||||
var bodyClass = $('body').attr('class');
|
||||
if(bodyClass){
|
||||
try {
|
||||
localStorageKey += '-' + bodyClass.split(/\s+/).filter(function(s){
|
||||
return s.match(/(action|controller)-.*/);
|
||||
}).sort().join('-');
|
||||
} catch(e) {
|
||||
// in case of error (probably IE8), continue with the unmodified key
|
||||
}
|
||||
}
|
||||
var storedState = localStorage.getItem(localStorageKey);
|
||||
main.toggleClass('collapsedsidebar', storedState === 'hidden');
|
||||
}
|
||||
// draw the toggle button once the DOM is complete
|
||||
$(document).ready(setupToggleButton);
|
||||
};
|
||||
}(jQuery));
|
||||
|
||||
$(document).ready(setupAjaxIndicator);
|
||||
$(document).ready(hideOnLoad);
|
||||
$(document).ready(addFormObserversForDoubleSubmit);
|
||||
|
||||
Reference in New Issue
Block a user