36 var bodywrapper = $(
'.bodywrapper');
37 var sidebar = $(
'.sphinxsidebar');
38 var sidebarwrapper = $(
'.sphinxsidebarwrapper');
41 if (!sidebar.length)
return;
45 var bw_margin_expanded = bodywrapper.css(
'margin-left');
46 var ssb_width_expanded = sidebar.width();
50 var bw_margin_collapsed =
'.8em';
51 var ssb_width_collapsed =
'.8em';
54 var dark_color = $(
'.related').css(
'background-color');
55 var light_color = $(
'.document').css(
'background-color');
57 function sidebar_is_collapsed() {
58 return sidebarwrapper.is(
':not(:visible)');
61 function toggle_sidebar() {
62 if (sidebar_is_collapsed())
68 function collapse_sidebar() {
69 sidebarwrapper.hide();
70 sidebar.css(
'width', ssb_width_collapsed);
71 bodywrapper.css(
'margin-left', bw_margin_collapsed);
74 'height': bodywrapper.height()
76 sidebarbutton.find(
'span').text(
'»');
77 sidebarbutton.attr(
'title', _(
'Expand sidebar'));
78 document.cookie =
'sidebar=collapsed';
81 function expand_sidebar() {
82 bodywrapper.css(
'margin-left', bw_margin_expanded);
83 sidebar.css(
'width', ssb_width_expanded);
84 sidebarwrapper.show();
86 'margin-left': ssb_width_expanded-12,
87 'height': bodywrapper.height()
89 sidebarbutton.find(
'span').text(
'«');
90 sidebarbutton.attr(
'title', _(
'Collapse sidebar'));
91 document.cookie =
'sidebar=expanded';
94 function add_sidebar_button() {
98 'width': ssb_width_expanded - 28
102 '<div id="sidebarbutton"><span>«</span></div>' 104 var sidebarbutton = $(
'#sidebarbutton');
105 light_color = sidebarbutton.css(
'background-color');
108 if (window.innerHeight)
109 viewport_height = window.innerHeight;
111 viewport_height = $(window).height();
112 sidebarbutton.find(
'span').css({
114 'margin-top': (viewport_height - sidebar.position().top - 20) / 2
117 sidebarbutton.click(toggle_sidebar);
118 sidebarbutton.attr(
'title', _(
'Collapse sidebar'));
121 'border-left':
'1px solid ' + dark_color,
122 'font-size':
'1.2em',
124 'height': bodywrapper.height(),
125 'padding-top':
'1px',
126 'margin-left': ssb_width_expanded - 12
131 $(
this).css(
'background-color', dark_color);
134 $(
this).css(
'background-color', light_color);
139 function set_position_from_cookie() {
140 if (!document.cookie)
142 var items = document.cookie.split(
';');
143 for(var k=0; k<items.length; k++) {
144 var key_val = items[k].split(
'=');
145 var key = key_val[0].replace(/ /,
"");
146 if (key ==
'sidebar') {
147 var value = key_val[1];
148 if ((value ==
'collapsed') && (!sidebar_is_collapsed()))
150 else if ((value ==
'expanded') && (sidebar_is_collapsed()))
156 add_sidebar_button();
157 var sidebarbutton = $(
'#sidebarbutton');
158 set_position_from_cookie();