Skip to content

Commit

Permalink
Viewer: consistently wrap find bar elements for small screen sizes
Browse files Browse the repository at this point in the history
This patch ensures that the find bar is not extended to the window width
when element wrapping occurs on small screens.
  • Loading branch information
Snuffleupagus authored and timvandermeij committed Mar 6, 2017
1 parent ac6efbc commit e46eb8e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
32 changes: 31 additions & 1 deletion web/pdf_find_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ var PDFFindBar = (function PDFFindBarClosure() {
this.caseSensitive.addEventListener('click', function() {
self.dispatchEvent('casesensitivitychange');
});

this.eventBus.on('resize', this._adjustWidth.bind(this));
}

PDFFindBar.prototype = {
Expand Down Expand Up @@ -155,6 +157,7 @@ var PDFFindBar = (function PDFFindBarClosure() {
this.findMsg.textContent = findMsg;

this.updateResultsCount(matchCount);
this._adjustWidth();
},

updateResultsCount: function(matchCount) {
Expand Down Expand Up @@ -183,6 +186,8 @@ var PDFFindBar = (function PDFFindBarClosure() {
}
this.findField.select();
this.findField.focus();

this._adjustWidth();
},

close: function PDFFindBar_close() {
Expand All @@ -201,7 +206,32 @@ var PDFFindBar = (function PDFFindBarClosure() {
} else {
this.open();
}
}
},

/**
* @private
*/
_adjustWidth: function PDFFindBar_adjustWidth() {
if (!this.opened) {
return;
}

// The find bar has an absolute position and thus the browser extends
// its width to the maximum possible width once the find bar does not fit
// entirely within the window anymore (and needs to be wrapped). Here we
// detect and fix that.
this.bar.classList.remove('wrapContainers');

var findbarHeight = this.bar.clientHeight;
var inputContainerHeight = this.bar.firstElementChild.clientHeight;

if (findbarHeight > inputContainerHeight) {
// The findbar is higher than the input container, which means that
// the browser wrapped some of the elements. For a consistent look,
// wrap all of them to adjust the width of the find bar.
this.bar.classList.add('wrapContainers');
}
},
};
return PDFFindBar;
})();
Expand Down
7 changes: 7 additions & 0 deletions web/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@ html[dir='rtl'] #toolbarContainer, .findbar, .secondaryToolbar {
.findbar > div {
height: 32px;
}
.findbar.wrapContainers > div {
clear: both;
}
.findbar.wrapContainers > div#findbarMessageContainer {
height: auto;
max-height: 32px;
}
html[dir='ltr'] .findbar {
left: 68px;
}
Expand Down

0 comments on commit e46eb8e

Please sign in to comment.