From 100dd0dd45859cee8e8a12027b50672843cb3e81 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 19 Jun 2012 13:22:00 +0530 Subject: [PATCH] More robust absleft() --- resources/compiled_coffeescript.zip | Bin 35080 -> 36336 bytes src/calibre/ebooks/oeb/display/paged.coffee | 37 ++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index c7b2bf582420f60f42d0cf5ec162cab93d449357..bacbcf8aaf11d325c9b2430b2ae6345b1dcc2112 100644 GIT binary patch delta 157 zcmeB}#Pne{lXQSLGm8iV2&~Gw?4WsP_3PCN3=AMFJ=w8CZldMv$%dw)lYMlAH(pL= z-n_$T3Cms+kYfl*tmkkxYN2Cn+jSp4_X& T^j>|EqUhu+y<%))9Uv # {{{ process.stdout.write(msg + '\n') # }}} -body_height = () -> +body_height = () -> # {{{ db = document.body dde = document.documentElement if db? and dde? return Math.max(db.scrollHeight, dde.scrollHeight, db.offsetHeight, dde.offsetHeight, db.clientHeight, dde.clientHeight) return 0 +# }}} -absleft = (elem) -> +window_scroll_pos = (win=window) -> # {{{ + if typeof(win.pageXOffset) == 'number' + x = win.pageXOffset + y = win.pageYOffset + else # IE < 9 + if document.body and ( document.body.scrollLeft or document.body.scrollTop ) + x = document.body.scrollLeft + y = document.body.scrollTop + else if document.documentElement and ( document.documentElement.scrollLeft or document.documentElement.scrollTop) + y = document.documentElement.scrollTop + x = document.documentElement.scrollLeft + return [x, y] +# }}} + +viewport_to_document = (x, y, doc=window?.document) -> # {{{ + until doc == window.document + # We are in a frame + frame = doc.defaultView.frameElement + rect = frame.getBoundingClientRect() + x += rect.left + y += rect.top + doc = frame.ownerDocument + win = doc.defaultView + [wx, wy] = window_scroll_pos(win) + x += wx + y += wy + return [x, y] +# }}} + +absleft = (elem) -> # {{{ r = elem.getBoundingClientRect() - return r.left + window.pageXOffset + return viewport_to_document(r.left, 0, elem.ownerDocument)[0] +# }}} class PagedDisplay ###