mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-22 10:33:22 +00:00
Correctly reset buttons when page changed
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
define([
|
||||
'jQuery',
|
||||
'lodash'
|
||||
], function($, _) {
|
||||
var $toolbar = $('.book-header');
|
||||
var $title = $toolbar.find('h1');
|
||||
'lodash',
|
||||
'core/events'
|
||||
], function($, _, events) {
|
||||
// List of created buttons
|
||||
var buttons = [];
|
||||
|
||||
|
||||
// Default click handler
|
||||
function defaultOnClick(e) {
|
||||
@@ -84,6 +86,15 @@ define([
|
||||
dropdown: null
|
||||
});
|
||||
|
||||
buttons.push(opts);
|
||||
updateButton(opts);
|
||||
}
|
||||
|
||||
// Update a button
|
||||
function updateButton(opts) {
|
||||
var $toolbar = $('.book-header');
|
||||
var $title = $toolbar.find('h1');
|
||||
|
||||
// Build class name
|
||||
var positionClass = 'pull-'+opts.position;
|
||||
|
||||
@@ -127,6 +138,16 @@ define([
|
||||
}
|
||||
}
|
||||
|
||||
// Update all buttons
|
||||
function updateAllButtons() {
|
||||
_.each(buttons, updateButton);
|
||||
}
|
||||
|
||||
// When page changed, reset buttons
|
||||
events.bind('page.change', function() {
|
||||
updateAllButtons();
|
||||
});
|
||||
|
||||
return {
|
||||
createButton: createButton
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user