fancy_format_gdpr.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * FANCY FORMAT GDPR TEXT
  3. * @author Harshvardhan Pandit
  4. * @author me a.t. harshp dot com
  5. * LICENSE: MIT
  6. *
  7. * Using the data from gdpr.json, this script restructures the HTML to create
  8. * a hierarchical page that can be referenced by HTML id attributes
  9. */
  10. // clear the body
  11. $('body').empty();
  12. // insert title and other items
  13. $('body').append(
  14. $('<h1>', {
  15. 'id': 'title',
  16. 'class': 'title',
  17. 'text': data.title + ' (' + data.abbrv + ')'
  18. }));
  19. $('body').append(
  20. $('<p>', {
  21. 'id': 'about',
  22. 'class': 'description',
  23. 'text': data.about
  24. }));
  25. // recitals
  26. var element_recital = $('<div>', { 'id': 'recitals' });
  27. element_recital.append(
  28. $('<h2>', {
  29. 'class': 'recital-title',
  30. 'text': 'Recitals'
  31. }));
  32. data.recitals.map(function(recital) {
  33. element_recital.append(
  34. $('<p>', {
  35. 'id': 'recital-' + recital.number,
  36. 'class': 'recital',
  37. 'text': '(' + recital.number + ') ' + recital.text
  38. }));
  39. });
  40. $('body').append(element_recital);
  41. // chapters
  42. data.chapters.map(function(chapter) {
  43. var element_chapter = $('<div>', {
  44. 'id': 'chapter' + chapter.number,
  45. 'class': 'chapter'
  46. });
  47. element_chapter.append(
  48. $('<h2>', {
  49. 'class': 'chapter-title',
  50. 'text': "Chapter " + chapter.number + " " + chapter.title
  51. }));
  52. // process entries in chapter
  53. // store the article handler so that it can be called on sections and
  54. // articles and reduces the things written in if-else blocks
  55. /**
  56. * handles article and creates elements
  57. * returns article div containing points and sub-points
  58. */
  59. var handler_article = function(article) {
  60. var element_article = $('<div>', {
  61. 'id': 'article' + article.number,
  62. 'class': 'article'
  63. });
  64. element_article.append(
  65. $('<h3>', {
  66. 'class': 'article-title',
  67. 'text': 'Article ' + article.number + " " + article.title
  68. }));
  69. // handle points
  70. article.contents.map(function(point) {
  71. if (point.number != null) {
  72. var element_point = $('<p>', {
  73. 'id': 'article' + article.number + '-' + point.number,
  74. 'class': 'point',
  75. 'text': '(' + point.number + ') ' + point.text
  76. });
  77. } else {
  78. var element_point = $('<p>', {
  79. 'class': 'point',
  80. 'text': point.text
  81. });
  82. }
  83. point.subpoints.map(function(subpoint) {
  84. if (subpoint.number != null) {
  85. element_point.append(
  86. $('<p>', {
  87. 'id': 'article' + article.number + '-' + point.number
  88. + '-' + subpoint.number,
  89. 'class': 'subpoint',
  90. 'text': '(' + subpoint.number + ') ' + subpoint.text
  91. }));
  92. } else {
  93. element_point.append(
  94. $('<p>', {
  95. 'class': 'subpoint',
  96. 'text': '- ' + subpoint.text
  97. }));
  98. }
  99. });
  100. element_article.append(element_point);
  101. });
  102. return element_article;
  103. };
  104. // process sections if chapter has sections
  105. if (chapter.contents[0].type == 'section') {
  106. chapter.contents.map(function(section) {
  107. var element_section = $('<div>', {
  108. 'id': 'section' + section.number,
  109. 'class': 'section'
  110. });
  111. element_section.append(
  112. $('<h3>', {
  113. 'class': 'section-title',
  114. 'text': 'Section ' + section.number + " " + section.title
  115. }));
  116. section.contents.map(function(article) {
  117. element_section.append(handler_article(article));
  118. });
  119. element_chapter.append(element_section);
  120. });
  121. } else {
  122. chapter.contents.map(function(article) {
  123. element_chapter.append(handler_article(article));
  124. });
  125. }
  126. // append chapter to body
  127. $('body').append(element_chapter);
  128. });
  129. // Citations / References
  130. var element_citation = $('<div>', { 'id': 'citations' });
  131. element_citation.append(
  132. $('<h2>', {
  133. 'class': 'citation-title',
  134. 'text': 'References'
  135. }));
  136. data.citations.map(function(index, citation) {
  137. element_citation.append(
  138. $('<p>', {
  139. 'id': 'citation-' + citation.number,
  140. 'class': 'citation',
  141. 'text': '(' + citation.number + ') ' + citation.text
  142. }));
  143. });
  144. $('body').append(element_citation);