Correctly reset buttons when page changed

This commit is contained in:
Samy Pessé
2015-10-05 12:13:54 +02:00
parent 90715c1944
commit 222ec8d4b9
2 changed files with 26 additions and 5 deletions
+25 -4
View File
@@ -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
};