index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* global $ */
  2. $(document).ready(function () {
  3. const $api = $('.api');
  4. const $start = $('.start');
  5. const $show = $('.left .show');
  6. const $hide = $('.left .hide');
  7. let width = $(window).width();
  8. const THRESHOLD = 700;
  9. init();
  10. $(window).on('resize', function () {
  11. width = $(window).width();
  12. init();
  13. });
  14. var hash = window.location.hash;
  15. if (hash === '#start' && width < THRESHOLD) {
  16. hideAPI();
  17. }
  18. function init () {
  19. if (width < THRESHOLD) {
  20. $api.addClass('fullscreen');
  21. $start.addClass('full');
  22. $show.hide();
  23. $hide.hide();
  24. } else {
  25. $start.removeClass('full');
  26. $api.removeClass('fullscreen');
  27. $show.show();
  28. $hide.show();
  29. }
  30. if ($api.attr('class').indexOf('hidden') === -1) {
  31. showAPI();
  32. } else {
  33. hideAPI();
  34. }
  35. }
  36. function hideAPI () {
  37. $api.addClass('hidden');
  38. if (width >= THRESHOLD) {
  39. $start.addClass('full');
  40. $hide.hide();
  41. $show.show();
  42. }
  43. }
  44. function showAPI () {
  45. if (width >= THRESHOLD) {
  46. $start.removeClass('full');
  47. $show.hide();
  48. $hide.show();
  49. }
  50. $api.removeClass('hidden');
  51. }
  52. $('body').on('click', '.left', function () {
  53. if ($api.attr('class').indexOf('hidden') !== -1) {
  54. showAPI();
  55. } else if ($api.attr('class').indexOf('fullscreen') === -1) {
  56. // Now the headers are only links.
  57. hideAPI();
  58. }
  59. });
  60. $('body').on('click', '.right', function () {
  61. hideAPI();
  62. });
  63. $('body').on('click', 'a', function () {
  64. if ($(this).attr('href').indexOf('#') === 0) {
  65. showAPI();
  66. }
  67. });
  68. });