gui.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. if(spread){
  59. $('[name="spread"]').prop('checked', true).change();
  60. }
  61. //$('[name="hi-res"]').change(function() {
  62. //if($(this).is(":checked")) {
  63. //doc.addClass("export");
  64. //} else {
  65. //doc.removeClass("export");
  66. //}
  67. //});
  68. $('[name="zoom"]').change(function() {
  69. zoomLevel = $(this).val() / 100;
  70. doc.find("#pages").css({
  71. "-webkit-transform": "scale(" + zoomLevel + ")",
  72. "-webkit-transform-origin": "0 0"
  73. });
  74. });
  75. //$(".paper").each(function(){
  76. //page = $(this).attr("id");
  77. //$("#toc-pages").append("<li><a href='#" + page + "'>" + page.replace("-", " ") + "</a></li>")
  78. //});
  79. $('[name="page"]').change(function() {
  80. var pageNumber = $(this).val() - 1;
  81. var target = doc.find('.paper:eq(' + pageNumber + ')');
  82. var offsetTop = target.offset().top;
  83. doc.find('body').scrollTop(offsetTop);
  84. });
  85. $("#print").on('click', function() {
  86. $("iframe").get(0).contentWindow.print();
  87. });
  88. }
  89. //// __________________________________ HIGH RESOLUTION __________________________________ //
  90. //$("#hi-res").click(function(e){
  91. //e.preventDefault();
  92. //$(this).toggleClass("button-active");
  93. //$("html").toggleClass("export");
  94. //$("img").each(function(){
  95. //var hires = $(this).attr("data-alt-src");
  96. //var lores = $(this).attr("src");
  97. //$(this).attr("data-alt-src", lores)
  98. //$(this).attr("src", hires)
  99. //});
  100. //console.log("Wait for hi-res images to load");
  101. //window.setTimeout(function(){
  102. //console.log("Check image resolution");
  103. //// Redlights images too small for printing
  104. //$("img").each(function(){
  105. //if (Math.ceil(this.naturalHeight / $(this).height()) < 3) {
  106. //console.log($(this).attr("src") + ": " + Math.floor(this.naturalHeight / $(this).height()) );
  107. //if($(this).parent().hasClass("moveable")) {
  108. //$(this).parent().toggleClass("lo-res");
  109. //} else {
  110. //$(this).toggleClass("lo-res");
  111. //}
  112. //}
  113. //});
  114. //}, 2000);
  115. //});
  116. });
  117. //(function($) {
  118. //'use strict';
  119. //$('iframe')[0].addEventListener("load", function(event) {
  120. //console.log(arguments);
  121. //}, false);
  122. //})(document.querySelectorAll.bind(document));