1EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, renderer){ 2 var images = renderer.contents.querySelectorAll('img'), 3 items = Array.prototype.slice.call(images), 4 iheight = renderer.height,//chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height, 5 oheight; 6 7 if(renderer.layoutSettings.layout != "reflowable") { 8 callback(); 9 return; //-- Only adjust images for reflowable text 10 } 11 12 items.forEach(function(item){ 13 14 var size = function() { 15 var itemRect = item.getBoundingClientRect(), 16 rectHeight = itemRect.height, 17 top = itemRect.top, 18 oHeight = item.getAttribute('data-height'), 19 height = oHeight || rectHeight, 20 newHeight, 21 fontSize = Number(getComputedStyle(item, "").fontSize.match(/(\d*(\.\d*)?)px/)[1]), 22 fontAdjust = fontSize ? fontSize / 2 : 0; 23 24 iheight = renderer.contents.clientHeight; 25 if(top < 0) top = 0; 26 27 if(height + top >= iheight) { 28 29 if(top < iheight/2) { 30 // Remove top and half font-size from height to keep container from overflowing 31 newHeight = iheight - top - fontAdjust; 32 item.style.maxHeight = newHeight + "px"; 33 item.style.width= "auto"; 34 }else{ 35 if(height > iheight) { 36 item.style.maxHeight = iheight + "px"; 37 item.style.width= "auto"; 38 itemRect = item.getBoundingClientRect(); 39 height = itemRect.height; 40 } 41 item.style.display = "block"; 42 item.style["WebkitColumnBreakBefore"] = "always"; 43 item.style["breakBefore"] = "column"; 44 45 } 46 47 item.setAttribute('data-height', newHeight); 48 49 }else{ 50 item.style.removeProperty('max-height'); 51 item.style.removeProperty('margin-top'); 52 } 53 } 54 55 var unloaded = function(){ 56 // item.removeEventListener('load', size); // crashes in IE 57 renderer.off("renderer:resized", size); 58 renderer.off("renderer:chapterUnload", this); 59 }; 60 61 item.addEventListener('load', size, false); 62 63 renderer.on("renderer:resized", size); 64 65 renderer.on("renderer:chapterUnload", unloaded); 66 67 size(); 68 69 }); 70 71 if(callback) callback(); 72 73}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.