don't deselect on click, only scroll if not in view
This commit is contained in:
parent
2c5c56c036
commit
9c765bf863
2 changed files with 10 additions and 8 deletions
|
@ -113,9 +113,7 @@ function getText(book, cfiRange, cb) {
|
||||||
|
|
||||||
function onHighlightClicked(e) {
|
function onHighlightClicked(e) {
|
||||||
console.log("highlight clicked", e.target.dataset.epubcfi);
|
console.log("highlight clicked", e.target.dataset.epubcfi);
|
||||||
if(e.target.classList.contains('selected')) {
|
if(!e.target.classList.contains('selected')) {
|
||||||
e.target.classList.remove('selected')
|
|
||||||
} else {
|
|
||||||
document.querySelectorAll('.epubjs-hl.selected').forEach(function(other) {
|
document.querySelectorAll('.epubjs-hl.selected').forEach(function(other) {
|
||||||
other.classList.remove('selected')
|
other.classList.remove('selected')
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,7 +22,7 @@ Ox.load({
|
||||||
}
|
}
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var el = document.querySelector('.a' + annotation.id);
|
var el = document.querySelector('.a' + annotation.id);
|
||||||
if (el) {
|
if (el && !isInView(el)) {
|
||||||
document.querySelector('#viewerContainer').scrollTop = el.offsetTop + el.parentElement.offsetTop - 64;
|
document.querySelector('#viewerContainer').scrollTop = el.offsetTop + el.parentElement.offsetTop - 64;
|
||||||
}
|
}
|
||||||
}, delay)
|
}, delay)
|
||||||
|
@ -134,10 +134,7 @@ function renderAnnotation(annotation) {
|
||||||
'width:' + Math.abs(bounds[0] - bounds[2]) + 'px; height:' + Math.abs(bounds[1] - bounds[3]) + 'px;');
|
'width:' + Math.abs(bounds[0] - bounds[2]) + 'px; height:' + Math.abs(bounds[1] - bounds[3]) + 'px;');
|
||||||
|
|
||||||
el.addEventListener('click', function() {
|
el.addEventListener('click', function() {
|
||||||
if (el.classList.contains('selected')) {
|
if (!el.classList.contains('selected')) {
|
||||||
deselectAnnotation(annotation.id)
|
|
||||||
Ox.$parent.postMessage('selectAnnotation', {id: null})
|
|
||||||
} else {
|
|
||||||
selectAnnotation(annotation.id)
|
selectAnnotation(annotation.id)
|
||||||
Ox.$parent.postMessage('selectAnnotation', {id: annotation.id})
|
Ox.$parent.postMessage('selectAnnotation', {id: annotation.id})
|
||||||
}
|
}
|
||||||
|
@ -204,3 +201,10 @@ function loadAnnotations(page) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isInView(element) {
|
||||||
|
var docViewTop = $(window).scrollTop();
|
||||||
|
var docViewBottom = docViewTop + $(window).height();
|
||||||
|
var elementTop = $(element).offset().top;
|
||||||
|
var elementBottom = elementTop + $(element).height();
|
||||||
|
return elementTop < docViewBottom && elementBottom > docViewTop;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue