1 | /*
|
2 | Copyright 2013-2015 ASIAL CORPORATION
|
3 |
|
4 | Licensed under the Apache License, Version 2.0 (the "License");
|
5 | you may not use this file except in compliance with the License.
|
6 | You may obtain a copy of the License at
|
7 |
|
8 | http://www.apache.org/licenses/LICENSE-2.0
|
9 |
|
10 | Unless required by applicable law or agreed to in writing, software
|
11 | distributed under the License is distributed on an "AS IS" BASIS,
|
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | See the License for the specific language governing permissions and
|
14 | limitations under the License.
|
15 |
|
16 | */
|
17 |
|
18 | import util from './util.js';
|
19 | import elements from './elements.js';
|
20 | import animit from './animit.js';
|
21 | import GestureDetector from './gesture-detector.js';
|
22 | import platform from './platform.js';
|
23 | import notification from './notification.js';
|
24 | import actionSheet from './action-sheet.js';
|
25 | import internal from './internal/index.js';
|
26 | import orientation from './orientation.js';
|
27 | import modifier from './modifier.js';
|
28 | import softwareKeyboard from './software-keyboard.js';
|
29 | import pageAttributeExpression from './page-attribute-expression.js';
|
30 | import autoStyle from './autostyle.js';
|
31 | import DoorLock from './doorlock.js';
|
32 | import { defaultPageLoader, PageLoader } from './page-loader.js';
|
33 |
|
34 | /**
|
35 | * @object ons
|
36 | * @category util
|
37 | * @description
|
38 | * [ja]Onsen UIで利用できるグローバルなオブジェクトです。[/ja]
|
39 | * [en]A global object that's used in Onsen UI. [/en]
|
40 | */
|
41 | const ons = {
|
42 | animit,
|
43 | defaultPageLoader,
|
44 | elements,
|
45 | GestureDetector,
|
46 | modifier,
|
47 | notification,
|
48 | orientation,
|
49 | pageAttributeExpression,
|
50 | PageLoader,
|
51 | platform,
|
52 | softwareKeyboard,
|
53 | _autoStyle: autoStyle,
|
54 | _internal: internal,
|
55 | _readyLock: new DoorLock(),
|
56 | _util: util,
|
57 | };
|
58 |
|
59 | ons.platform.select((window.location.search.match(/platform=([\w-]+)/) || [])[1]);
|
60 |
|
61 | waitDeviceReady();
|
62 |
|
63 | const readyError = after => util.throw(`This method must be called ${after ? 'after' : 'before'} ons.isReady() is true`);
|
64 |
|
65 | /**
|
66 | * @method isReady
|
67 | * @signature isReady()
|
68 | * @return {Boolean}
|
69 | * [en]Will be true if Onsen UI is initialized.[/en]
|
70 | * [ja]初期化されているかどうかを返します。[/ja]
|
71 | * @description
|
72 | * [en]Returns true if Onsen UI is initialized.[/en]
|
73 | * [ja]Onsen UIがすでに初期化されているかどうかを返すメソッドです。[/ja]
|
74 | */
|
75 | ons.isReady = () => {
|
76 | return !ons._readyLock.isLocked();
|
77 | };
|
78 |
|
79 | /**
|
80 | * @method isWebView
|
81 | * @signature isWebView()
|
82 | * @return {Boolean}
|
83 | * [en]Will be true if the app is running in Cordova.[/en]
|
84 | * [ja]Cordovaで実行されている場合にtrueになります。[/ja]
|
85 | * @description
|
86 | * [en]Returns true if running inside Cordova.[/en]
|
87 | * [ja]Cordovaで実行されているかどうかを返すメソッドです。[/ja]
|
88 | */
|
89 | ons.isWebView = ons.platform.isWebView;
|
90 |
|
91 | /**
|
92 | * @method ready
|
93 | * @signature ready(callback)
|
94 | * @description
|
95 | * [ja]アプリの初期化に利用するメソッドです。渡された関数は、Onsen UIの初期化が終了している時点で必ず呼ばれます。[/ja]
|
96 | * [en]Method used to wait for app initialization. Waits for `DOMContentLoaded` and `deviceready`, when necessary, before executing the callback.[/en]
|
97 | * @param {Function} callback
|
98 | * [en]Function that executes after Onsen UI has been initialized.[/en]
|
99 | * [ja]Onsen UIが初期化が完了した後に呼び出される関数オブジェクトを指定します。[/ja]
|
100 | */
|
101 | ons.ready = callback => {
|
102 | if (ons.isReady()) {
|
103 | callback();
|
104 | } else {
|
105 | ons._readyLock.waitUnlock(callback);
|
106 | }
|
107 | };
|
108 |
|
109 | /**
|
110 | * @method setDefaultDeviceBackButtonListener
|
111 | * @signature setDefaultDeviceBackButtonListener(listener)
|
112 | * @param {Function} listener
|
113 | * [en]Function that executes when device back button is pressed. Must be called on `ons.ready`.[/en]
|
114 | * [ja]デバイスのバックボタンが押された時に実行される関数オブジェクトを指定します。[/ja]
|
115 | * @description
|
116 | * [en]Set default handler for device back button.[/en]
|
117 | * [ja]デバイスのバックボタンのためのデフォルトのハンドラを設定します。[/ja]
|
118 | */
|
119 | ons.setDefaultDeviceBackButtonListener = function(listener) {
|
120 | if (!ons.isReady()) {
|
121 | readyError(true);
|
122 | }
|
123 | ons._defaultDeviceBackButtonHandler.setListener(listener);
|
124 | };
|
125 |
|
126 | /**
|
127 | * @method disableDeviceBackButtonHandler
|
128 | * @signature disableDeviceBackButtonHandler()
|
129 | * @description
|
130 | * [en]Disable device back button event handler. Must be called on `ons.ready`.[/en]
|
131 | * [ja]デバイスのバックボタンのイベントを受け付けないようにします。[/ja]
|
132 | */
|
133 | ons.disableDeviceBackButtonHandler = function() {
|
134 | if (!ons.isReady()) {
|
135 | readyError(true);
|
136 | }
|
137 | internal.dbbDispatcher.disable();
|
138 | };
|
139 |
|
140 | /**
|
141 | * @method enableDeviceBackButtonHandler
|
142 | * @signature enableDeviceBackButtonHandler()
|
143 | * @description
|
144 | * [en]Enable device back button event handler. Must be called on `ons.ready`.[/en]
|
145 | * [ja]デバイスのバックボタンのイベントを受け付けるようにします。[/ja]
|
146 | */
|
147 | ons.enableDeviceBackButtonHandler = function() {
|
148 | if (!ons.isReady()) {
|
149 | readyError(true);
|
150 | }
|
151 | internal.dbbDispatcher.enable();
|
152 | };
|
153 |
|
154 | ons.fireDeviceBackButtonEvent = function() {
|
155 | internal.dbbDispatcher.fireDeviceBackButtonEvent();
|
156 | };
|
157 |
|
158 | /**
|
159 | * @method enableAutoStatusBarFill
|
160 | * @signature enableAutoStatusBarFill()
|
161 | * @description
|
162 | * [en]Enable status bar fill feature on iOS7 and above (except for iPhone X). Must be called before `ons.ready`.[/en]
|
163 | * [ja]iOS7以上(iPhone Xは除く)で、ステータスバー部分の高さを自動的に埋める処理を有効にします。[/ja]
|
164 | */
|
165 | ons.enableAutoStatusBarFill = () => {
|
166 | if (ons.isReady()) {
|
167 | readyError(false);
|
168 | }
|
169 | internal.config.autoStatusBarFill = true;
|
170 | };
|
171 |
|
172 | /**
|
173 | * @method disableAutoStatusBarFill
|
174 | * @signature disableAutoStatusBarFill()
|
175 | * @description
|
176 | * [en]Disable status bar fill feature on iOS7 and above (except for iPhone X). Must be called before `ons.ready`.[/en]
|
177 | * [ja]iOS7以上(iPhone Xは除く)で、ステータスバー部分の高さを自動的に埋める処理を無効にします。[/ja]
|
178 | */
|
179 | ons.disableAutoStatusBarFill = () => {
|
180 | if (ons.isReady()) {
|
181 | readyError(false);
|
182 | }
|
183 | internal.config.autoStatusBarFill = false;
|
184 | };
|
185 |
|
186 | /**
|
187 | * @method mockStatusBar
|
188 | * @signature mockStatusBar()
|
189 | * @description
|
190 | * [en]Creates a static element similar to iOS status bar. Only useful for browser testing. Must be called before `ons.ready`.[/en]
|
191 | * [ja][/ja]
|
192 | */
|
193 | ons.mockStatusBar = () => {
|
194 | if (ons.isReady()) {
|
195 | readyError(false);
|
196 | }
|
197 |
|
198 | const mock = () => {
|
199 | if (!document.body.children[0] || !document.body.children[0].classList.contains('ons-status-bar-mock')) {
|
200 | const android = platform.isAndroid(), i = i => `<i class="${i.split('-')[0]} ${i}"></i>`;
|
201 | const left = android ? `${i('zmdi-twitter')} ${i('zmdi-google-play')}` : `No SIM ${i('fa-wifi')}`,
|
202 | center = android ? '' : '12:28 PM',
|
203 | right = android ? `${i('zmdi-network')} ${i('zmdi-wifi')} ${i('zmdi-battery')} 12:28 PM` : `80% ${i('fa-battery-three-quarters')}`;
|
204 |
|
205 | document.body.insertBefore(util.createElement(
|
206 | `<div class="ons-status-bar-mock ${android ? 'android' : 'ios'}">` +
|
207 | `<div>${left}</div><div>${center}</div><div>${right}</div>` +
|
208 | `</div>`
|
209 | ), document.body.firstChild);
|
210 | }
|
211 | };
|
212 |
|
213 | document.body
|
214 | ? mock()
|
215 | : internal.waitDOMContentLoaded(mock);
|
216 | };
|
217 |
|
218 | /**
|
219 | * @method disableAnimations
|
220 | * @signature disableAnimations()
|
221 | * @description
|
222 | * [en]Disable all animations. Could be handy for testing and older devices.[/en]
|
223 | * [ja]アニメーションを全て無効にします。テストの際に便利です。[/ja]
|
224 | */
|
225 | ons.disableAnimations = () => {
|
226 | internal.config.animationsDisabled = true;
|
227 | };
|
228 |
|
229 | /**
|
230 | * @method enableAnimations
|
231 | * @signature enableAnimations()
|
232 | * @description
|
233 | * [en]Enable animations (default).[/en]
|
234 | * [ja]アニメーションを有効にします。[/ja]
|
235 | */
|
236 | ons.enableAnimations = () => {
|
237 | internal.config.animationsDisabled = false;
|
238 | };
|
239 |
|
240 | ons._disableWarnings = () => {
|
241 | internal.config.warningsDisabled = true;
|
242 | };
|
243 |
|
244 | ons._enableWarnings = () => {
|
245 | internal.config.warningsDisabled = false;
|
246 | };
|
247 |
|
248 | /**
|
249 | * @method disableAutoStyling
|
250 | * @signature disableAutoStyling()
|
251 | * @description
|
252 | * [en]Disable automatic styling.[/en]
|
253 | * [ja][/ja]
|
254 | */
|
255 | ons.disableAutoStyling = autoStyle.disable;
|
256 |
|
257 | /**
|
258 | * @method enableAutoStyling
|
259 | * @signature enableAutoStyling()
|
260 | * @description
|
261 | * [en]Enable automatic styling based on OS (default).[/en]
|
262 | * [ja][/ja]
|
263 | */
|
264 | ons.enableAutoStyling = autoStyle.enable;
|
265 |
|
266 | /**
|
267 | * @method disableIconAutoPrefix
|
268 | * @signature disableIconAutoPrefix()
|
269 | * @description
|
270 | * [en]Disable adding `fa-` prefix automatically to `ons-icon` classes. Useful when including custom icon packs.[/en]
|
271 | * [ja][/ja]
|
272 | */
|
273 | ons.disableIconAutoPrefix = () => {
|
274 | util.checkMissingImport('Icon');
|
275 | elements.Icon.setAutoPrefix(false);
|
276 | };
|
277 |
|
278 | /**
|
279 | * @method forcePlatformStyling
|
280 | * @signature forcePlatformStyling(platform)
|
281 | * @description
|
282 | * [en]Refresh styling for the given platform. Only useful for demos. Use `ons.platform.select(...)` instead for development and production.[/en]
|
283 | * [ja][/ja]
|
284 | * @param {string} platform New platform to style the elements.
|
285 | */
|
286 | ons.forcePlatformStyling = newPlatform => {
|
287 | ons.enableAutoStyling();
|
288 | ons.platform.select(newPlatform || 'ios');
|
289 |
|
290 | ons._util.arrayFrom(document.querySelectorAll('*'))
|
291 | .forEach(function(element) {
|
292 | if (element.tagName.toLowerCase() === 'ons-if') {
|
293 | element._platformUpdate();
|
294 | } else if (element.tagName.match(/^ons-/i)) {
|
295 | autoStyle.prepare(element, true);
|
296 | if (element.tagName.toLowerCase() === 'ons-tabbar') {
|
297 | element._updatePosition();
|
298 | }
|
299 | }
|
300 | });
|
301 | };
|
302 |
|
303 | /**
|
304 | * @method preload
|
305 | * @signature preload(templatePaths)
|
306 | * @param {String|Array} templatePaths
|
307 | * [en]Set of HTML file paths containing 'ons-page' elements.[/en]
|
308 | * [ja][/ja]
|
309 | * @return {Promise}
|
310 | * [en]Promise that resolves when all the templates are cached.[/en]
|
311 | * [ja][/ja]
|
312 | * @description
|
313 | * [en]Separated files need to be requested on demand and this can slightly delay pushing new pages. This method requests and caches templates for later use.[/en]
|
314 | * [ja][/ja]
|
315 | */
|
316 | ons.preload = function(templates = []) {
|
317 | return Promise.all((templates instanceof Array ? templates : [templates]).map(template => {
|
318 | if (typeof template !== 'string') {
|
319 | util.throw('Expected string arguments but got ' + typeof template);
|
320 | }
|
321 | return internal.getTemplateHTMLAsync(template);
|
322 | }));
|
323 | };
|
324 |
|
325 | /**
|
326 | * @method createElement
|
327 | * @signature createElement(template, options)
|
328 | * @param {String} template
|
329 | * [en]Either an HTML file path, a `<template>` id or an HTML string such as `'<div id="foo">hoge</div>'`.[/en]
|
330 | * [ja][/ja]
|
331 | * @param {Object} [options]
|
332 | * [en]Parameter object.[/en]
|
333 | * [ja]オプションを指定するオブジェクト。[/ja]
|
334 | * @param {Boolean|HTMLElement} [options.append]
|
335 | * [en]Whether or not the element should be automatically appended to the DOM. Defaults to `false`. If `true` value is given, `document.body` will be used as the target.[/en]
|
336 | * [ja][/ja]
|
337 | * @param {HTMLElement} [options.insertBefore]
|
338 | * [en]Reference node that becomes the next sibling of the new node (`options.append` element).[/en]
|
339 | * [ja][/ja]
|
340 | * @return {HTMLElement|Promise}
|
341 | * [en]If the provided template was an inline HTML string, it returns the new element. Otherwise, it returns a promise that resolves to the new element.[/en]
|
342 | * [ja][/ja]
|
343 | * @description
|
344 | * [en]Create a new element from a template. Both inline HTML and external files are supported although the return value differs.[/en]
|
345 | * [ja][/ja]
|
346 | */
|
347 | ons.createElement = (template, options = {}) => {
|
348 | template = template.trim();
|
349 |
|
350 | const create = html => {
|
351 | const element = ons._util.createElement(html);
|
352 | element.remove();
|
353 |
|
354 | if (options.append) {
|
355 | const target = options.append instanceof HTMLElement ? options.append : document.body;
|
356 | target.insertBefore(element, options.insertBefore || null);
|
357 | options.link instanceof Function && options.link(element);
|
358 | }
|
359 |
|
360 | return element;
|
361 | };
|
362 |
|
363 | return template.charAt(0) === '<' ? create(template) : internal.getPageHTMLAsync(template).then(create);
|
364 | };
|
365 |
|
366 | /**
|
367 | * @method createPopover
|
368 | * @signature createPopover(page, [options])
|
369 | * @param {String} page
|
370 | * [en]Page name. Can be either an HTML file or a <template> containing a <ons-dialog> component.[/en]
|
371 | * [ja]pageのURLか、もしくは`<template>`で宣言したテンプレートのid属性の値を指定できます。[/ja]
|
372 | * @param {Object} [options]
|
373 | * [en]Parameter object.[/en]
|
374 | * [ja]オプションを指定するオブジェクト。[/ja]
|
375 | * @param {Object} [options.parentScope]
|
376 | * [en]Parent scope of the dialog. Used to bind models and access scope methods from the dialog.[/en]
|
377 | * [ja]ダイアログ内で利用する親スコープを指定します。ダイアログからモデルやスコープのメソッドにアクセスするのに使います。このパラメータはAngularJSバインディングでのみ利用できます。[/ja]
|
378 | * @return {Promise}
|
379 | * [en]Promise object that resolves to the popover component object.[/en]
|
380 | * [ja]ポップオーバーのコンポーネントオブジェクトを解決するPromiseオブジェクトを返します。[/ja]
|
381 | * @description
|
382 | * [en]Create a popover instance from a template.[/en]
|
383 | * [ja]テンプレートからポップオーバーのインスタンスを生成します。[/ja]
|
384 | */
|
385 | /**
|
386 | * @method createDialog
|
387 | * @signature createDialog(page, [options])
|
388 | * @param {String} page
|
389 | * [en]Page name. Can be either an HTML file or an `<template>` containing a <ons-dialog> component.[/en]
|
390 | * [ja]pageのURLか、もしくは`<template>`で宣言したテンプレートのid属性の値を指定できます。[/ja]
|
391 | * @param {Object} [options]
|
392 | * [en]Parameter object.[/en]
|
393 | * [ja]オプションを指定するオブジェクト。[/ja]
|
394 | * @return {Promise}
|
395 | * [en]Promise object that resolves to the dialog component object.[/en]
|
396 | * [ja]ダイアログのコンポーネントオブジェクトを解決するPromiseオブジェクトを返します。[/ja]
|
397 | * @description
|
398 | * [en]Create a dialog instance from a template.[/en]
|
399 | * [ja]テンプレートからダイアログのインスタンスを生成します。[/ja]
|
400 | */
|
401 | /**
|
402 | * @method createAlertDialog
|
403 | * @signature createAlertDialog(page, [options])
|
404 | * @param {String} page
|
405 | * [en]Page name. Can be either an HTML file or an `<template>` containing a <ons-alert-dialog> component.[/en]
|
406 | * [ja]pageのURLか、もしくは`<template>`で宣言したテンプレートのid属性の値を指定できます。[/ja]
|
407 | * @param {Object} [options]
|
408 | * [en]Parameter object.[/en]
|
409 | * [ja]オプションを指定するオブジェクト。[/ja]
|
410 | * @return {Promise}
|
411 | * [en]Promise object that resolves to the alert dialog component object.[/en]
|
412 | * [ja]ダイアログのコンポーネントオブジェクトを解決するPromiseオブジェクトを返します。[/ja]
|
413 | * @description
|
414 | * [en]Create a alert dialog instance from a template.[/en]
|
415 | * [ja]テンプレートからアラートダイアログのインスタンスを生成します。[/ja]
|
416 | */
|
417 | ons.createPopover = ons.createDialog = ons.createAlertDialog = (template, options = {}) => ons.createElement(template, { append: true, ...options });
|
418 |
|
419 | /**
|
420 | * @method openActionSheet
|
421 | * @signature openActionSheet(options)
|
422 | * @description
|
423 | * [en]Shows an instant Action Sheet and lets the user choose an action.[/en]
|
424 | * [ja][/ja]
|
425 | * @param {Object} [options]
|
426 | * [en]Parameter object.[/en]
|
427 | * [ja]オプションを指定するオブジェクト。[/ja]
|
428 | * @param {Array} [options.buttons]
|
429 | * [en]Represent each button of the action sheet following the specified order. Every item can be either a string label or an object containing `label`, `icon` and `modifier` properties.[/en]
|
430 | * [ja][/ja]
|
431 | * @param {String} [options.title]
|
432 | * [en]Optional title for the action sheet.[/en]
|
433 | * [ja][/ja]
|
434 | * @param {Number} [options.destructive]
|
435 | * [en]Optional index of the "destructive" button (only for iOS). It can be specified in the button array as well.[/en]
|
436 | * [ja][/ja]
|
437 | * @param {Boolean} [options.cancelable]
|
438 | * [en]Whether the action sheet can be canceled by tapping on the background mask or not.[/en]
|
439 | * [ja][/ja]
|
440 | * @param {String} [options.modifier]
|
441 | * [en]Modifier attribute of the action sheet. E.g. `'destructive'`.[/en]
|
442 | * [ja][/ja]
|
443 | * @param {String} [options.maskColor]
|
444 | * [en]Optionally change the background mask color.[/en]
|
445 | * [ja][/ja]
|
446 | * @param {String} [options.id]
|
447 | * [en]The element's id attribute.[/en]
|
448 | * [ja][/ja]
|
449 | * @param {String} [options.class]
|
450 | * [en]The element's class attribute.[/en]
|
451 | * [ja][/ja]
|
452 | * @return {Promise}
|
453 | * [en]Will resolve when the action sheet is closed. The resolve value is either the index of the tapped button or -1 when canceled.[/en]
|
454 | * [ja][/ja]
|
455 | */
|
456 | ons.openActionSheet = actionSheet;
|
457 |
|
458 | /**
|
459 | * @method resolveLoadingPlaceholder
|
460 | * @signature resolveLoadingPlaceholder(page)
|
461 | * @param {String} page
|
462 | * [en]Page name. Can be either an HTML file or a `<template>` id.[/en]
|
463 | * [ja]pageのURLか、もしくは`<template>`で宣言したテンプレートのid属性の値を指定できます。[/ja]
|
464 | * @description
|
465 | * [en]If no page is defined for the `ons-loading-placeholder` attribute it will wait for this method being called before loading the page.[/en]
|
466 | * [ja]ons-loading-placeholderの属性値としてページが指定されていない場合は、ページロード前に呼ばれるons.resolveLoadingPlaceholder処理が行われるまで表示されません。[/ja]
|
467 | */
|
468 | ons.resolveLoadingPlaceholder = (page, link) => {
|
469 | const elements = ons._util.arrayFrom(window.document.querySelectorAll('[ons-loading-placeholder]'));
|
470 | if (elements.length === 0) {
|
471 | util.throw('No ons-loading-placeholder exists');
|
472 | }
|
473 |
|
474 | elements
|
475 | .filter(element => !element.getAttribute('page'))
|
476 | .forEach(element => {
|
477 | element.setAttribute('ons-loading-placeholder', page);
|
478 | ons._resolveLoadingPlaceholder(element, page, link);
|
479 | });
|
480 | };
|
481 |
|
482 |
|
483 | ons._setupLoadingPlaceHolders = function() {
|
484 | ons.ready(() => {
|
485 | const elements = ons._util.arrayFrom(window.document.querySelectorAll('[ons-loading-placeholder]'));
|
486 |
|
487 | elements.forEach(element => {
|
488 | const page = element.getAttribute('ons-loading-placeholder');
|
489 | if (typeof page === 'string') {
|
490 | ons._resolveLoadingPlaceholder(element, page);
|
491 | }
|
492 | });
|
493 | });
|
494 | };
|
495 |
|
496 | ons._resolveLoadingPlaceholder = function(parent, page, link = ((el, done) => done())) {
|
497 | page && ons.createElement(page)
|
498 | .then(element => {
|
499 | element.style.display = 'none';
|
500 | parent.appendChild(element);
|
501 | link(element, () => {
|
502 | while (parent.firstChild && parent.firstChild !== element) {
|
503 | parent.removeChild(parent.firstChild);
|
504 | }
|
505 | element.style.display = '';
|
506 | });
|
507 | })
|
508 | .catch(error => Promise.reject('Unabled to resolve placeholder: ' + error));
|
509 | };
|
510 |
|
511 | function waitDeviceReady() {
|
512 | const unlockDeviceReady = ons._readyLock.lock();
|
513 | window.addEventListener('DOMContentLoaded', () => {
|
514 | if (ons.isWebView()) {
|
515 | window.document.addEventListener('deviceready', unlockDeviceReady, {once: true});
|
516 | } else {
|
517 | unlockDeviceReady();
|
518 | }
|
519 | }, {once: true});
|
520 | }
|
521 |
|
522 | /**
|
523 | * @method getScriptPage
|
524 | * @signature getScriptPage()
|
525 | * @description
|
526 | * [en]Access the last created page from the current `script` scope. Only works inside `<script></script>` tags that are direct children of `ons-page` element. Use this to add lifecycle hooks to a page.[/en]
|
527 | * [ja][/ja]
|
528 | * @return {HTMLElement}
|
529 | * [en]Returns the corresponding page element.[/en]
|
530 | * [ja][/ja]
|
531 | */
|
532 | const getCS = 'currentScript' in document ? () => document.currentScript : () => document.scripts[document.scripts.length - 1];
|
533 | ons.getScriptPage = () => getCS() && /ons-page/i.test(getCS().parentElement.tagName) && getCS().parentElement || null;
|
534 |
|
535 | export default ons;
|