Skip to content

Commit

Permalink
Merge pull request mozilla#8576 from Snuffleupagus/toolbar-inline-sel…
Browse files Browse the repository at this point in the history
…ectScaleOption

Remove the `selectScaleOption` helper function, in `Toolbar._updateUIState`, and simply inline its code instead
  • Loading branch information
timvandermeij authored Jun 26, 2017
2 parents aee0eeb + 20f69b9 commit fca84ea
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions web/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ class Toolbar {
}

_bindListeners() {
let eventBus = this.eventBus;
let { eventBus, items, } = this;
let self = this;
let items = this.items;

items.previous.addEventListener('click', function() {
eventBus.dispatch('previouspage');
Expand Down Expand Up @@ -172,36 +171,10 @@ class Toolbar {
// Don't update the UI state until we localize the toolbar.
return;
}

let selectScaleOption = (value, scale) => {
let customScale = Math.round(scale * 10000) / 100;
this.l10n.get('page_scale_percent', { scale: customScale, },
'{{scale}}%').then((msg) => {
let options = items.scaleSelect.options;
let predefinedValueFound = false;
for (let i = 0, ii = options.length; i < ii; i++) {
let option = options[i];
if (option.value !== value) {
option.selected = false;
continue;
}
option.selected = true;
predefinedValueFound = true;
}
if (!predefinedValueFound) {
items.customScaleOption.textContent = msg;
items.customScaleOption.selected = true;
}
});
};

let pageNumber = this.pageNumber;
let { pageNumber, pagesCount, items, } = this;
let scaleValue = (this.pageScaleValue || this.pageScale).toString();
let scale = this.pageScale;

let items = this.items;
let pagesCount = this.pagesCount;

if (resetNumPages) {
if (this.hasPageLabels) {
items.pageNumber.type = 'text';
Expand All @@ -218,8 +191,7 @@ class Toolbar {
if (this.hasPageLabels) {
items.pageNumber.value = this.pageLabel;
this.l10n.get('page_of_pages', { pageNumber, pagesCount, },
'({{pageNumber}} of {{pagesCount}})').
then((msg) => {
'({{pageNumber}} of {{pagesCount}})').then((msg) => {
items.numPages.textContent = msg;
});
} else {
Expand All @@ -232,7 +204,25 @@ class Toolbar {
items.zoomOut.disabled = (scale <= MIN_SCALE);
items.zoomIn.disabled = (scale >= MAX_SCALE);

selectScaleOption(scaleValue, scale);
let customScale = Math.round(scale * 10000) / 100;
this.l10n.get('page_scale_percent', { scale: customScale, },
'{{scale}}%').then((msg) => {
let options = items.scaleSelect.options;
let predefinedValueFound = false;
for (let i = 0, ii = options.length; i < ii; i++) {
let option = options[i];
if (option.value !== scaleValue) {
option.selected = false;
continue;
}
option.selected = true;
predefinedValueFound = true;
}
if (!predefinedValueFound) {
items.customScaleOption.textContent = msg;
items.customScaleOption.selected = true;
}
});
}

updateLoadingIndicatorState(loading = false) {
Expand Down

0 comments on commit fca84ea

Please sign in to comment.