re_integrated html2print boilerplate from osp

This commit is contained in:
Bachir Soussi Chiadmi
2017-04-22 16:56:29 +02:00
parent b68f53c0b0
commit 6366f20dcb
26 changed files with 1293 additions and 565 deletions
File diff suppressed because one or more lines are too long
+127
View File
@@ -0,0 +1,127 @@
$(function() {
$.getJSON('build/toc.json', function(data){
// console.log(data);
for (book of data) {
// console.log(book);
var $optgroup = $('<optgroup>').attr('label', book.label);
for (page of book.pages) {
// console.log(page);
$optgroup.append($('<option>').attr('value', book.label+'/'+page.file).text(book.label+' : '+page.label));
}
$('[name="document"]').append($optgroup);
}
})
$('select[name="document"]').change(function(e){
// console.log(e);
// var optionSelected = $("option:selected", this);
// var valueSelected = ;
console.log(this.value);
$('iframe').attr('src', 'build/'+this.value);
});
// activate toolbar events when iframe is loaded
$('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");
//} 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("<li><a href='#" + page + "'>" + page.replace("-", " ") + "</a></li>")
//});
$('[name="page"]').change(function() {
var pageNumber = $(this).val() - 1;
var target = doc.find('.paper:eq(' + pageNumber + ')');
var offsetTop = target.offset().top;
doc.find('body').scrollTop(offsetTop);
});
$("#print").on('click', function() {
$("iframe").get(0).contentWindow.print();
});
});
//// __________________________________ HIGH RESOLUTION __________________________________ //
//$("#hi-res").click(function(e){
//e.preventDefault();
//$(this).toggleClass("button-active");
//$("html").toggleClass("export");
//$("img").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").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);
//});
});
//(function($) {
//'use strict';
//$('iframe')[0].addEventListener("load", function(event) {
//console.log(arguments);
//}, false);
//})(document.querySelectorAll.bind(document));
+106
View File
@@ -0,0 +1,106 @@
// html2print needs CSS regions
// load a polyfill if the browser does not support it
if (window.chrome) {
console.log('running chrome, no support for css regions; loading the polyfill');
var script = document.createElement('script');
script.setAttribute('src', 'assets/lib/css-regions.min.js');
document.getElementsByTagName('head')[0].appendChild(script);
};
$(function() {
// ________________________________ INIT __________________________________ //
// Creating crop marks
$("#master-page").append("<div class='crops'><div class='crop-top-left'><span class='bleed'></span></div><div class='crop-top-right'><span class='bleed'></span></div><div class='crop-bottom-right'><span class='bleed'></span></div><div class='crop-bottom-left'><span class='bleed'></span></div></div>")
// Cloning the master page
for (i = 1; i < nb_page; i++){
$("#master-page").clone().attr("id","page-"+i).insertBefore($("#master-page"));
}
$("#master-page").attr("data-width", $(".paper:first-child").width()).hide();
// Loads main content into <article id="my-story">
// if (content) {
// $("#my-story").load(content);
// }
// ________________________________ PREVIEW __________________________________ //
$("#preview").click(function(e){
e.preventDefault();
$(this).toggleClass("button-active");
$("html").toggleClass("preview normal");
});
// __________________________________ DEBUG __________________________________ //
$("#debug").click(function(e){
e.preventDefault();
$(this).toggleClass("button-active");
$("html").toggleClass("debug");
});
// __________________________________ SPREAD __________________________________ //
$("#spread").click(function(e){
e.preventDefault();
$(this).toggleClass("button-active");
$("body").toggleClass("spread");
});
// __________________________________ HIGH RESOLUTION __________________________________ //
$("#hi-res").click(function(e){
e.preventDefault();
$(this).toggleClass("button-active");
$("html").toggleClass("export");
$("img").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").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);
});
// __________________________________ TOC __________________________________ //
$(".paper").each(function(){
page = $(this).attr("id");
$("#toc-pages").append("<li><a href='#" + page + "'>" + page.replace("-", " ") + "</a></li>")
});
$("#goto").click(function(e){
e.preventDefault();
$(this).toggleClass("button-active");
$("#toc-pages").toggle();
});
// __________________________________ ZOOM __________________________________ //
$("#zoom").click(function(e){
e.preventDefault();
$(this).toggleClass("button-active");
$("#zoom-list").toggle();
});
$("#zoom-list a").click(function(e){
e.preventDefault();
zoom = $(this).attr("title") / 100 ;
unzoom = 1 / zoom;
$("#pages").css("-webkit-transform", "scale(" + zoom + ")");
$("#pages").css("-webkit-transform-origin", "0 0");
});
});
-5
View File
File diff suppressed because one or more lines are too long
-23
View File
@@ -1,23 +0,0 @@
// ________________________________ SETUP __________________________________ //
var nb_page = 15;
var cropmarks = false;
var debug = false;
// ________________________________ INIT __________________________________ //
// Creating crop marks
if(cropmarks){
$("#master-page").append("<div class='crops'><div class='crop-top-left'><span class='bleed'></span></div><div class='crop-top-right'><span class='bleed'></span></div><div class='crop-bottom-right'><span class='bleed'></span></div><div class='crop-bottom-left'><span class='bleed'></span></div></div>")
}
// Cloning the master page
for (i = 1; i <= nb_page; i++){
console.log('page',i);
$("#master-page").clone().attr("id","page-"+i).insertBefore($("#master-page"));
}
$("#master-page").attr("data-width", $(".paper:first-child").width()).hide();
if (debug) {
$('body').addClass("debug");
}
+1 -4
View File
@@ -1,6 +1,3 @@
<script type="text/javascript">
nb_page = 5;
cropmarks = false;
</script>
cropmarks = true;