faq.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. define([
  2. 'jquery',
  3. '/common/hyperscript.js',
  4. '/customize/messages.js',
  5. '/customize/pages.js'
  6. ], function ($, h, Msg, Pages) {
  7. return function () {
  8. var categories = [];
  9. var faq = Msg.faq;
  10. Object.keys(faq).forEach(function (c) {
  11. var questions = [];
  12. Object.keys(faq[c]).forEach(function (q) {
  13. var item = faq[c][q];
  14. if (typeof item !== "object") { return; }
  15. var answer = h('p.cp-faq-questions-a');
  16. var hash = c + '-' + q;
  17. var question = h('p.cp-faq-questions-q#' + hash);
  18. $(question).click(function () {
  19. if ($(answer).is(':visible')) {
  20. $(question).toggleClass('cp-active-faq');
  21. return void $(answer).slideUp();
  22. }
  23. $(question).toggleClass('cp-active-faq');
  24. $(answer).slideDown();
  25. var t = $(window).scrollTop();
  26. window.location.hash = hash;
  27. $(window).scrollTop(t);
  28. });
  29. questions.push(h('div.cp-faq-questions-items', [
  30. Pages.setHTML(question, item.q),
  31. Pages.setHTML(answer, item.a)
  32. ]));
  33. });
  34. categories.push(h('div.cp-faq-category', [
  35. h('h3', faq[c].title),
  36. h('div.cp-faq-category-questions', questions)
  37. ]));
  38. });
  39. var hash = window.location.hash;
  40. if (hash) {
  41. $(categories).find(hash).click();
  42. }
  43. return h('div#cp-main', [
  44. Pages.infopageTopbar(),
  45. h('div.container-fluid.cp-faq', [
  46. h('div.container',[
  47. h('center', h('h1', Msg.faq_title)),
  48. ]),
  49. ]),
  50. h('div.container.cp-faq-ques-det',[
  51. h('div.cp-faq-header.text-center', h('a.nav-item.nav-link', {
  52. href: '/what-is-cryptpad.html'
  53. }, Pages.setHTML(h('h4'),Msg.faq_whatis))),
  54. h('div.cp-faq-container', categories)
  55. ]),
  56. Pages.infopageFooter()
  57. ]);
  58. };
  59. });