diff --git a/resources/viewer/referencing.js b/resources/viewer/referencing.js index eceea9f31d..7c2a9d0a3f 100644 --- a/resources/viewer/referencing.js +++ b/resources/viewer/referencing.js @@ -60,8 +60,13 @@ function goto_reference(ref) { if (num < 0) {alert("Invalid reference: "+ref); return;} var p = $("p"); if (num >= p.length) {alert("Reference not found: "+ref); return;} - $.scrollTo($(p[num]), 1000, - {onAfter:function(){window.py_bridge.animated_scroll_done()}}); + var dest = $(p[num]); + if (window.paged_display.in_paged_mode) { + var xpos = dest.offset().left; + window.paged_display.scroll_to_xpos(xpos, true, true, 1000); + } else + $.scrollTo(dest, 1000, + {onAfter:function(){window.py_bridge.animated_scroll_done()}}); } diff --git a/src/calibre/ebooks/oeb/display/paged.coffee b/src/calibre/ebooks/oeb/display/paged.coffee index 263fe27f72..ff16c05085 100644 --- a/src/calibre/ebooks/oeb/display/paged.coffee +++ b/src/calibre/ebooks/oeb/display/paged.coffee @@ -50,14 +50,12 @@ absleft = (elem) -> # {{{ # }}} class PagedDisplay - ### - This class is a namespace to expose functions via the - window.paged_display object. The most important functions are: - - set_geometry(): sets the parameters used to layout text in paged mode - - layout(): causes the currently loaded document to be laid out in columns. - ### + # This class is a namespace to expose functions via the + # window.paged_display object. The most important functions are: + # + # set_geometry(): sets the parameters used to layout text in paged mode + # + # layout(): causes the currently loaded document to be laid out in columns. constructor: () -> if not this instanceof arguments.callee @@ -163,7 +161,7 @@ class PagedDisplay xpos = Math.floor(document.body.scrollWidth * frac) this.scroll_to_xpos(xpos) - scroll_to_xpos: (xpos) -> + scroll_to_xpos: (xpos, animated=false, notify=false, duration=1000) -> # Scroll so that the column containing xpos is the left most column in # the viewport if typeof(xpos) != 'number' @@ -177,7 +175,31 @@ class PagedDisplay pos += this.page_width limit = document.body.scrollWidth - this.screen_width pos = limit if pos > limit - window.scrollTo(pos, 0) + if animated + this.animated_scroll(pos, duration=1000, notify=notify) + else + window.scrollTo(pos, 0) + + animated_scroll: (pos, duration=1000, notify=true) -> + delta = pos - window.pageXOffset + interval = 50 + steps = Math.floor(duration/interval) + step_size = Math.floor(delta/steps) + this.current_scroll_animation = {target:pos, step_size:step_size, interval:interval, notify:notify, fn: () => + a = this.current_scroll_animation + npos = window.pageXOffset + a.step_size + completed = false + if Math.abs(npos - a.target) < Math.abs(a.step_size) + completed = true + npos = a.target + window.scrollTo(npos, 0) + if completed + if notify + window.py_bridge.animated_scroll_done() + else + setTimeout(a.fn, a.interval) + } + this.current_scroll_animation.fn() current_pos: (frac) -> # The current scroll position as a fraction between 0 and 1 @@ -329,7 +351,6 @@ if window? window.paged_display = new PagedDisplay() # TODO: -# Go to reference positions # Indexing # Resizing of images # Full screen mode diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index c74fd649de..8200169025 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -138,7 +138,9 @@ class Reference(QLineEdit): self.editingFinished.connect(self.editing_finished) def editing_finished(self): - self.goto.emit(unicode(self.text())) + text = unicode(self.text()) + self.setText('') + self.goto.emit(text) class RecentAction(QAction):