gui.js 4.4 KB

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