error_tmpl.js 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const error = function (title, text, links) {
  2. if (text == null) {
  3. text = "";
  4. }
  5. if (links == null) {
  6. links = "";
  7. }
  8. if (text) {
  9. text = `<p class="_error-text">${text}</p>`;
  10. }
  11. if (links) {
  12. links = `<p class="_error-links">${links}</p>`;
  13. }
  14. return `<div class="_error"><h1 class="_error-title">${title}</h1>${text}${links}</div>`;
  15. };
  16. const back = '<a href="#" data-behavior="back" class="_error-link">Go back</a>';
  17. app.templates.notFoundPage = () =>
  18. error(
  19. " Page not found. ",
  20. " It may be missing from the source documentation or this could be a bug. ",
  21. back,
  22. );
  23. app.templates.pageLoadError = () =>
  24. error(
  25. " The page failed to load. ",
  26. ` It may be missing from the server (try reloading the app) or you could be offline (try <a href="/offline">installing the documentation for offline usage</a> when online again).<br>
  27. If you're online and you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. `,
  28. ` ${back} &middot; <a href="/#${location.pathname}" target="_top" class="_error-link">Reload</a>
  29. &middot; <a href="#" class="_error-link" data-retry>Retry</a> `,
  30. );
  31. app.templates.bootError = () =>
  32. error(
  33. " The app failed to load. ",
  34. ` Check your Internet connection and try <a href="#" data-behavior="reload">reloading</a>.<br>
  35. If you keep seeing this, you're likely behind a proxy or firewall that blocks cross-domain requests. `,
  36. );
  37. app.templates.offlineError = function (reason, exception) {
  38. if (reason === "cookie_blocked") {
  39. return error(" Cookies must be enabled to use offline mode. ");
  40. }
  41. reason = (() => {
  42. switch (reason) {
  43. case "not_supported":
  44. return ` DevDocs requires IndexedDB to cache documentations for offline access.<br>
  45. Unfortunately your browser either doesn't support IndexedDB or doesn't make it available. `;
  46. case "buggy":
  47. return ` DevDocs requires IndexedDB to cache documentations for offline access.<br>
  48. Unfortunately your browser's implementation of IndexedDB contains bugs that prevent DevDocs from using it. `;
  49. case "private_mode":
  50. return ` Your browser appears to be running in private mode.<br>
  51. This prevents DevDocs from caching documentations for offline access.`;
  52. case "exception":
  53. return ` An error occurred when trying to open the IndexedDB database:<br>
  54. <code class="_label">${exception.name}: ${exception.message}</code> `;
  55. case "cant_open":
  56. return ` An error occurred when trying to open the IndexedDB database:<br>
  57. <code class="_label">${exception.name}: ${exception.message}</code><br>
  58. This could be because you're browsing in private mode or have disallowed offline storage on the domain. `;
  59. case "version":
  60. return ` The IndexedDB database was modified with a newer version of the app.<br>
  61. <a href="#" data-behavior="reload">Reload the page</a> to use offline mode. `;
  62. case "empty":
  63. return ' The IndexedDB database appears to be corrupted. Try <a href="#" data-behavior="reset">resetting the app</a>. ';
  64. }
  65. })();
  66. return error("Offline mode is unavailable.", reason);
  67. };
  68. app.templates.unsupportedBrowser = `\
  69. <div class="_fail">
  70. <h1 class="_fail-title">Your browser is unsupported, sorry.</h1>
  71. <p class="_fail-text">DevDocs is an API documentation browser which supports the following browsers:
  72. <ul class="_fail-list">
  73. <li>Recent versions of Firefox, Chrome, or Opera
  74. <li>Safari 11.1+
  75. <li>Edge 17+
  76. <li>iOS 11.3+
  77. </ul>
  78. <p class="_fail-text">
  79. If you're unable to upgrade, we apologize.
  80. We decided to prioritize speed and new features over support for older browsers.
  81. <p class="_fail-text">
  82. Note: if you're already using one of the browsers above, check your settings and add-ons.
  83. The app uses feature detection, not user agent sniffing.
  84. <p class="_fail-text">
  85. &mdash; <a href="https://twitter.com/DevDocs">@DevDocs</a>
  86. </div>\
  87. `;