Skip to content

Commit 4c4158e

Browse files
committed
2nd round code review fixes
1 parent 799ae5b commit 4c4158e

9 files changed

Lines changed: 176 additions & 148 deletions

File tree

package-lock.json

Lines changed: 23 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@internetarchive/icon-magnify-minus": "^1.4.0",
4343
"@internetarchive/icon-magnify-plus": "^1.4.0",
4444
"@internetarchive/icon-search": "^1.4.0",
45+
"@internetarchive/icon-share": "1.4.0",
4546
"@internetarchive/icon-toc": "^1.4.0",
4647
"@internetarchive/icon-visual-adjustment": "^1.4.0",
4748
"@internetarchive/modal-manager": "^0.2.12",

src/css/_TextSelection.scss

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,61 @@
152152
display: none;
153153
}
154154

155+
.br-selection-menu__root {
156+
display: none;
157+
border-radius: 20px;
158+
background-color: #333;
159+
color-scheme: dark;
160+
padding: 2px;
161+
overflow: hidden;
162+
transition: border-radius 0.2s;
163+
}
164+
.br-selection-menu__root:hover {
165+
border-radius: 8px;
166+
}
167+
168+
.br-selection-menu__root:hover .textFragmentButton {
169+
border-radius: 6px;
170+
}
171+
155172
.textFragmentButton {
156-
background: inherit;
157-
background-position: center;
158-
background-repeat: no-repeat;
159-
background-color: darksalmon;
160-
width: 60px;
161-
height: 30px;
162-
top: inherit;
163-
left: inherit;
173+
--iconWidth: 15px;
174+
--iconHeight: 15px;
175+
--iconFillColor: currentColor;
176+
background: transparent;
177+
display: flex;
178+
align-items: center;
179+
border-radius: 20px;
180+
font-family: inherit;
181+
border: 0;
182+
transition: background-color 0.2s, border-radius 0.2s;
183+
cursor: pointer;
184+
text-wrap: nowrap;
185+
padding: 4px;
164186
}
165187

166-
.textFragmentButtonBar {
167-
display: none;
188+
.textFragmentButton:hover {
189+
background-color: rgba(255, 255, 255, 0.1);
190+
}
191+
192+
.textFragmentButton ia-icon-share {
193+
display: block;
194+
flex-shrink: 0;
195+
width: 17px;
196+
height: 17px;
197+
}
198+
199+
.menuOptionTitle {
200+
width: 0px;
201+
opacity: 0;
202+
interpolate-size: allow-keywords;
203+
transition: width 0.2s;
204+
font-size: 12px;
205+
}
206+
207+
208+
.br-selection-menu__root:hover .menuOptionTitle {
209+
width: auto;
210+
margin-left: 4px;
211+
opacity: 1;
168212
}

src/plugins/plugin.experiments.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ export class ExperimentsPlugin extends BookReaderPlugin {
5151
localStorageKey: 'BrExperiments',
5252

5353
/** The experiments that should be shown in the experiments panel */
54-
enabledExperiments: ['translate', 'highlightUrl'],
54+
enabledExperiments: ['translate', 'copyToSelectionUrl'],
5555
}
5656

5757
/** @type {ExperimentModel[]} */
5858
allExperiments = [
5959
new class extends ExperimentModel {
60-
name = 'highlightUrl';
61-
title = 'URL Link to Highlight';
62-
description = 'Share highlighted content via URL';
60+
name = 'copyToSelectionUrl';
61+
title = 'Copy to Selection URL';
62+
description = 'Share text selection via URL';
6363
learnMore = 'none';
64-
icon = 'images/translate.svg';
64+
icon = null;
6565
enabled = false;
6666
async enable ({ manual = false }) {
6767
this.br.plugins.textSelection.enableExperiment();

src/plugins/plugin.text_selection.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ export class TextSelectionPlugin extends BookReaderPlugin {
6464
}
6565

6666
enableExperiment() {
67-
if (!this.textSelectionManager) return;
68-
this.textSelectionManager.highlightEnabled = true;
69-
this.textSelectionManager.addHighlightBar();
67+
this.textSelectionManager.selectionMenuEnabled = true;
68+
this.textSelectionManager.renderSelectionMenu();
7069
}
7170

7271
/**

src/plugins/url/plugin.url.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ BookReader.prototype.urlUpdateFragment = function() {
171171
const newFragmentWithSlash = newFragment === '' ? '' : `/${newFragment}`;
172172
const textFragment = this.urlPlugin.retrieveTextFragment(newQueryString);
173173
const newUrlPath = `${baseWithoutSlash}${newFragmentWithSlash}${newQueryString}`;
174-
let extractedPage = newFragmentWithSlash.match(/(?<=\/)n?\d+(?=\/)/);
175-
if (extractedPage) {
176-
extractedPage = extractedPage[0];
177-
}
174+
const extractedPage = this.urlPlugin.urlStringToUrlState(newFragmentWithSlash)?.page;
178175
if (!this.textFragmentPage && textFragment) {
179176
this.textFragmentPage = extractedPage ? extractedPage : null;
180177
this.textFragment = `:~:text=${textFragment}`;
@@ -261,14 +258,13 @@ export class BookreaderUrlPlugin extends BookReader {
261258
this.on('textLayerVisible', async (_, {pageContainerEl}) => {
262259
const visiblePageNum = pageContainerEl.getAttribute('data-page-num');
263260
await new Promise(resolve => setTimeout(resolve, 100));
261+
// No textFragment found or the textFragment stored doesn't match current visible page loaded
262+
if (!this.textFragment || this.textFragmentPage !== visiblePageNum) return;
264263
if (this.options.urlMode === 'history') {
265-
if (this.textFragment && this.textFragmentPage == visiblePageNum) {
266-
window.location.replace(`#${this.textFragment}`);
267-
}
264+
window.location.replace(`#${this.textFragment}`);
268265
} else {
269-
if (this.textFragment && this.textFragmentPage == visiblePageNum) {
270-
window.location.replace(`#${this.oldLocationHash}`);
271-
}
266+
// for urlMode hash, textFragment is stored in oldLocationHash already
267+
window.location.replace(`#${this.oldLocationHash}`);
272268
}
273269
});
274270
}

0 commit comments

Comments
 (0)