import _extends from 'babel-runtime/helpers/extends'; import _typeof from 'babel-runtime/helpers/typeof'; import _Promise from 'babel-runtime/core-js/promise'; /* Copyright 2013-2015 ASIAL CORPORATION Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import util from './util'; import elements from './elements'; import animit from './animit'; import GestureDetector from './gesture-detector'; import platform from './platform'; import notification from './notification'; import actionSheet from './action-sheet'; import internal from './internal'; import orientation from './orientation'; import modifier from './modifier'; import softwareKeyboard from './software-keyboard'; import pageAttributeExpression from './page-attribute-expression'; import autoStyle from './autostyle'; import DoorLock from './doorlock'; import { defaultPageLoader, PageLoader } from './page-loader'; /** * @object ons * @category util * @description * [ja]Onsen UIで利用できるグローバルなオブジェクトです。[/ja] * [en]A global object that's used in Onsen UI. [/en] */ var ons = { animit: animit, defaultPageLoader: defaultPageLoader, elements: elements, GestureDetector: GestureDetector, modifier: modifier, notification: notification, orientation: orientation, pageAttributeExpression: pageAttributeExpression, PageLoader: PageLoader, platform: platform, softwareKeyboard: softwareKeyboard, _autoStyle: autoStyle, _internal: internal, _readyLock: new DoorLock(), _util: util }; ons.platform.select((window.location.search.match(/platform=([\w-]+)/) || [])[1]); waitDeviceReady(); var readyError = function readyError(after) { return util.throw('This method must be called ' + (after ? 'after' : 'before') + ' ons.isReady() is true'); }; /** * @method isReady * @signature isReady() * @return {Boolean} * [en]Will be true if Onsen UI is initialized.[/en] * [ja]初期化されているかどうかを返します。[/ja] * @description * [en]Returns true if Onsen UI is initialized.[/en] * [ja]Onsen UIがすでに初期化されているかどうかを返すメソッドです。[/ja] */ ons.isReady = function () { return !ons._readyLock.isLocked(); }; /** * @method isWebView * @signature isWebView() * @return {Boolean} * [en]Will be true if the app is running in Cordova.[/en] * [ja]Cordovaで実行されている場合にtrueになります。[/ja] * @description * [en]Returns true if running inside Cordova.[/en] * [ja]Cordovaで実行されているかどうかを返すメソッドです。[/ja] */ ons.isWebView = ons.platform.isWebView; /** * @method ready * @signature ready(callback) * @description * [ja]アプリの初期化に利用するメソッドです。渡された関数は、Onsen UIの初期化が終了している時点で必ず呼ばれます。[/ja] * [en]Method used to wait for app initialization. Waits for `DOMContentLoaded` and `deviceready`, when necessary, before executing the callback.[/en] * @param {Function} callback * [en]Function that executes after Onsen UI has been initialized.[/en] * [ja]Onsen UIが初期化が完了した後に呼び出される関数オブジェクトを指定します。[/ja] */ ons.ready = function (callback) { if (ons.isReady()) { callback(); } else { ons._readyLock.waitUnlock(callback); } }; /** * @method setDefaultDeviceBackButtonListener * @signature setDefaultDeviceBackButtonListener(listener) * @param {Function} listener * [en]Function that executes when device back button is pressed. Must be called on `ons.ready`.[/en] * [ja]デバイスのバックボタンが押された時に実行される関数オブジェクトを指定します。[/ja] * @description * [en]Set default handler for device back button.[/en] * [ja]デバイスのバックボタンのためのデフォルトのハンドラを設定します。[/ja] */ ons.setDefaultDeviceBackButtonListener = function (listener) { if (!ons.isReady()) { readyError(true); } ons._defaultDeviceBackButtonHandler.setListener(listener); }; /** * @method disableDeviceBackButtonHandler * @signature disableDeviceBackButtonHandler() * @description * [en]Disable device back button event handler. Must be called on `ons.ready`.[/en] * [ja]デバイスのバックボタンのイベントを受け付けないようにします。[/ja] */ ons.disableDeviceBackButtonHandler = function () { if (!ons.isReady()) { readyError(true); } internal.dbbDispatcher.disable(); }; /** * @method enableDeviceBackButtonHandler * @signature enableDeviceBackButtonHandler() * @description * [en]Enable device back button event handler. Must be called on `ons.ready`.[/en] * [ja]デバイスのバックボタンのイベントを受け付けるようにします。[/ja] */ ons.enableDeviceBackButtonHandler = function () { if (!ons.isReady()) { readyError(true); } internal.dbbDispatcher.enable(); }; ons.fireDeviceBackButtonEvent = function () { internal.dbbDispatcher.fireDeviceBackButtonEvent(); }; /** * @method enableAutoStatusBarFill * @signature enableAutoStatusBarFill() * @description * [en]Enable status bar fill feature on iOS7 and above (except for iPhone X). Must be called before `ons.ready`.[/en] * [ja]iOS7以上(iPhone Xは除く)で、ステータスバー部分の高さを自動的に埋める処理を有効にします。[/ja] */ ons.enableAutoStatusBarFill = function () { if (ons.isReady()) { readyError(false); } internal.config.autoStatusBarFill = true; }; /** * @method disableAutoStatusBarFill * @signature disableAutoStatusBarFill() * @description * [en]Disable status bar fill feature on iOS7 and above (except for iPhone X). Must be called before `ons.ready`.[/en] * [ja]iOS7以上(iPhone Xは除く)で、ステータスバー部分の高さを自動的に埋める処理を無効にします。[/ja] */ ons.disableAutoStatusBarFill = function () { if (ons.isReady()) { readyError(false); } internal.config.autoStatusBarFill = false; }; /** * @method mockStatusBar * @signature mockStatusBar() * @description * [en]Creates a static element similar to iOS status bar. Only useful for browser testing. Must be called before `ons.ready`.[/en] * [ja][/ja] */ ons.mockStatusBar = function () { if (ons.isReady()) { readyError(false); } var mock = function mock() { if (!document.body.children[0] || !document.body.children[0].classList.contains('ons-status-bar-mock')) { var android = platform.isAndroid(), i = function i(_i) { return ''; }; var left = android ? i('zmdi-twitter') + ' ' + i('zmdi-google-play') : 'No SIM ' + i('fa-wifi'), center = android ? '' : '12:28 PM', right = android ? i('zmdi-network') + ' ' + i('zmdi-wifi') + ' ' + i('zmdi-battery') + ' 12:28 PM' : '80% ' + i('fa-battery-three-quarters'); document.body.insertBefore(util.createElement('
' + ('
' + left + '
' + center + '
' + right + '
') + '
'), document.body.firstChild); } }; document.body ? mock() : internal.waitDOMContentLoaded(mock); }; /** * @method disableAnimations * @signature disableAnimations() * @description * [en]Disable all animations. Could be handy for testing and older devices.[/en] * [ja]アニメーションを全て無効にします。テストの際に便利です。[/ja] */ ons.disableAnimations = function () { internal.config.animationsDisabled = true; }; /** * @method enableAnimations * @signature enableAnimations() * @description * [en]Enable animations (default).[/en] * [ja]アニメーションを有効にします。[/ja] */ ons.enableAnimations = function () { internal.config.animationsDisabled = false; }; ons._disableWarnings = function () { internal.config.warningsDisabled = true; }; ons._enableWarnings = function () { internal.config.warningsDisabled = false; }; /** * @method disableAutoStyling * @signature disableAutoStyling() * @description * [en]Disable automatic styling.[/en] * [ja][/ja] */ ons.disableAutoStyling = autoStyle.disable; /** * @method enableAutoStyling * @signature enableAutoStyling() * @description * [en]Enable automatic styling based on OS (default).[/en] * [ja][/ja] */ ons.enableAutoStyling = autoStyle.enable; /** * @method disableIconAutoPrefix * @signature disableIconAutoPrefix() * @description * [en]Disable adding `fa-` prefix automatically to `ons-icon` classes. Useful when including custom icon packs.[/en] * [ja][/ja] */ ons.disableIconAutoPrefix = function () { util.checkMissingImport('Icon'); elements.Icon.setAutoPrefix(false); }; /** * @method forceUIWebViewScrollFix * @signature forceUIWebViewScrollFix() * @param {Boolean} force Enable or disable the fix. * @description * [en]Applies a fix for iOS UIWebView which prevents scroll events jumping to pages under the top layer. This may visually affect normal scrolling of UIWebView if you open a dialog/menu before the scroll momentum finished. Disabled by default.[/en] * [ja][/ja] */ ons.forceUIWebViewScrollFix = function () { var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; internal.config.forceUIWebViewScrollFix = force; }; /** * @method forcePlatformStyling * @signature forcePlatformStyling(platform) * @description * [en]Refresh styling for the given platform. Only useful for demos. Use `ons.platform.select(...)` instead for development and production.[/en] * [ja][/ja] * @param {string} platform New platform to style the elements. */ ons.forcePlatformStyling = function (newPlatform) { ons.enableAutoStyling(); ons.platform.select(newPlatform || 'ios'); ons._util.arrayFrom(document.querySelectorAll('*')).forEach(function (element) { if (element.tagName.toLowerCase() === 'ons-if') { element._platformUpdate(); } else if (element.tagName.match(/^ons-/i)) { autoStyle.prepare(element, true); if (element.tagName.toLowerCase() === 'ons-tabbar') { element._updatePosition(); } } }); }; /** * @method preload * @signature preload(templatePaths) * @param {String|Array} templatePaths * [en]Set of HTML file paths containing 'ons-page' elements.[/en] * [ja][/ja] * @return {Promise} * [en]Promise that resolves when all the templates are cached.[/en] * [ja][/ja] * @description * [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] * [ja][/ja] */ ons.preload = function () { var templates = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; return _Promise.all((templates instanceof Array ? templates : [templates]).map(function (template) { if (typeof template !== 'string') { util.throw('Expected string arguments but got ' + (typeof template === 'undefined' ? 'undefined' : _typeof(template))); } return internal.getTemplateHTMLAsync(template); })); }; /** * @method createElement * @signature createElement(template, options) * @param {String} template * [en]Either an HTML file path, a `