mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-18 16:45:11 +00:00
Fix position of glossary icon relative to sidebar toggler
This commit is contained in:
@@ -27,6 +27,7 @@ function start(config) {
|
||||
|
||||
// Add action to toggle sidebar
|
||||
toolbar.createButton({
|
||||
index: 0,
|
||||
icon: 'fa fa-align-justify',
|
||||
onClick: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -6,6 +6,18 @@ var events = require('./events');
|
||||
// List of created buttons
|
||||
var buttons = [];
|
||||
|
||||
// Insert a jquery element at a specific position
|
||||
function insertAt(parent, selector, index, element) {
|
||||
var lastIndex = parent.children(selector).size();
|
||||
if (index < 0) {
|
||||
index = Math.max(0, lastIndex + 1 + index);
|
||||
}
|
||||
parent.append(element);
|
||||
|
||||
if (index < lastIndex) {
|
||||
parent.children(selector).eq(index).before(parent.children(selector).last());
|
||||
}
|
||||
}
|
||||
|
||||
// Default click handler
|
||||
function defaultOnClick(e) {
|
||||
@@ -83,7 +95,10 @@ function createButton(opts) {
|
||||
onClick: defaultOnClick,
|
||||
|
||||
// Button is a dropdown
|
||||
dropdown: null
|
||||
dropdown: null,
|
||||
|
||||
// Position in the toolbar
|
||||
index: null
|
||||
});
|
||||
|
||||
buttons.push(opts);
|
||||
@@ -92,6 +107,7 @@ function createButton(opts) {
|
||||
|
||||
// Update a button
|
||||
function updateButton(opts) {
|
||||
var $result;
|
||||
var $toolbar = $('.book-header');
|
||||
var $title = $toolbar.find('h1');
|
||||
|
||||
@@ -133,12 +149,17 @@ function updateButton(opts) {
|
||||
$menu.addClass('dropdown-'+(opts.position == 'right'? 'left' : 'right'));
|
||||
|
||||
$container.append($menu);
|
||||
|
||||
$container.insertBefore($title);
|
||||
$result = $container;
|
||||
} else {
|
||||
$btn.addClass(positionClass);
|
||||
$btn.addClass(opts.className);
|
||||
$btn.insertBefore($title);
|
||||
$result = $btn;
|
||||
}
|
||||
|
||||
if (_.isNumber(opts.index) && opts.index >= 0) {
|
||||
insertAt($toolbar, '.btn, .dropdown', opts.index, $result);
|
||||
} else {
|
||||
$result.insertBefore($title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user