gui.js 4.0 KB

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