6.17.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. $(document).ready(function() {
  2. $('#letter-a a').click(function(event) {
  3. event.preventDefault();
  4. $('#dictionary').hide().load('a.html', function() {
  5. $(this).fadeIn();
  6. });
  7. });
  8. $('#letter-b a').click(function(event) {
  9. event.preventDefault();
  10. $.getJSON('b.json', function(data) {
  11. var html = '';
  12. $.each(data, function(entryIndex, entry) {
  13. html += '<div class="entry">';
  14. html += '<h3 class="term">' + entry.term + '</h3>';
  15. html += '<div class="part">' + entry.part + '</div>';
  16. html += '<div class="definition">';
  17. html += entry.definition;
  18. if (entry.quote) {
  19. html += '<div class="quote">';
  20. $.each(entry.quote, function(lineIndex, line) {
  21. html += '<div class="quote-line">' + line + '</div>';
  22. });
  23. if (entry.author) {
  24. html += '<div class="quote-author">' + entry.author + '</div>';
  25. }
  26. html += '</div>';
  27. }
  28. html += '</div>';
  29. html += '</div>';
  30. });
  31. $('#dictionary').html(html);
  32. });
  33. });
  34. $('#letter-c a').click(function(event) {
  35. event.preventDefault();
  36. $.getScript('c.js');
  37. });
  38. $('#letter-d a').click(function(event) {
  39. event.preventDefault();
  40. $.get('d.xml', function(data) {
  41. $('#dictionary').empty();
  42. $(data).find('entry').each(function() {
  43. var $entry = $(this);
  44. var html = '<div class="entry">';
  45. html += '<h3 class="term">' + $entry.attr('term');
  46. html += '</h3>';
  47. html += '<div class="part">' + $entry.attr('part');
  48. html += '</div>';
  49. html += '<div class="definition">';
  50. html += $entry.find('definition').text();
  51. var $quote = $entry.find('quote');
  52. if ($quote.length) {
  53. html += '<div class="quote">';
  54. $quote.find('line').each(function() {
  55. html += '<div class="quote-line">';
  56. html += $(this).text() + '</div>';
  57. });
  58. if ($quote.attr('author')) {
  59. html += '<div class="quote-author">';
  60. html += $quote.attr('author') + '</div>';
  61. }
  62. html += '</div>';
  63. }
  64. html += '</div>';
  65. html += '</div>';
  66. $('#dictionary').append($(html));
  67. });
  68. });
  69. });
  70. $('#letter-e a').click(function(event) {
  71. event.preventDefault();
  72. var requestData = {term: $(this).text()};
  73. $.get('z.php', requestData, function(data) {
  74. $('#dictionary').html(data);
  75. }).fail(function(jqXHR) {
  76. $('#dictionary')
  77. .html('Sorry, but an error occurred: ' + jqXHR.status)
  78. .append(jqXHR.responseText);
  79. });
  80. });
  81. $('#letter-f form').submit(function(event) {
  82. event.preventDefault();
  83. var formValues = $(this).serialize();
  84. $.get('f.php', formValues, function(data) {
  85. $('#dictionary').html(data);
  86. });
  87. });
  88. var $loading = $('<div id="loading">Loading...</div>')
  89. .insertBefore('#dictionary');
  90. $(document).ajaxStart(function() {
  91. $loading.show();
  92. }).ajaxStop(function() {
  93. $loading.hide();
  94. });
  95. });