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
|
@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue