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:
parent
c24bc29757
commit
d7c051e807
@ -120,6 +120,32 @@ body {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="scrollModeOnLoad-template">
|
||||
<div class="settings-row">
|
||||
<label>
|
||||
<span></span>
|
||||
<select>
|
||||
<option value="0">Vertical scrolling</option>
|
||||
<option value="1">Horizontal scrolling</option>
|
||||
<option value="2">Wrapped scrolling</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="spreadModeOnLoad-template">
|
||||
<div class="settings-row">
|
||||
<label>
|
||||
<span></span>
|
||||
<select>
|
||||
<option value="0">No spreads</option>
|
||||
<option value="1">Odd spreads</option>
|
||||
<option value="2">Even spreads</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script src="options.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -144,6 +144,28 @@
|
||||
"description": "When enabled, pages whose orientation differ from the first page are rotated when printed.",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"scrollModeOnLoad": {
|
||||
"title": "Scroll mode on load",
|
||||
"description": "Controls how the viewer scrolls upon load.\n 0 = Vertical scrolling.\n 1 = Horizontal scrolling.\n 2 = Wrapped scrolling.",
|
||||
"type": "integer",
|
||||
"enum": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
"default": 0
|
||||
},
|
||||
"spreadModeOnLoad": {
|
||||
"title": "Spread mode on load",
|
||||
"description": "Whether the viewer should join pages into spreads upon load.\n 0 = No spreads.\n 1 = Odd spreads.\n 2 = Even spreads.",
|
||||
"type": "integer",
|
||||
"enum": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
"default": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
web/app.js
14
web/app.js
@ -242,6 +242,12 @@ let PDFViewerApplication = {
|
||||
preferences.get('enablePrintAutoRotate').then(function resolved(value) {
|
||||
AppOptions.set('enablePrintAutoRotate', value);
|
||||
}),
|
||||
preferences.get('scrollModeOnLoad').then(function resolved(value) {
|
||||
AppOptions.set('scrollModeOnLoad', value);
|
||||
}),
|
||||
preferences.get('spreadModeOnLoad').then(function resolved(value) {
|
||||
AppOptions.set('spreadModeOnLoad', value);
|
||||
}),
|
||||
]).catch(function(reason) { });
|
||||
},
|
||||
|
||||
@ -1040,8 +1046,8 @@ let PDFViewerApplication = {
|
||||
('zoom=' + AppOptions.get('defaultZoomValue')) : null;
|
||||
let rotation = null;
|
||||
let sidebarView = AppOptions.get('sidebarViewOnLoad');
|
||||
let scrollMode = null;
|
||||
let spreadMode = null;
|
||||
let scrollMode = AppOptions.get('scrollModeOnLoad');
|
||||
let spreadMode = AppOptions.get('spreadModeOnLoad');
|
||||
|
||||
if (values.exists && AppOptions.get('showPreviousViewOnLoad')) {
|
||||
hash = 'page=' + values.page +
|
||||
@ -1248,6 +1254,10 @@ let PDFViewerApplication = {
|
||||
this.pdfViewer.pagesRotation = angle;
|
||||
}
|
||||
};
|
||||
|
||||
// Putting these before isInitialViewSet = true prevents these values from
|
||||
// being stored in the document history (and overriding any future changes
|
||||
// made to the corresponding global preferences), just this once.
|
||||
if (Number.isInteger(scrollMode)) {
|
||||
this.pdfViewer.setScrollMode(scrollMode);
|
||||
}
|
||||
|
@ -16,5 +16,7 @@
|
||||
"renderInteractiveForms": false,
|
||||
"enablePrintAutoRotate": false,
|
||||
"disablePageMode": false,
|
||||
"disablePageLabels": false
|
||||
"disablePageLabels": false,
|
||||
"scrollModeOnLoad": 0,
|
||||
"spreadModeOnLoad": 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user