capacitor-welcome.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. window.customElements.define('capacitor-welcome', class extends HTMLElement {
  2. constructor() {
  3. super();
  4. Capacitor.Plugins.SplashScreen.hide();
  5. const root = this.attachShadow({ mode: 'open' });
  6. root.innerHTML = `
  7. <style>
  8. :host {
  9. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  10. display: block;
  11. width: 100%;
  12. height: 100%;
  13. }
  14. h1, h2, h3, h4, h5 {
  15. text-transform: uppercase;
  16. }
  17. .button {
  18. display: inline-block;
  19. padding: 10px;
  20. background-color: #73B5F6;
  21. color: #fff;
  22. font-size: 0.9em;
  23. border: 0;
  24. border-radius: 3px;
  25. text-decoration: none;
  26. cursor: pointer;
  27. }
  28. main {
  29. padding: 15px;
  30. }
  31. main hr { height: 1px; background-color: #eee; border: 0; }
  32. main h1 {
  33. font-size: 1.4em;
  34. text-transform: uppercase;
  35. letter-spacing: 1px;
  36. }
  37. main h2 {
  38. font-size: 1.1em;
  39. }
  40. main h3 {
  41. font-size: 0.9em;
  42. }
  43. main p {
  44. color: #333;
  45. }
  46. main pre {
  47. white-space: pre-line;
  48. }
  49. </style>
  50. <div>
  51. <capacitor-welcome-titlebar>
  52. <h1>Capacitor</h1>
  53. </capacitor-welcome-titlebar>
  54. <main>
  55. <p>
  56. Capacitor makes it easy to build powerful apps for the app stores, mobile web (Progressive Web Apps), and desktop, all
  57. with a single code base.
  58. </p>
  59. <h2>Getting Started</h2>
  60. <p>
  61. You'll probably need a UI framework to build a full-featured app. Might we recommend
  62. <a target="_blank" href="http://ionicframework.com/">Ionic</a>?
  63. </p>
  64. <p>
  65. Visit <a href="http://ionic-team.github.io/capacitor">ionic-team.github.io/capacitor</a> for information
  66. on using native features, building plugins, and more.
  67. </p>
  68. <a href="http://ionic-team.github.io/capacitor" target="_blank" class="button">Read more</a>
  69. <h2>Tiny Demo</h2>
  70. <p>
  71. This demo shows how to call Capacitor plugins. Say cheese!
  72. </p>
  73. <p>
  74. <button class="button" id="take-photo">Take Photo</button>
  75. </p>
  76. <p>
  77. <img id="image" style="max-width: 100%">
  78. </p>
  79. </main>
  80. </div>
  81. `
  82. }
  83. connectedCallback() {
  84. const self = this;
  85. self.shadowRoot.querySelector('#take-photo').addEventListener('click', async function(e) {
  86. const { Camera } = Capacitor.Plugins;
  87. try {
  88. const photo = await Camera.getPhoto({
  89. resultType: "uri"
  90. });
  91. const image = self.shadowRoot.querySelector('#image');
  92. if (!image) {
  93. return;
  94. }
  95. image.src = photo.webPath;
  96. } catch (e) {
  97. console.warn('User cancelled', e);
  98. }
  99. })
  100. }
  101. });
  102. window.customElements.define('capacitor-welcome-titlebar', class extends HTMLElement {
  103. constructor() {
  104. super();
  105. const root = this.attachShadow({ mode: 'open' });
  106. root.innerHTML = `
  107. <style>
  108. :host {
  109. position: relative;
  110. display: block;
  111. padding: 15px 15px 15px 15px;
  112. text-align: center;
  113. background-color: #73B5F6;
  114. }
  115. ::slotted(h1) {
  116. margin: 0;
  117. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  118. font-size: 0.9em;
  119. font-weight: 600;
  120. color: #fff;
  121. }
  122. </style>
  123. <slot></slot>
  124. `;
  125. }
  126. });