offline_tmpl.js 4.2 KB

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