3421N/A/*
3421N/A * sidebar.js
3421N/A * ~~~~~~~~~~
3421N/A *
3421N/A * This script makes the Sphinx sidebar collapsible.
3421N/A *
3421N/A * .sphinxsidebar contains .sphinxsidebarwrapper. This script adds
3421N/A * in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton
3421N/A * used to collapse and expand the sidebar.
3421N/A *
3421N/A * When the sidebar is collapsed the .sphinxsidebarwrapper is hidden
3421N/A * and the width of the sidebar and the margin-left of the document
3421N/A * are decreased. When the sidebar is expanded the opposite happens.
3421N/A * This script saves a per-browser/per-session cookie used to
3421N/A * remember the position of the sidebar among the pages.
3421N/A * Once the browser is closed the cookie is deleted and the position
3421N/A * reset to the default (expanded).
3421N/A *
3421N/A * :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
3421N/A * :license: BSD, see LICENSE for details.
3421N/A *
3421N/A */
3421N/A
3421N/A$(function() {
3421N/A
3421N/A
3421N/A
3421N/A
3421N/A
3421N/A
3421N/A
3421N/A
3421N/A // global elements used by the functions.
3421N/A // the 'sidebarbutton' element is defined as global after its
3421N/A // creation, in the add_sidebar_button function
3421N/A var bodywrapper = $('.bodywrapper');
3421N/A var sidebar = $('.sphinxsidebar');
3421N/A var sidebarwrapper = $('.sphinxsidebarwrapper');
3421N/A
3421N/A // for some reason, the document has no sidebar; do not run into errors
3421N/A if (!sidebar.length) return;
3421N/A
3421N/A // original margin-left of the bodywrapper and width of the sidebar
3421N/A // with the sidebar expanded
3421N/A var bw_margin_expanded = bodywrapper.css('margin-left');
3421N/A var ssb_width_expanded = sidebar.width();
3421N/A
3421N/A // margin-left of the bodywrapper and width of the sidebar
3421N/A // with the sidebar collapsed
3421N/A var bw_margin_collapsed = '.8em';
3421N/A var ssb_width_collapsed = '.8em';
3421N/A
3421N/A // colors used by the current theme
3421N/A var dark_color = $('.related').css('background-color');
3421N/A var light_color = $('.document').css('background-color');
3421N/A
3421N/A function sidebar_is_collapsed() {
3421N/A return sidebarwrapper.is(':not(:visible)');
3421N/A }
3421N/A
3421N/A function toggle_sidebar() {
3421N/A if (sidebar_is_collapsed())
3421N/A expand_sidebar();
3421N/A else
3421N/A collapse_sidebar();
3421N/A }
3421N/A
3421N/A function collapse_sidebar() {
3421N/A sidebarwrapper.hide();
3421N/A sidebar.css('width', ssb_width_collapsed);
3421N/A bodywrapper.css('margin-left', bw_margin_collapsed);
3421N/A sidebarbutton.css({
3421N/A 'margin-left': '0',
3421N/A 'height': bodywrapper.height()
3421N/A });
3421N/A sidebarbutton.find('span').text('»');
3421N/A sidebarbutton.attr('title', _('Expand sidebar'));
3421N/A document.cookie = 'sidebar=collapsed';
3421N/A }
3421N/A
3421N/A function expand_sidebar() {
3421N/A bodywrapper.css('margin-left', bw_margin_expanded);
3421N/A sidebar.css('width', ssb_width_expanded);
3421N/A sidebarwrapper.show();
3421N/A sidebarbutton.css({
3421N/A 'margin-left': ssb_width_expanded-12,
3421N/A 'height': bodywrapper.height()
3421N/A });
3421N/A sidebarbutton.find('span').text('«');
3421N/A sidebarbutton.attr('title', _('Collapse sidebar'));
3421N/A document.cookie = 'sidebar=expanded';
3421N/A }
3421N/A
3421N/A function add_sidebar_button() {
3421N/A sidebarwrapper.css({
3421N/A 'float': 'left',
3421N/A 'margin-right': '0',
3421N/A 'width': ssb_width_expanded - 28
3421N/A });
3421N/A // create the button
3421N/A sidebar.append(
3421N/A '<div id="sidebarbutton"><span>&laquo;</span></div>'
3421N/A );
3421N/A var sidebarbutton = $('#sidebarbutton');
3421N/A light_color = sidebarbutton.css('background-color');
3421N/A // find the height of the viewport to center the '<<' in the page
3421N/A var viewport_height;
3421N/A if (window.innerHeight)
3421N/A viewport_height = window.innerHeight;
3421N/A else
3421N/A viewport_height = $(window).height();
3421N/A sidebarbutton.find('span').css({
3421N/A 'display': 'block',
3421N/A 'margin-top': (viewport_height - sidebar.position().top - 20) / 2
3421N/A });
3421N/A
3421N/A sidebarbutton.click(toggle_sidebar);
3421N/A sidebarbutton.attr('title', _('Collapse sidebar'));
3421N/A sidebarbutton.css({
3421N/A 'color': '#FFFFFF',
3421N/A 'border-left': '1px solid ' + dark_color,
3421N/A 'font-size': '1.2em',
3421N/A 'cursor': 'pointer',
3421N/A 'height': bodywrapper.height(),
3421N/A 'padding-top': '1px',
3421N/A 'margin-left': ssb_width_expanded - 12
3421N/A });
3421N/A
3421N/A sidebarbutton.hover(
3421N/A function () {
3421N/A $(this).css('background-color', dark_color);
3421N/A },
3421N/A function () {
3421N/A $(this).css('background-color', light_color);
3421N/A }
3421N/A );
3421N/A }
3421N/A
3421N/A function set_position_from_cookie() {
3421N/A if (!document.cookie)
3421N/A return;
3421N/A var items = document.cookie.split(';');
3421N/A for(var k=0; k<items.length; k++) {
3421N/A var key_val = items[k].split('=');
3421N/A var key = key_val[0].replace(/ /, ""); // strip leading spaces
3421N/A if (key == 'sidebar') {
3421N/A var value = key_val[1];
3421N/A if ((value == 'collapsed') && (!sidebar_is_collapsed()))
3421N/A collapse_sidebar();
3421N/A else if ((value == 'expanded') && (sidebar_is_collapsed()))
3421N/A expand_sidebar();
3421N/A }
3421N/A }
3421N/A }
3421N/A
3421N/A add_sidebar_button();
3421N/A var sidebarbutton = $('#sidebarbutton');
3421N/A set_position_from_cookie();
3421N/A});