6.15.js 2.8 KB

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