/* * sidebar.js * ~~~~~~~~~~ * * This script makes the Sphinx sidebar collapsible. * * .sphinxsidebar contains .sphinxsidebarwrapper. This script adds * in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton * used to collapse and expand the sidebar. * * When the sidebar is collapsed the .sphinxsidebarwrapper is hidden * and the width of the sidebar and the margin-left of the document * are decreased. When the sidebar is expanded the opposite happens. * This script saves a per-browser/per-session cookie used to * remember the position of the sidebar among the pages. * Once the browser is closed the cookie is deleted and the position * reset to the default (expanded). * * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. * :license: BSD, see LICENSE for details. * */$(function(){{%iftheme_rightsidebar|tobool%}{%setside='right'%}{%setopposite='left'%}{%setinitial_label='&raquo;'%}{%setexpand_label='«'%}{%setcollapse_label='»'%}{%else%}{%setside='left'%}{%setopposite='right'%}{%setinitial_label='&laquo;'%}{%setexpand_label='»'%}{%setcollapse_label='«'%}{%endif%}// global elements used by the functions.// the 'sidebarbutton' element is defined as global after its// creation, in the add_sidebar_button functionvarbodywrapper=$('.bodywrapper');varsidebar=$('.sphinxsidebar');varsidebarwrapper=$('.sphinxsidebarwrapper');// for some reason, the document has no sidebar; do not run into errorsif(!sidebar.length)return;// original margin-left of the bodywrapper and width of the sidebar// with the sidebar expandedvarbw_margin_expanded=bodywrapper.css('margin-{{side}}');varssb_width_expanded=sidebar.width();// margin-left of the bodywrapper and width of the sidebar// with the sidebar collapsedvarbw_margin_collapsed='.8em';varssb_width_collapsed='.8em';// colors used by the current themevardark_color=$('.related').css('background-color');varlight_color=$('.document').css('background-color');functionsidebar_is_collapsed(){returnsidebarwrapper.is(':not(:visible)');}functiontoggle_sidebar(){if(sidebar_is_collapsed())expand_sidebar();elsecollapse_sidebar();}functioncollapse_sidebar(){sidebarwrapper.hide();sidebar.css('width',ssb_width_collapsed);bodywrapper.css('margin-{{side}}',bw_margin_collapsed);sidebarbutton.css({'margin-{{side}}':'0','height':bodywrapper.height()});sidebarbutton.find('span').text('{{expand_label}}');sidebarbutton.attr('title',_('Expand sidebar'));document.cookie='sidebar=collapsed';}functionexpand_sidebar(){bodywrapper.css('margin-{{side}}',bw_margin_expanded);sidebar.css('width',ssb_width_expanded);sidebarwrapper.show();sidebarbutton.css({'margin-{{side}}':ssb_width_expanded-12,'height':bodywrapper.height()});sidebarbutton.find('span').text('{{collapse_label}}');sidebarbutton.attr('title',_('Collapse sidebar'));document.cookie='sidebar=expanded';}functionadd_sidebar_button(){sidebarwrapper.css({'float':'{{side}}','margin-{{opposite}}':'0','width':ssb_width_expanded-28});// create the buttonsidebar.append('<div id="sidebarbutton"><span>{{initial_label}}</span></div>');varsidebarbutton=$('#sidebarbutton');light_color=sidebarbutton.css('background-color');// find the height of the viewport to center the '<<' in the pagevarviewport_height;if(window.innerHeight)viewport_height=window.innerHeight;elseviewport_height=$(window).height();sidebarbutton.find('span').css({'display':'block','margin-top':(viewport_height-sidebar.position().top-20)/2});sidebarbutton.click(toggle_sidebar);sidebarbutton.attr('title',_('Collapse sidebar'));sidebarbutton.css({'color':'#FFFFFF','border-{{side}}':'1px solid '+dark_color,'font-size':'1.2em','cursor':'pointer','height':bodywrapper.height(),'padding-top':'1px','margin-{{side}}':ssb_width_expanded-12});sidebarbutton.hover(function(){$(this).css('background-color',dark_color);},function(){$(this).css('background-color',light_color);});}functionset_position_from_cookie(){if(!document.cookie)return;varitems=document.cookie.split(';');for(vark=0;k<items.length;k++){varkey_val=items[k].split('=');varkey=key_val[0];if(key=='sidebar'){varvalue=key_val[1];if((value=='collapsed')&&(!sidebar_is_collapsed()))collapse_sidebar();elseif((value=='expanded')&&(sidebar_is_collapsed()))expand_sidebar();}}}add_sidebar_button();varsidebarbutton=$('#sidebarbutton');set_position_from_cookie();});