Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * sidebar.js |
michael@0 | 3 | * ~~~~~~~~~~ |
michael@0 | 4 | * |
michael@0 | 5 | * This script makes the Sphinx sidebar collapsible. |
michael@0 | 6 | * |
michael@0 | 7 | * .sphinxsidebar contains .sphinxsidebarwrapper. This script adds |
michael@0 | 8 | * in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton |
michael@0 | 9 | * used to collapse and expand the sidebar. |
michael@0 | 10 | * |
michael@0 | 11 | * When the sidebar is collapsed the .sphinxsidebarwrapper is hidden |
michael@0 | 12 | * and the width of the sidebar and the margin-left of the document |
michael@0 | 13 | * are decreased. When the sidebar is expanded the opposite happens. |
michael@0 | 14 | * This script saves a per-browser/per-session cookie used to |
michael@0 | 15 | * remember the position of the sidebar among the pages. |
michael@0 | 16 | * Once the browser is closed the cookie is deleted and the position |
michael@0 | 17 | * reset to the default (expanded). |
michael@0 | 18 | * |
michael@0 | 19 | * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. |
michael@0 | 20 | * :license: BSD, see LICENSE for details. |
michael@0 | 21 | * |
michael@0 | 22 | */ |
michael@0 | 23 | |
michael@0 | 24 | $(function() { |
michael@0 | 25 | // global elements used by the functions. |
michael@0 | 26 | // the 'sidebarbutton' element is defined as global after its |
michael@0 | 27 | // creation, in the add_sidebar_button function |
michael@0 | 28 | var bodywrapper = $('.bodywrapper'); |
michael@0 | 29 | var sidebar = $('.sphinxsidebar'); |
michael@0 | 30 | var sidebarwrapper = $('.sphinxsidebarwrapper'); |
michael@0 | 31 | |
michael@0 | 32 | // original margin-left of the bodywrapper and width of the sidebar |
michael@0 | 33 | // with the sidebar expanded |
michael@0 | 34 | var bw_margin_expanded = bodywrapper.css('margin-left'); |
michael@0 | 35 | var ssb_width_expanded = sidebar.width(); |
michael@0 | 36 | |
michael@0 | 37 | // margin-left of the bodywrapper and width of the sidebar |
michael@0 | 38 | // with the sidebar collapsed |
michael@0 | 39 | var bw_margin_collapsed = '.8em'; |
michael@0 | 40 | var ssb_width_collapsed = '.8em'; |
michael@0 | 41 | |
michael@0 | 42 | // colors used by the current theme |
michael@0 | 43 | var dark_color = $('.related').css('background-color'); |
michael@0 | 44 | var light_color = $('.document').css('background-color'); |
michael@0 | 45 | |
michael@0 | 46 | function sidebar_is_collapsed() { |
michael@0 | 47 | return sidebarwrapper.is(':not(:visible)'); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function toggle_sidebar() { |
michael@0 | 51 | if (sidebar_is_collapsed()) |
michael@0 | 52 | expand_sidebar(); |
michael@0 | 53 | else |
michael@0 | 54 | collapse_sidebar(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function collapse_sidebar() { |
michael@0 | 58 | sidebarwrapper.hide(); |
michael@0 | 59 | sidebar.css('width', ssb_width_collapsed); |
michael@0 | 60 | bodywrapper.css('margin-left', bw_margin_collapsed); |
michael@0 | 61 | sidebarbutton.css({ |
michael@0 | 62 | 'margin-left': '0', |
michael@0 | 63 | 'height': bodywrapper.height() |
michael@0 | 64 | }); |
michael@0 | 65 | sidebarbutton.find('span').text('»'); |
michael@0 | 66 | sidebarbutton.attr('title', _('Expand sidebar')); |
michael@0 | 67 | document.cookie = 'sidebar=collapsed'; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function expand_sidebar() { |
michael@0 | 71 | bodywrapper.css('margin-left', bw_margin_expanded); |
michael@0 | 72 | sidebar.css('width', ssb_width_expanded); |
michael@0 | 73 | sidebarwrapper.show(); |
michael@0 | 74 | sidebarbutton.css({ |
michael@0 | 75 | 'margin-left': ssb_width_expanded-12, |
michael@0 | 76 | 'height': bodywrapper.height() |
michael@0 | 77 | }); |
michael@0 | 78 | sidebarbutton.find('span').text('«'); |
michael@0 | 79 | sidebarbutton.attr('title', _('Collapse sidebar')); |
michael@0 | 80 | document.cookie = 'sidebar=expanded'; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function add_sidebar_button() { |
michael@0 | 84 | sidebarwrapper.css({ |
michael@0 | 85 | 'float': 'left', |
michael@0 | 86 | 'margin-right': '0', |
michael@0 | 87 | 'width': ssb_width_expanded - 28 |
michael@0 | 88 | }); |
michael@0 | 89 | // create the button |
michael@0 | 90 | sidebar.append( |
michael@0 | 91 | '<div id="sidebarbutton"><span>«</span></div>' |
michael@0 | 92 | ); |
michael@0 | 93 | var sidebarbutton = $('#sidebarbutton'); |
michael@0 | 94 | light_color = sidebarbutton.css('background-color'); |
michael@0 | 95 | // find the height of the viewport to center the '<<' in the page |
michael@0 | 96 | var viewport_height; |
michael@0 | 97 | if (window.innerHeight) |
michael@0 | 98 | viewport_height = window.innerHeight; |
michael@0 | 99 | else |
michael@0 | 100 | viewport_height = $(window).height(); |
michael@0 | 101 | sidebarbutton.find('span').css({ |
michael@0 | 102 | 'display': 'block', |
michael@0 | 103 | 'margin-top': (viewport_height - sidebar.position().top - 20) / 2 |
michael@0 | 104 | }); |
michael@0 | 105 | |
michael@0 | 106 | sidebarbutton.click(toggle_sidebar); |
michael@0 | 107 | sidebarbutton.attr('title', _('Collapse sidebar')); |
michael@0 | 108 | sidebarbutton.css({ |
michael@0 | 109 | 'color': '#FFFFFF', |
michael@0 | 110 | 'border-left': '1px solid ' + dark_color, |
michael@0 | 111 | 'font-size': '1.2em', |
michael@0 | 112 | 'cursor': 'pointer', |
michael@0 | 113 | 'height': bodywrapper.height(), |
michael@0 | 114 | 'padding-top': '1px', |
michael@0 | 115 | 'margin-left': ssb_width_expanded - 12 |
michael@0 | 116 | }); |
michael@0 | 117 | |
michael@0 | 118 | sidebarbutton.hover( |
michael@0 | 119 | function () { |
michael@0 | 120 | $(this).css('background-color', dark_color); |
michael@0 | 121 | }, |
michael@0 | 122 | function () { |
michael@0 | 123 | $(this).css('background-color', light_color); |
michael@0 | 124 | } |
michael@0 | 125 | ); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | function set_position_from_cookie() { |
michael@0 | 129 | if (!document.cookie) |
michael@0 | 130 | return; |
michael@0 | 131 | var items = document.cookie.split(';'); |
michael@0 | 132 | for(var k=0; k<items.length; k++) { |
michael@0 | 133 | var key_val = items[k].split('='); |
michael@0 | 134 | var key = key_val[0]; |
michael@0 | 135 | if (key == 'sidebar') { |
michael@0 | 136 | var value = key_val[1]; |
michael@0 | 137 | if ((value == 'collapsed') && (!sidebar_is_collapsed())) |
michael@0 | 138 | collapse_sidebar(); |
michael@0 | 139 | else if ((value == 'expanded') && (sidebar_is_collapsed())) |
michael@0 | 140 | expand_sidebar(); |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | add_sidebar_button(); |
michael@0 | 146 | var sidebarbutton = $('#sidebarbutton'); |
michael@0 | 147 | set_position_from_cookie(); |
michael@0 | 148 | }); |