Skip to content

Commit

Permalink
Merge pull request #9208 from rhendric/scrolling-modes
Browse files Browse the repository at this point in the history
Add scrolling and spread modes to web viewer
  • Loading branch information
Rob--W authored May 15, 2018
2 parents 91a8027 + d7c051e commit 7ba5044
Show file tree
Hide file tree
Showing 27 changed files with 985 additions and 128 deletions.
26 changes: 26 additions & 0 deletions extensions/chromium/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,32 @@
</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>
100 changes: 24 additions & 76 deletions extensions/chromium/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
22 changes: 22 additions & 0 deletions extensions/chromium/preferences_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 14 additions & 0 deletions l10n/en-US/viewer.properties
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ cursor_text_select_tool_label=Text Selection Tool
cursor_hand_tool.title=Enable Hand Tool
cursor_hand_tool_label=Hand Tool

scroll_vertical.title=Use Vertical Scrolling
scroll_vertical_label=Vertical Scrolling
scroll_horizontal.title=Use Horizontal Scrolling
scroll_horizontal_label=Horizontal Scrolling
scroll_wrapped.title=Use Wrapped Scrolling
scroll_wrapped_label=Wrapped Scrolling

spread_none.title=Do not join page spreads
spread_none_label=No Spreads
spread_odd.title=Join page spreads starting with odd-numbered pages
spread_odd_label=Odd Spreads
spread_even.title=Join page spreads starting with even-numbered pages
spread_even_label=Even Spreads

# Document properties dialog box
document_properties.title=Document Properties…
document_properties_label=Document Properties…
Expand Down
Loading

0 comments on commit 7ba5044

Please sign in to comment.