mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
fixed error in removing marker
This commit is contained in:
parent
ed82dfe736
commit
4cf8bbc161
9 changed files with 72 additions and 33 deletions
|
@ -2607,6 +2607,11 @@ EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){
|
|||
|
||||
cfi = new EPUBJS.EpubCFI(cfiString);
|
||||
spinePos = cfi.spinePos;
|
||||
|
||||
if(spinePos == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
spineItem = this.spine[spinePos];
|
||||
promise = deferred.promise;
|
||||
this._moving = true;
|
||||
|
@ -3463,6 +3468,10 @@ EPUBJS.EpubCFI.prototype.parse = function(cfiStr) {
|
|||
path,
|
||||
end,
|
||||
text;
|
||||
|
||||
if(typeof cfiStr !== "string") {
|
||||
return {spinePos: -1};
|
||||
}
|
||||
|
||||
cfi.str = cfiStr;
|
||||
|
||||
|
@ -3569,7 +3578,7 @@ EPUBJS.EpubCFI.prototype.addMarker = function(cfi, _doc, _marker) {
|
|||
if(lastStep && lastStep.type === "text") {
|
||||
text = parent.childNodes[lastStep.index];
|
||||
if(cfi.characterOffset){
|
||||
split = text.splitText();
|
||||
split = text.splitText(cfi.characterOffset);
|
||||
marker.classList.add("EPUBJS-CFI-SPLIT");
|
||||
parent.insertBefore(marker, split);
|
||||
} else {
|
||||
|
@ -3595,20 +3604,22 @@ EPUBJS.EpubCFI.prototype.removeMarker = function(marker, _doc) {
|
|||
var doc = _doc || document;
|
||||
// var id = marker.id;
|
||||
|
||||
// Remove only elements added as markers
|
||||
if(marker.classList.contains("EPUBJS-CFI-MARKER")){
|
||||
marker.parentElement.removeChild(marker);
|
||||
}
|
||||
|
||||
// Cleanup textnodes
|
||||
// Cleanup textnodes if they were split
|
||||
if(marker.classList.contains("EPUBJS-CFI-SPLIT")){
|
||||
nextSib = marker.nextSibling;
|
||||
prevSib = marker.previousSibling;
|
||||
if(nextSib.nodeType === 3 && prevSib.nodeType === 3){
|
||||
if(nextSib &&
|
||||
prevSib &&
|
||||
nextSib.nodeType === 3 &&
|
||||
prevSib.nodeType === 3){
|
||||
|
||||
prevSib.innerText += nextSib.innerText;
|
||||
marker.parentElement.removeChild(nextSib);
|
||||
}
|
||||
marker.parentElement.removeChild(marker);
|
||||
} else if(marker.classList.contains("EPUBJS-CFI-MARKER")) {
|
||||
// Remove only elements added as markers
|
||||
marker.parentElement.removeChild(marker);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
4
build/epub.min.js
vendored
4
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -2606,6 +2606,11 @@ EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){
|
|||
|
||||
cfi = new EPUBJS.EpubCFI(cfiString);
|
||||
spinePos = cfi.spinePos;
|
||||
|
||||
if(spinePos == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
spineItem = this.spine[spinePos];
|
||||
promise = deferred.promise;
|
||||
this._moving = true;
|
||||
|
@ -3462,6 +3467,10 @@ EPUBJS.EpubCFI.prototype.parse = function(cfiStr) {
|
|||
path,
|
||||
end,
|
||||
text;
|
||||
|
||||
if(typeof cfiStr !== "string") {
|
||||
return {spinePos: -1};
|
||||
}
|
||||
|
||||
cfi.str = cfiStr;
|
||||
|
||||
|
@ -3568,7 +3577,7 @@ EPUBJS.EpubCFI.prototype.addMarker = function(cfi, _doc, _marker) {
|
|||
if(lastStep && lastStep.type === "text") {
|
||||
text = parent.childNodes[lastStep.index];
|
||||
if(cfi.characterOffset){
|
||||
split = text.splitText();
|
||||
split = text.splitText(cfi.characterOffset);
|
||||
marker.classList.add("EPUBJS-CFI-SPLIT");
|
||||
parent.insertBefore(marker, split);
|
||||
} else {
|
||||
|
@ -3594,20 +3603,22 @@ EPUBJS.EpubCFI.prototype.removeMarker = function(marker, _doc) {
|
|||
var doc = _doc || document;
|
||||
// var id = marker.id;
|
||||
|
||||
// Remove only elements added as markers
|
||||
if(marker.classList.contains("EPUBJS-CFI-MARKER")){
|
||||
marker.parentElement.removeChild(marker);
|
||||
}
|
||||
|
||||
// Cleanup textnodes
|
||||
// Cleanup textnodes if they were split
|
||||
if(marker.classList.contains("EPUBJS-CFI-SPLIT")){
|
||||
nextSib = marker.nextSibling;
|
||||
prevSib = marker.previousSibling;
|
||||
if(nextSib.nodeType === 3 && prevSib.nodeType === 3){
|
||||
if(nextSib &&
|
||||
prevSib &&
|
||||
nextSib.nodeType === 3 &&
|
||||
prevSib.nodeType === 3){
|
||||
|
||||
prevSib.innerText += nextSib.innerText;
|
||||
marker.parentElement.removeChild(nextSib);
|
||||
}
|
||||
marker.parentElement.removeChild(marker);
|
||||
} else if(marker.classList.contains("EPUBJS-CFI-MARKER")) {
|
||||
// Remove only elements added as markers
|
||||
marker.parentElement.removeChild(marker);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -403,6 +403,7 @@ EPUBJS.reader.ControlsController = function(book) {
|
|||
});
|
||||
|
||||
book.on('renderer:locationChanged', function(cfi){
|
||||
var cfiFragment = "#" + cfi;
|
||||
//-- Check if bookmarked
|
||||
var bookmarked = reader.isBookmarked(cfi);
|
||||
if(bookmarked === -1) { //-- Not bookmarked
|
||||
|
@ -416,8 +417,10 @@ EPUBJS.reader.ControlsController = function(book) {
|
|||
}
|
||||
|
||||
// Update the History Location
|
||||
if(reader.settings.history) {
|
||||
history.pushState({}, '', "#"+cfi);
|
||||
if(reader.settings.history &&
|
||||
window.location.hash != cfiFragment) {
|
||||
// Add CFI fragment to the history
|
||||
history.pushState({}, '', cfiFragment);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
4
demo/js/epub.min.js
vendored
4
demo/js/epub.min.js
vendored
File diff suppressed because one or more lines are too long
2
demo/js/reader.min.js
vendored
2
demo/js/reader.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -80,6 +80,7 @@ EPUBJS.reader.ControlsController = function(book) {
|
|||
});
|
||||
|
||||
book.on('renderer:locationChanged', function(cfi){
|
||||
var cfiFragment = "#" + cfi;
|
||||
//-- Check if bookmarked
|
||||
var bookmarked = reader.isBookmarked(cfi);
|
||||
if(bookmarked === -1) { //-- Not bookmarked
|
||||
|
@ -93,8 +94,10 @@ EPUBJS.reader.ControlsController = function(book) {
|
|||
}
|
||||
|
||||
// Update the History Location
|
||||
if(reader.settings.history) {
|
||||
history.pushState({}, '', "#"+cfi);
|
||||
if(reader.settings.history &&
|
||||
window.location.hash != cfiFragment) {
|
||||
// Add CFI fragment to the history
|
||||
history.pushState({}, '', cfiFragment);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -831,6 +831,11 @@ EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){
|
|||
|
||||
cfi = new EPUBJS.EpubCFI(cfiString);
|
||||
spinePos = cfi.spinePos;
|
||||
|
||||
if(spinePos == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
spineItem = this.spine[spinePos];
|
||||
promise = deferred.promise;
|
||||
this._moving = true;
|
||||
|
|
|
@ -97,6 +97,10 @@ EPUBJS.EpubCFI.prototype.parse = function(cfiStr) {
|
|||
path,
|
||||
end,
|
||||
text;
|
||||
|
||||
if(typeof cfiStr !== "string") {
|
||||
return {spinePos: -1};
|
||||
}
|
||||
|
||||
cfi.str = cfiStr;
|
||||
|
||||
|
@ -203,7 +207,7 @@ EPUBJS.EpubCFI.prototype.addMarker = function(cfi, _doc, _marker) {
|
|||
if(lastStep && lastStep.type === "text") {
|
||||
text = parent.childNodes[lastStep.index];
|
||||
if(cfi.characterOffset){
|
||||
split = text.splitText();
|
||||
split = text.splitText(cfi.characterOffset);
|
||||
marker.classList.add("EPUBJS-CFI-SPLIT");
|
||||
parent.insertBefore(marker, split);
|
||||
} else {
|
||||
|
@ -229,20 +233,22 @@ EPUBJS.EpubCFI.prototype.removeMarker = function(marker, _doc) {
|
|||
var doc = _doc || document;
|
||||
// var id = marker.id;
|
||||
|
||||
// Remove only elements added as markers
|
||||
if(marker.classList.contains("EPUBJS-CFI-MARKER")){
|
||||
marker.parentElement.removeChild(marker);
|
||||
}
|
||||
|
||||
// Cleanup textnodes
|
||||
// Cleanup textnodes if they were split
|
||||
if(marker.classList.contains("EPUBJS-CFI-SPLIT")){
|
||||
nextSib = marker.nextSibling;
|
||||
prevSib = marker.previousSibling;
|
||||
if(nextSib.nodeType === 3 && prevSib.nodeType === 3){
|
||||
if(nextSib &&
|
||||
prevSib &&
|
||||
nextSib.nodeType === 3 &&
|
||||
prevSib.nodeType === 3){
|
||||
|
||||
prevSib.innerText += nextSib.innerText;
|
||||
marker.parentElement.removeChild(nextSib);
|
||||
}
|
||||
marker.parentElement.removeChild(marker);
|
||||
} else if(marker.classList.contains("EPUBJS-CFI-MARKER")) {
|
||||
// Remove only elements added as markers
|
||||
marker.parentElement.removeChild(marker);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue