offline_tmpl.js 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Sanity-check the conversion and remove this comment.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS102: Remove unnecessary code created because of implicit returns
  6. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
  7. */
  8. app.templates.offlinePage = (docs) => `\
  9. <h1 class="_lined-heading">Offline Documentation</h1>
  10. <div class="_docs-tools">
  11. <label>
  12. <input type="checkbox" name="autoUpdate" value="1" ${
  13. app.settings.get("manualUpdate") ? "" : "checked"
  14. }>Install updates automatically
  15. </label>
  16. <div class="_docs-links">
  17. <button type="button" class="_btn-link" data-action-all="install">Install all</button><button type="button" class="_btn-link" data-action-all="update"><strong>Update all</strong></button><button type="button" class="_btn-link" data-action-all="uninstall">Uninstall all</button>
  18. </div>
  19. </div>
  20. <div class="_table">
  21. <table class="_docs">
  22. <tr>
  23. <th>Documentation</th>
  24. <th class="_docs-size">Size</th>
  25. <th>Status</th>
  26. <th>Action</th>
  27. </tr>
  28. ${docs}
  29. </table>
  30. </div>
  31. <p class="_note"><strong>Note:</strong> your browser may delete DevDocs's offline data if your computer is running low on disk space and you haven't used the app in a while. Load this page before going offline to make sure the data is still there.
  32. <h2 class="_block-heading">Questions & Answers</h2>
  33. <dl>
  34. <dt>How does this work?
  35. <dd>Each page is cached as a key-value pair in <a href="https://devdocs.io/dom/indexeddb_api">IndexedDB</a> (downloaded from a single file).<br>
  36. The app also uses <a href="https://devdocs.io/dom/service_worker_api/using_service_workers">Service Workers</a> and <a href="https://devdocs.io/dom/web_storage_api">localStorage</a> to cache the assets and index files.
  37. <dt>Can I close the tab/browser?
  38. <dd>${canICloseTheTab()}
  39. <dt>What if I don't update a documentation?
  40. <dd>You'll see outdated content and some pages will be missing or broken, because the rest of the app (including data for the search and sidebar) uses a different caching mechanism that's updated automatically.
  41. <dt>I found a bug, where do I report it?
  42. <dd>In the <a href="https://github.com/freeCodeCamp/devdocs/issues">issue tracker</a>. Thanks!
  43. <dt>How do I uninstall/reset the app?
  44. <dd>Click <a href="#" data-behavior="reset">here</a>.
  45. <dt>Why aren't all documentations listed above?
  46. <dd>You have to <a href="/settings">enable</a> them first.
  47. </dl>\
  48. `;
  49. var canICloseTheTab = function () {
  50. if (app.ServiceWorker.isEnabled()) {
  51. return ' Yes! Even offline, you can open a new tab, go to <a href="//devdocs.io">devdocs.io</a>, and everything will work as if you were online (provided you installed all the documentations you want to use beforehand). ';
  52. } else {
  53. let reason = "aren't available in your browser (or are disabled)";
  54. if (app.config.env !== "production") {
  55. reason =
  56. "are disabled in your development instance of DevDocs (enable them by setting the <code>ENABLE_SERVICE_WORKER</code> environment variable to <code>true</code>)";
  57. }
  58. return ` No. Service Workers ${reason}, so loading <a href="//devdocs.io">devdocs.io</a> offline won't work.<br>
  59. The current tab will continue to function even when you go offline (provided you installed all the documentations beforehand). `;
  60. }
  61. };
  62. app.templates.offlineDoc = function (doc, status) {
  63. const outdated = doc.isOutdated(status);
  64. let html = `\
  65. <tr data-slug="${doc.slug}"${outdated ? ' class="_highlight"' : ""}>
  66. <td class="_docs-name _icon-${doc.icon}">${doc.fullName}</td>
  67. <td class="_docs-size">${
  68. Math.ceil(doc.db_size / 100000) / 10
  69. }&nbsp;<small>MB</small></td>\
  70. `;
  71. html += !(status && status.installed)
  72. ? `\
  73. <td>-</td>
  74. <td><button type="button" class="_btn-link" data-action="install">Install</button></td>\
  75. `
  76. : outdated
  77. ? `\
  78. <td><strong>Outdated</strong></td>
  79. <td><button type="button" class="_btn-link _bold" data-action="update">Update</button> - <button type="button" class="_btn-link" data-action="uninstall">Uninstall</button></td>\
  80. `
  81. : `\
  82. <td>Up&#8209;to&#8209;date</td>
  83. <td><button type="button" class="_btn-link" data-action="uninstall">Uninstall</button></td>\
  84. `;
  85. return html + "</tr>";
  86. };