1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Add preferences for default scroll/spread modes

This commit adds `scrollModeOnLoad` and `spreadModeOnLoad` preferences
that control the default viewer state when opening a new document for
the first time.

This commit also contains a minor refactoring of some of the option UI
rendering code in extensions/chromium/options/options.js, as I couldn't
bear creating two more functions nearly identical to the four that
already existed.
This commit is contained in:
Ryan Hendrickson 2018-05-14 23:10:33 -04:00
parent c24bc29757
commit d7c051e807
5 changed files with 87 additions and 79 deletions

View file

@ -75,16 +75,15 @@ Promise.all([
renderPreference = renderBooleanPref(prefSchema.title,
prefSchema.description,
prefName);
} else if (prefSchema.type === 'integer' && prefSchema.enum) {
// Most other prefs are integer-valued enumerations, render them in a
// generic way too.
// Unlike the renderBooleanPref branch, each preference handled by this
// branch still needs its own template in options.html with
// id="$prefName-template".
renderPreference = renderEnumPref(prefSchema.title, prefName);
} else if (prefName === 'defaultZoomValue') {
renderPreference = renderDefaultZoomValue(prefSchema.title);
} else if (prefName === 'sidebarViewOnLoad') {
renderPreference = renderSidebarViewOnLoad(prefSchema.title);
} else if (prefName === 'cursorToolOnLoad') {
renderPreference = renderCursorToolOnLoad(prefSchema.title);
} else if (prefName === 'textLayerMode') {
renderPreference = renderTextLayerMode(prefSchema.title);
} else if (prefName === 'externalLinkTarget') {
renderPreference = renderExternalLinkTarget(prefSchema.title);
} else {
// Should NEVER be reached. Only happens if a new type of preference is
// added to the storage manifest.
@ -156,6 +155,23 @@ function renderBooleanPref(shortDescription, description, prefName) {
return renderPreference;
}
function renderEnumPref(shortDescription, prefName) {
var wrapper = importTemplate(prefName + '-template');
var select = wrapper.querySelector('select');
select.onchange = function() {
var pref = {};
pref[prefName] = parseInt(this.value);
storageArea.set(pref);
};
wrapper.querySelector('span').textContent = shortDescription;
document.getElementById('settings-boxes').appendChild(wrapper);
function renderPreference(value) {
select.value = value;
}
return renderPreference;
}
function renderDefaultZoomValue(shortDescription) {
var wrapper = importTemplate('defaultZoomValue-template');
var select = wrapper.querySelector('select');
@ -184,71 +200,3 @@ function renderDefaultZoomValue(shortDescription) {
}
return renderPreference;
}
function renderSidebarViewOnLoad(shortDescription) {
var wrapper = importTemplate('sidebarViewOnLoad-template');
var select = wrapper.querySelector('select');
select.onchange = function() {
storageArea.set({
sidebarViewOnLoad: parseInt(this.value),
});
};
wrapper.querySelector('span').textContent = shortDescription;
document.getElementById('settings-boxes').appendChild(wrapper);
function renderPreference(value) {
select.value = value;
}
return renderPreference;
}
function renderCursorToolOnLoad(shortDescription) {
var wrapper = importTemplate('cursorToolOnLoad-template');
var select = wrapper.querySelector('select');
select.onchange = function() {
storageArea.set({
cursorToolOnLoad: parseInt(this.value),
});
};
wrapper.querySelector('span').textContent = shortDescription;
document.getElementById('settings-boxes').appendChild(wrapper);
function renderPreference(value) {
select.value = value;
}
return renderPreference;
}
function renderTextLayerMode(shortDescription) {
var wrapper = importTemplate('textLayerMode-template');
var select = wrapper.querySelector('select');
select.onchange = function() {
storageArea.set({
textLayerMode: parseInt(this.value),
});
};
wrapper.querySelector('span').textContent = shortDescription;
document.getElementById('settings-boxes').appendChild(wrapper);
function renderPreference(value) {
select.value = value;
}
return renderPreference;
}
function renderExternalLinkTarget(shortDescription) {
var wrapper = importTemplate('externalLinkTarget-template');
var select = wrapper.querySelector('select');
select.onchange = function() {
storageArea.set({
externalLinkTarget: parseInt(this.value),
});
};
wrapper.querySelector('span').textContent = shortDescription;
document.getElementById('settings-boxes').appendChild(wrapper);
function renderPreference(value) {
select.value = value;
}
return renderPreference;
}