integrated last medor boilerplate from osp

This commit is contained in:
Bachir Soussi Chiadmi
2017-05-02 17:40:34 +02:00
parent 45e8f6a1b9
commit 235959b2ce
21 changed files with 1717 additions and 888 deletions
+157 -130
View File
@@ -1,150 +1,177 @@
$(function() {
/**
* This file is part of HTML2print.
*
* HTML2print is free software: you can redistribute it and/or modify it under the
* terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* HTML2print is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with HTML2print. If not, see <http://www.gnu.org/licenses/>.
*/
$('select[name="document"]').change(function(e){
console.log("document selection",this);
$('iframe').attr('src', this.value);
});
(function($, undefined) {
'use strict';
$.getJSON('build/toc.json', function(data){
console.log(data);
for (book in data) {
console.log(data[book]);
// var $optgroup = $('<optgroup>').attr('label', data[book].label);
// for (page of data[book].pages) {
// // console.log(page);
// $optgroup.append($('<option>').attr('value', data[book].label+'/'+page.file).text(data[book].label+' : '+page.label));
// }
$('[name="document"]').append(
$('<option>')
.attr('value', data[book].file).text(data[book].label)
);
}
var $viewport = $("#viewport")[0]
, $previewBtn = $('[name="preview"]')[0]
, $gridBtn = $('[name="grid"]')[0]
, $debugBtn = $('[name="debug"]')[0]
, $spreadBtn = $('[name="spread"]')[0]
, $zoomBtn = $('[name="zoom"]')[0]
, $pageBtn = $('[name="page"]')[0]
, $displayBtn = $('[name="display"]')[0]
, $reloadBtn = $('#reload')[0]
, $printBtn = $('#print')[0]
, $designmodeBtn = $('[name="designmode"]')[0]
;
console.log(window.location.hash);
$viewport.addEventListener("load", function(event) {
var $contentDoc = this.contentDocument;
var $doc = this.contentDocument.getElementsByTagName('html')[0]
var hash = parseInt(window.location.hash.replace('#',''));
console.log(hash);
var value = $('[name="document"] option:eq('+hash+')').attr('value');
console.log('value', value);
$('[name="document"]').val(value).change();
})
// activate toolbar events when iframe is loaded
$('iframe').load(function() {
initIframe();
});
function initIframe(){
var doc = $("iframe").contents().find("html");
console.log('initIframe :: doc', doc);
$('input[name="preview"]').change(function(e) {
console.log('Preview',e);
if($(this).is(":checked")) {
doc.addClass("preview");
doc.removeClass("normal");
} else {
doc.removeClass("preview");
doc.addClass("normal");
}
});
if(preview){
$('input[name="preview"]').prop('checked', true).change();
}
$('[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");
function switchPreview(event) {
if(this.checked) {
$doc.classList.add("preview");
$doc.classList.remove("normal");
} else {
$doc.classList.add("normal");
$doc.classList.remove("preview");
}
}
});
if(spread){
$('[name="spread"]').prop('checked', true).change();
}
//$('[name="hi-res"]').change(function() {
//if($(this).is(":checked")) {
//doc.addClass("export");
//} else {
//doc.removeClass("export");
//}
//});
function switchGrid(event) {
console.log(event);
if (this.checked) {
$doc.classList.add("grid");
} else {
$doc.classList.remove("grid");
}
}
$('[name="zoom"]').change(function() {
zoomLevel = $(this).val() / 100;
function switchDebug(event) {
if(this.checked) {
$doc.classList.add("debug");
} else {
$doc.classList.remove("debug");
}
}
doc.find("#pages").css({
"-webkit-transform": "scale(" + zoomLevel + ")",
"-webkit-transform-origin": "0 0"
});
});
function switchSpread(event) {
if(this.checked) {
$doc.classList.add("spread");
} else {
$doc.classList.remove("spread");
}
}
//$(".paper").each(function(){
//page = $(this).attr("id");
//$("#toc-pages").append("<li><a href='#" + page + "'>" + page.replace("-", " ") + "</a></li>")
//});
function switchDesignMode(event) {
if(this.checked) {
$contentDoc.designMode = "on";
} else {
$contentDoc.designMode = "off";
}
}
$('[name="page"]').change(function() {
var pageNumber = $(this).val() - 1;
function setZoom(event) {
var zoomLevel = this.value / 100;
var elt = $doc.querySelector("#pages");
var target = doc.find('.paper:eq(' + pageNumber + ')');
var offsetTop = target.offset().top;
elt.style.webkitTransform = "scale(" + zoomLevel + ")";
elt.style.webkitTransformOrigin = "0 0";
}
doc.find('body').scrollTop(offsetTop);
});
function changePage(event) {
var pageNumber = this.value - 1;
$("#print").on('click', function() {
$("iframe").get(0).contentWindow.print();
});
}
var target = $doc.querySelectorAll('.paper')[pageNumber];
var offsetTop = target.offsetTop;
//// __________________________________ 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");
//}
$doc.querySelector('body').scrollTop = offsetTop;
}
function changeDisplay(event) {
var htmlelt = $doc.querySelectorAll('html')[0];
var elts = $doc.querySelectorAll('img');
$doc.classList.remove("low");
$doc.classList.remove("bw");
$doc.classList.remove("color");
$doc.classList.add(this.value);
//for (var i = 0, l = elts.length; i < l; i ++) {
//var elt = elts[i];
//if (!elt.dataset.low) { elt.dataset.low = elt.src; }
//elt.style.visibility = 'visible';
//if (elt.dataset[this.value]) {
//elt.src = elt.dataset[this.value];
//} else {
//elt.src = "";
//elt.style.visibility = 'hidden'
//}
//});
//}, 2000);
//});
//}
//console.log("Wait for hi-res images to load");
//window.setTimeout(function(){
console.log("Check image resolution");
// Redlights images too small for printing
var images = $doc.getElementsByTagName("img");
for (var i=0; i < images.length; i++) {
if (Math.ceil(images[i].naturalHeight / images[i].height) < 1.8) {
console.log(images[i] + ": " + Math.floor(images[i].naturalHeight / images[i].height) );
images[i].className += "lo-res";
}
if (Math.ceil(images[i].naturalHeight / images[i].height) < 4.5) {
console.log(images[i] + ": " + Math.floor(images[i].naturalHeight / images[i].height) );
images[i].className += "too-big";
}
}
console.log("done checking resolution");
//}, 2000);
//
// TODO: change le titre ici
//console.log(document.title)
//console.log($contentDoc.title)
//
}
function reload(event) {
$viewport.contentWindow.location.reload();
}
function print(event) {
$viewport.contentWindow.print();
}
});
$previewBtn.addEventListener("change", switchPreview);
$gridBtn.addEventListener("change", switchGrid);
$debugBtn.addEventListener("change", switchDebug);
$spreadBtn.addEventListener("change", switchSpread);
$zoomBtn.addEventListener("change", setZoom);
$pageBtn.addEventListener("change", changePage);
$reloadBtn.addEventListener("click", reload);
$printBtn.addEventListener("click", print);
$displayBtn.addEventListener("change", changeDisplay);
$designmodeBtn.addEventListener("change", switchDesignMode);
//(function($) {
//'use strict';
//$('iframe')[0].addEventListener("load", function(event) {
//console.log(arguments);
//}, false);
//})(document.querySelectorAll.bind(document));
switchPreview.bind($previewBtn)();
switchGrid.bind($gridBtn)();
switchDebug.bind($debugBtn)();
switchSpread.bind($spreadBtn)();
setZoom.bind($zoomBtn)();
//changePage.bind($pageBtn)();
}, false);
})(document.querySelectorAll.bind(document));
-96
View File
@@ -1,16 +1,5 @@
// 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++){
@@ -18,89 +7,4 @@ $(function() {
}
$("#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");
});
});
-4
View File
@@ -1,5 +1 @@
nb_page = 100;
// ui options default values
// TODO: add default values for all gui options
preview = true;
spread = true;