offline_tmpl.js 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. app.templates.offlinePage = (docs) => `\
  2. <h1 class="_lined-heading">Offline Documentation</h1>
  3. <div class="_docs-tools">
  4. <label>
  5. <input type="checkbox" name="autoUpdate" value="1" ${
  6. app.settings.get("manualUpdate") ? "" : "checked"
  7. }>Install updates automatically
  8. </label>
  9. <div class="_docs-links">
  10. <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>
  11. </div>
  12. </div>
  13. <div class="_table">
  14. <table class="_docs">
  15. <tr>
  16. <th>Documentation</th>
  17. <th class="_docs-size">Size</th>
  18. <th>Status</th>
  19. <th>Action</th>
  20. </tr>
  21. ${docs}
  22. </table>
  23. </div>
  24. <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.
  25. <h2 class="_block-heading">Questions & Answers</h2>
  26. <dl>
  27. <dt>How does this work?
  28. <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>
  29. 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.
  30. <dt>Can I close the tab/browser?
  31. <dd>${canICloseTheTab()}
  32. <dt>What if I don't update a documentation?
  33. <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.
  34. <dt>I found a bug, where do I report it?
  35. <dd>In the <a href="https://github.com/freeCodeCamp/devdocs/issues">issue tracker</a>. Thanks!
  36. <dt>How do I uninstall/reset the app?
  37. <dd>Click <a href="#" data-behavior="reset">here</a>.
  38. <dt>Why aren't all documentations listed above?
  39. <dd>You have to <a href="/settings">enable</a> them first.
  40. </dl>\
  41. `;
  42. var canICloseTheTab = function () {
  43. if (app.ServiceWorker.isEnabled()) {
  44. 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). ';
  45. } else {
  46. let reason = "aren't available in your browser (or are disabled)";
  47. if (app.config.env !== "production") {
  48. reason =
  49. "are disabled in your development instance of DevDocs (enable them by setting the <code>ENABLE_SERVICE_WORKER</code> environment variable to <code>true</code>)";
  50. }
  51. return ` No. Service Workers ${reason}, so loading <a href="//devdocs.io">devdocs.io</a> offline won't work.<br>
  52. The current tab will continue to function even when you go offline (provided you installed all the documentations beforehand). `;
  53. }
  54. };
  55. app.templates.offlineDoc = function (doc, status) {
  56. const outdated = doc.isOutdated(status);
  57. let html = `\
  58. <tr data-slug="${doc.slug}"${outdated ? ' class="_highlight"' : ""}>
  59. <td class="_docs-name _icon-${doc.icon}">${doc.fullName}</td>
  60. <td class="_docs-size">${
  61. Math.ceil(doc.db_size / 100000) / 10
  62. }&nbsp;<small>MB</small></td>\
  63. `;
  64. html += !(status && status.installed)
  65. ? `\
  66. <td>-</td>
  67. <td><button type="button" class="_btn-link" data-action="install">Install</button></td>\
  68. `
  69. : outdated
  70. ? `\
  71. <td><strong>Outdated</strong></td>
  72. <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>\
  73. `
  74. : `\
  75. <td>Up&#8209;to&#8209;date</td>
  76. <td><button type="button" class="_btn-link" data-action="uninstall">Uninstall</button></td>\
  77. `;
  78. return html + "</tr>";
  79. };