- var layout = this;
- if ( !this.scrolling && page ) {
- page.scrollElementIntoView().done( function () {
- if ( layout.autoFocus && !OO.ui.isMobile() ) {
- layout.focus();
- }
+ var promise, layout = this;
+ // If everything is unselected, do nothing
+ if ( !page ) {
+ return;
+ }
+ // For continuous BookletLayouts, scroll the selected page into view first
+ if ( this.stackLayout.continuous && !this.scrolling ) {
+ promise = page.scrollElementIntoView();
+ } else {
+ promise = $.Deferred().resolve();
+ }
+ // Focus the first element on the newly selected panel
+ if ( this.autoFocus && !OO.ui.isMobile() ) {
+ promise.done( function () {
+ layout.focus();