APIs

Show:
  1. /**
  2. * @namespace flexygo.ui.wc
  3. */
  4. var flexygo;
  5. (function (flexygo) {
  6. var ui;
  7. (function (ui) {
  8. var wc;
  9. (function (wc) {
  10. /**
  11. * Library for the FlxOfflineEmulator
  12. *
  13. * @class FlxOfflineEmulator
  14. * @constructor
  15. * @return {FlxOfflineEmulator} .
  16. */
  17. class FlxOfflineEmulator extends HTMLElement {
  18. constructor() {
  19. //If a constructor is defined, is REQUIRED call the super constructor
  20. super();
  21. /**
  22. * Set if element has been connected to DOM
  23. * @property connected {boolean}
  24. */
  25. this.connected = false;
  26. /**
  27. * Ionic Mode
  28. * @property ionicMode {string}
  29. */
  30. this.ionicMode = 'md';
  31. /**
  32. * Iframe Loaded
  33. * @property iframeLoaded {boolean}
  34. */
  35. this.iframeLoaded = false;
  36. }
  37. /**
  38. * Array of observed attributes. REQUIRED
  39. * @property observedAttributes {Array}
  40. */
  41. static get observedAttributes() {
  42. return ['ModuleName', 'url', 'mode'];
  43. }
  44. /**
  45. * Init the webcomponent. REQUIRED.
  46. * @method init
  47. */
  48. init() {
  49. this.render();
  50. }
  51. /**
  52. * Refresh de webcomponent. REQUIRED.
  53. * @method refresh
  54. */
  55. refresh() {
  56. this.ionicWindow.postMessage({ action: 'reload' }, '*');
  57. }
  58. /**
  59. * Refresh pages from linked app.
  60. * @method refresh
  61. */
  62. refreshpages() {
  63. this.ionicWindow.postMessage({ action: 'syncTemplates' }, '*');
  64. }
  65. /**
  66. * Render HTML data.
  67. * @method render
  68. */
  69. render() {
  70. if (this.url) {
  71. $(this).html([
  72. this.renderModeToggle(),
  73. this.renderDevice(),
  74. this.renderHelpOptions(),
  75. ].join(''));
  76. this.setMainEvents();
  77. }
  78. else {
  79. flexygo.msg.warning("The emulator needs the url attribute");
  80. }
  81. }
  82. /**
  83. * Render Mode Toggle.
  84. * @method render
  85. */
  86. renderModeToggle() {
  87. return (`<div class="mode-toggle" active-mode="${this.ionicMode}">
  88. <div class="toggle-group">
  89. ${[{ mode: 'ios', icon: 'fa fa-apple' }, { mode: 'md', icon: 'fa fa-android' }].map(platform => (`<button
  90. ${(platform.mode === this.ionicMode) ? 'class= "rippled"' : ''}
  91. data-toggle="tooltip"
  92. title="${flexygo.localization.translate('offlineemulator.' + platform.mode)}"
  93. mode="${platform.mode}">
  94. <i class="${platform.icon}"/>
  95. </button>`)).join('')}
  96. </div>
  97. </div>`);
  98. }
  99. /**
  100. * Render Device.
  101. * @method render
  102. */
  103. renderDevice() {
  104. return (`<div class="device" mode="${this.ionicMode}">
  105. <figure>
  106. <svg class="device__md-bar" viewBox="0 0 1384.3 40.3">
  107. <path class="st0" d="M1343 5l18.8 32.3c.8 1.3 2.7 1.3 3.5 0L1384 5c.8-1.3-.2-3-1.7-3h-37.6c-1.5 0-2.5 1.7-1.7 3z"/>
  108. <circle class="st0" cx="1299" cy="20.2" r="20"/>
  109. <path class="st0" d="M1213 1.2h30c2.2 0 4 1.8 4 4v30c0 2.2-1.8 4-4 4h-30c-2.2 0-4-1.8-4-4v-30c0-2.3 1.8-4 4-4zM16 4.2h64c8.8 0 16 7.2 16 16s-7.2 16-16 16H16c-8.8 0-16-7.2-16-16s7.2-16 16-16z"/>
  110. </svg>
  111. <svg class="device__ios-notch" viewBox="0 0 219 31">
  112. <path d="M0 1V0h219v1a5 5 0 0 0-5 5v3c0 12.15-9.85 22-22 22H27C14.85 31 5 21.15 5 9V6a5 5 0 0 0-5-5z" fill-rule="evenodd"/>
  113. </svg>
  114. <iframe
  115. loading="lazy"
  116. importance="low"
  117. src="${this.buildUrl()}"/>
  118. </figure>
  119. </div>`);
  120. }
  121. /**
  122. * Render Device.
  123. * @method render
  124. */
  125. renderHelpOptions() {
  126. return (`<div class="help-options">
  127. <i data-action="refreshpages" class="flx-icon icon-refresh" data-toggle="tooltip" data-placement="bottom" title="Refresh"/>
  128. <i data-action="externalemulator" class="flx-icon icon-new-link" data-toggle="tooltip" data-placement="bottom" title="External emulator"/>
  129. </div>`);
  130. }
  131. /**
  132. * Set Main Events.
  133. * @method setMainEvents
  134. */
  135. setMainEvents() {
  136. $(this).find('.device>figure>iframe').off('load.offline-emulator').on('load.offline-emulator', (e) => {
  137. this.iframeLoaded = true;
  138. this.ionicWindow = e.currentTarget.contentWindow;
  139. });
  140. $(this).find('.mode-toggle>.toggle-group>button').off('click.offline-emulator').on('click.offline-emulator', (e) => {
  141. if (this.ionicMode !== e.currentTarget.getAttribute("mode")) {
  142. this.setAttribute('mode', e.currentTarget.getAttribute("mode"));
  143. setTimeout(() => {
  144. $(this).find('.mode-toggle>.toggle-group>button').removeClass('rippled').filter(`[mode="${e.currentTarget.getAttribute("mode")}"]`).addClass('rippled');
  145. }, 500);
  146. }
  147. }).hover((e) => {
  148. if (e.currentTarget.getAttribute("mode") !== this.ionicMode) {
  149. $(this).find('.mode-toggle>.toggle-group').addClass('chage-mode');
  150. }
  151. }, (e) => {
  152. $(this).find('.mode-toggle>.toggle-group').removeClass('chage-mode');
  153. });
  154. $(this).find('.help-options>[data-action]').off('click.offline-emulator').on('click.offline-emulator', (e) => {
  155. switch ($(e.currentTarget).attr('data-action')) {
  156. case 'refreshpages':
  157. this.refreshpages();
  158. break;
  159. case 'externalemulator':
  160. window.open(this.buildUrl());
  161. break;
  162. }
  163. });
  164. $(this).find('[data-toggle="tooltip"]').tooltip({ container: 'body', trigger: 'hover', delay: { show: 600, hide: 0 } });
  165. }
  166. /**
  167. * Change Url.
  168. * @method changeUrl
  169. */
  170. changeUrl() {
  171. $(this).find('.device>figure>iframe').attr('src', this.buildUrl());
  172. }
  173. /**
  174. * Change Mode.
  175. * @method changeMode
  176. */
  177. changeMode() {
  178. $(this).find('.mode-toggle').attr("active-mode", this.ionicMode);
  179. $(this).find('.device').attr("mode", this.ionicMode);
  180. $(this).find('.device>figure>iframe').attr('src', this.buildUrl());
  181. $(this).find('.mode-toggle>.toggle-group').removeClass('chage-mode');
  182. }
  183. /**
  184. * Build Url.
  185. * @method buildUrl
  186. */
  187. buildUrl() {
  188. return `${this.url}?ionic:mode=${this.ionicMode}`;
  189. }
  190. /**
  191. * Fires when element is attached to DOM
  192. * @method connectedCallback
  193. */
  194. connectedCallback() {
  195. let element = $(this);
  196. this.connected = true;
  197. this.moduleName = element.attr("modulename");
  198. this.url = element.attr("url");
  199. element.attr("mode", this.ionicMode);
  200. this.init();
  201. }
  202. /**
  203. * Fires when the attribute value of the element is changed.
  204. * @method attributeChangedCallback
  205. */
  206. attributeChangedCallback(attrName, oldVal, newVal) {
  207. let needInit = false;
  208. if (attrName.toLowerCase() == 'modulename' && newVal && newVal != '') {
  209. this.moduleName = newVal;
  210. needInit = true;
  211. }
  212. else if (attrName.toLowerCase() == 'url' && newVal && newVal != '') {
  213. this.url = newVal;
  214. if (this.connected) {
  215. this.changeUrl();
  216. }
  217. }
  218. else if (attrName.toLowerCase() == 'mode' && newVal && newVal != '') {
  219. this.ionicMode = newVal;
  220. if (this.connected) {
  221. this.changeMode();
  222. }
  223. }
  224. if (this.connected && needInit) {
  225. this.init();
  226. }
  227. }
  228. }
  229. wc.FlxOfflineEmulator = FlxOfflineEmulator;
  230. })(wc = ui.wc || (ui.wc = {}));
  231. })(ui = flexygo.ui || (flexygo.ui = {}));
  232. })(flexygo || (flexygo = {}));
  233. window.customElements.define("flx-offline-emulator", flexygo.ui.wc.FlxOfflineEmulator);
  234. //# sourceMappingURL=flx-offline-emulator.js.map