gui.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. $(function() {
  2. $('select[name="document"]').change(function(e){
  3. console.log("document selection",this);
  4. $('iframe').attr('src', this.value);
  5. });
  6. $.getJSON('build/toc.json', function(data){
  7. console.log(data);
  8. for (book in data) {
  9. console.log(data[book]);
  10. // var $optgroup = $('<optgroup>').attr('label', data[book].label);
  11. // for (page of data[book].pages) {
  12. // // console.log(page);
  13. // $optgroup.append($('<option>').attr('value', data[book].label+'/'+page.file).text(data[book].label+' : '+page.label));
  14. // }
  15. $('[name="document"]').append(
  16. $('<option>')
  17. .attr('value', data[book].file).text(data[book].label)
  18. );
  19. }
  20. console.log(window.location.hash);
  21. var hash = parseInt(window.location.hash.replace('#',''));
  22. console.log(hash);
  23. var value = $('[name="document"] option:eq('+hash+')').attr('value');
  24. console.log('value', value);
  25. $('[name="document"]').val(value).change();
  26. })
  27. // activate toolbar events when iframe is loaded
  28. $('iframe').load(function() {
  29. initIframe();
  30. });
  31. function initIframe(){
  32. var doc = $("iframe").contents().find("html");
  33. console.log('initIframe :: doc', doc);
  34. $('input[name="preview"]').change(function(e) {
  35. console.log('Preview',e);
  36. if($(this).is(":checked")) {
  37. doc.addClass("preview");
  38. doc.removeClass("normal");
  39. } else {
  40. doc.removeClass("preview");
  41. doc.addClass("normal");
  42. }
  43. });
  44. $('[name="debug"]').change(function() {
  45. if($(this).is(":checked")) {
  46. doc.addClass("debug");
  47. } else {
  48. doc.removeClass("debug");
  49. }
  50. });
  51. $('[name="spread"]').change(function() {
  52. if($(this).is(":checked")) {
  53. doc.addClass("spread");
  54. } else {
  55. doc.removeClass("spread");
  56. }
  57. });
  58. //$('[name="hi-res"]').change(function() {
  59. //if($(this).is(":checked")) {
  60. //doc.addClass("export");
  61. //} else {
  62. //doc.removeClass("export");
  63. //}
  64. //});
  65. $('[name="zoom"]').change(function() {
  66. zoomLevel = $(this).val() / 100;
  67. doc.find("#pages").css({
  68. "-webkit-transform": "scale(" + zoomLevel + ")",
  69. "-webkit-transform-origin": "0 0"
  70. });
  71. });
  72. //$(".paper").each(function(){
  73. //page = $(this).attr("id");
  74. //$("#toc-pages").append("<li><a href='#" + page + "'>" + page.replace("-", " ") + "</a></li>")
  75. //});
  76. $('[name="page"]').change(function() {
  77. var pageNumber = $(this).val() - 1;
  78. var target = doc.find('.paper:eq(' + pageNumber + ')');
  79. var offsetTop = target.offset().top;
  80. doc.find('body').scrollTop(offsetTop);
  81. });
  82. $("#print").on('click', function() {
  83. $("iframe").get(0).contentWindow.print();
  84. });
  85. }
  86. //// __________________________________ HIGH RESOLUTION __________________________________ //
  87. //$("#hi-res").click(function(e){
  88. //e.preventDefault();
  89. //$(this).toggleClass("button-active");
  90. //$("html").toggleClass("export");
  91. //$("img").each(function(){
  92. //var hires = $(this).attr("data-alt-src");
  93. //var lores = $(this).attr("src");
  94. //$(this).attr("data-alt-src", lores)
  95. //$(this).attr("src", hires)
  96. //});
  97. //console.log("Wait for hi-res images to load");
  98. //window.setTimeout(function(){
  99. //console.log("Check image resolution");
  100. //// Redlights images too small for printing
  101. //$("img").each(function(){
  102. //if (Math.ceil(this.naturalHeight / $(this).height()) < 3) {
  103. //console.log($(this).attr("src") + ": " + Math.floor(this.naturalHeight / $(this).height()) );
  104. //if($(this).parent().hasClass("moveable")) {
  105. //$(this).parent().toggleClass("lo-res");
  106. //} else {
  107. //$(this).toggleClass("lo-res");
  108. //}
  109. //}
  110. //});
  111. //}, 2000);
  112. //});
  113. });
  114. //(function($) {
  115. //'use strict';
  116. //$('iframe')[0].addEventListener("load", function(event) {
  117. //console.log(arguments);
  118. //}, false);
  119. //})(document.querySelectorAll.bind(document));