$(function() { $('iframe').load(function() { var doc = $("iframe").contents().find("html"); $('[name="preview"]').change(function() { if($(this).is(":checked")) { doc.addClass("preview"); doc.removeClass("normal"); } else { doc.removeClass("preview"); doc.addClass("normal"); } }); $('[name="debug"]').change(function() { if($(this).is(":checked")) { doc.addClass("debug"); } else { doc.removeClass("debug"); } }); $('[name="spread"]').change(function() { if($(this).is(":checked")) { doc.addClass("spread"); } else { doc.removeClass("spread"); } }); $('[name="hi-res"]').change(function() { if($(this).is(":checked")) { doc.addClass("export"); $("img", doc).each(function(){ var hires = $(this).attr("data-alt-src"); var lores = $(this).attr("src"); $(this).attr("data-alt-src", lores) $(this).attr("src", hires) }); console.log("Wait for hi-res images to load"); window.setTimeout(function(){ console.log("Check image resolution"); // Redlights images too small for printing $("img", doc).each(function(){ if (Math.ceil(this.naturalHeight / $(this).height()) < 3) { console.log($(this).attr("src") + ": " + Math.floor(this.naturalHeight / $(this).height()) ); if($(this).parent().hasClass("moveable")) { $(this).parent().toggleClass("lo-res"); } else { $(this).toggleClass("lo-res"); } } }); }, 2000); } else { doc.removeClass("export"); } }); $('[name="zoom"]').change(function() { zoomLevel = $(this).val() / 100; doc.find("#pages").css({ "-webkit-transform": "scale(" + zoomLevel + ")", "-webkit-transform-origin": "0 0" }); }); //$(".paper").each(function(){ //page = $(this).attr("id"); //$("#toc-pages").append("