diff options
author | Andrew Dolgov <[email protected]> | 2018-06-29 17:57:16 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-06-29 17:57:16 +0300 |
commit | e77a7e8869761661937d1cde3b004e406d45bfd3 (patch) | |
tree | 8c25daa5e94fdc2c731f236e4c4fa373dc0d554c /lib/smartimages.js | |
parent | 0018be7edc28b11a8da14e94613c5591da98d93a (diff) | |
parent | d4a1bb6a2f2d7a9e0e0dad419b032d6de915291a (diff) |
Merge branch 'epubjs-0.3'
Diffstat (limited to 'lib/smartimages.js')
-rw-r--r-- | lib/smartimages.js | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/lib/smartimages.js b/lib/smartimages.js deleted file mode 100644 index 8c1ec5f..0000000 --- a/lib/smartimages.js +++ /dev/null @@ -1,73 +0,0 @@ -EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, renderer){ - var images = renderer.contents.querySelectorAll('img'), - items = Array.prototype.slice.call(images), - iheight = renderer.height,//chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height, - oheight; - - if(renderer.layoutSettings.layout != "reflowable") { - callback(); - return; //-- Only adjust images for reflowable text - } - - items.forEach(function(item){ - - var size = function() { - var itemRect = item.getBoundingClientRect(), - rectHeight = itemRect.height, - top = itemRect.top, - oHeight = item.getAttribute('data-height'), - height = oHeight || rectHeight, - newHeight, - fontSize = Number(getComputedStyle(item, "").fontSize.match(/(\d*(\.\d*)?)px/)[1]), - fontAdjust = fontSize ? fontSize / 2 : 0; - - iheight = renderer.contents.clientHeight; - if(top < 0) top = 0; - - if(height + top >= iheight) { - - if(top < iheight/2) { - // Remove top and half font-size from height to keep container from overflowing - newHeight = iheight - top - fontAdjust; - item.style.maxHeight = newHeight + "px"; - item.style.width= "auto"; - }else{ - if(height > iheight) { - item.style.maxHeight = iheight + "px"; - item.style.width= "auto"; - itemRect = item.getBoundingClientRect(); - height = itemRect.height; - } - item.style.display = "block"; - item.style["WebkitColumnBreakBefore"] = "always"; - item.style["breakBefore"] = "column"; - - } - - item.setAttribute('data-height', newHeight); - - }else{ - item.style.removeProperty('max-height'); - item.style.removeProperty('margin-top'); - } - } - - var unloaded = function(){ - // item.removeEventListener('load', size); // crashes in IE - renderer.off("renderer:resized", size); - renderer.off("renderer:chapterUnload", this); - }; - - item.addEventListener('load', size, false); - - renderer.on("renderer:resized", size); - - renderer.on("renderer:chapterUnload", unloaded); - - size(); - - }); - - if(callback) callback(); - -} |