Upgrade for 'default' theme: collapsiblesidebar works with rightsidebar

This commit is contained in:
Denis 2012-12-10 14:13:35 +04:00
parent c69b7b4253
commit 5b54c253bb
2 changed files with 27 additions and 14 deletions

View File

@ -111,8 +111,7 @@ These themes are:
- **collapsiblesidebar** (true or false): Add an *experimental* JavaScript - **collapsiblesidebar** (true or false): Add an *experimental* JavaScript
snippet that makes the sidebar collapsible via a button on its side. snippet that makes the sidebar collapsible via a button on its side.
*Doesn't work together with "rightsidebar" or "stickysidebar".* Defaults to *Doesn't work with "stickysidebar".* Defaults to false.
false.
- **externalrefs** (true or false): Display external links differently from - **externalrefs** (true or false): Display external links differently from
internal links. Defaults to false. internal links. Defaults to false.

View File

@ -22,6 +22,20 @@
*/ */
$(function() { $(function() {
{% if theme_rightsidebar|tobool %}
{% set side = 'right' %}
{% set opposite = 'left' %}
{% set initial_label = '»' %}
{% set expand_label = '«' %}
{% set collapse_label = '»' %}
{% else %}
{% set side = 'left' %}
{% set opposite = 'right' %}
{% set initial_label = '«' %}
{% set expand_label = '»' %}
{% set collapse_label = '«' %}
{% endif %}
// global elements used by the functions. // global elements used by the functions.
// the 'sidebarbutton' element is defined as global after its // the 'sidebarbutton' element is defined as global after its
// creation, in the add_sidebar_button function // creation, in the add_sidebar_button function
@ -34,7 +48,7 @@ $(function() {
// original margin-left of the bodywrapper and width of the sidebar // original margin-left of the bodywrapper and width of the sidebar
// with the sidebar expanded // with the sidebar expanded
var bw_margin_expanded = bodywrapper.css('margin-left'); var bw_margin_expanded = bodywrapper.css('margin-{{side}}');
var ssb_width_expanded = sidebar.width(); var ssb_width_expanded = sidebar.width();
// margin-left of the bodywrapper and width of the sidebar // margin-left of the bodywrapper and width of the sidebar
@ -60,38 +74,38 @@ $(function() {
function collapse_sidebar() { function collapse_sidebar() {
sidebarwrapper.hide(); sidebarwrapper.hide();
sidebar.css('width', ssb_width_collapsed); sidebar.css('width', ssb_width_collapsed);
bodywrapper.css('margin-left', bw_margin_collapsed); bodywrapper.css('margin-{{side}}', bw_margin_collapsed);
sidebarbutton.css({ sidebarbutton.css({
'margin-left': '0', 'margin-{{side}}': '0',
'height': bodywrapper.height() 'height': bodywrapper.height()
}); });
sidebarbutton.find('span').text('»'); sidebarbutton.find('span').text('{{expand_label}}');
sidebarbutton.attr('title', _('Expand sidebar')); sidebarbutton.attr('title', _('Expand sidebar'));
document.cookie = 'sidebar=collapsed'; document.cookie = 'sidebar=collapsed';
} }
function expand_sidebar() { function expand_sidebar() {
bodywrapper.css('margin-left', bw_margin_expanded); bodywrapper.css('margin-{{side}}', bw_margin_expanded);
sidebar.css('width', ssb_width_expanded); sidebar.css('width', ssb_width_expanded);
sidebarwrapper.show(); sidebarwrapper.show();
sidebarbutton.css({ sidebarbutton.css({
'margin-left': ssb_width_expanded-12, 'margin-{{side}}': ssb_width_expanded-12,
'height': bodywrapper.height() 'height': bodywrapper.height()
}); });
sidebarbutton.find('span').text('«'); sidebarbutton.find('span').text('{{collapse_label}}');
sidebarbutton.attr('title', _('Collapse sidebar')); sidebarbutton.attr('title', _('Collapse sidebar'));
document.cookie = 'sidebar=expanded'; document.cookie = 'sidebar=expanded';
} }
function add_sidebar_button() { function add_sidebar_button() {
sidebarwrapper.css({ sidebarwrapper.css({
'float': 'left', 'float': '{{side}}',
'margin-right': '0', 'margin-{{opposite}}': '0',
'width': ssb_width_expanded - 28 'width': ssb_width_expanded - 28
}); });
// create the button // create the button
sidebar.append( sidebar.append(
'<div id="sidebarbutton"><span>&laquo;</span></div>' '<div id="sidebarbutton"><span>{{initial_label}}</span></div>'
); );
var sidebarbutton = $('#sidebarbutton'); var sidebarbutton = $('#sidebarbutton');
light_color = sidebarbutton.css('background-color'); light_color = sidebarbutton.css('background-color');
@ -110,12 +124,12 @@ $(function() {
sidebarbutton.attr('title', _('Collapse sidebar')); sidebarbutton.attr('title', _('Collapse sidebar'));
sidebarbutton.css({ sidebarbutton.css({
'color': '#FFFFFF', 'color': '#FFFFFF',
'border-left': '1px solid ' + dark_color, 'border-{{side}}': '1px solid ' + dark_color,
'font-size': '1.2em', 'font-size': '1.2em',
'cursor': 'pointer', 'cursor': 'pointer',
'height': bodywrapper.height(), 'height': bodywrapper.height(),
'padding-top': '1px', 'padding-top': '1px',
'margin-left': ssb_width_expanded - 12 'margin-{{side}}': ssb_width_expanded - 12
}); });
sidebarbutton.hover( sidebarbutton.hover(