UNPKG

onsenui

Version:

HTML5 Mobile Framework & UI Components

1,877 lines (1,532 loc) 2.88 MB
/* onsenui v2.10.1 - 2018-05-28 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.ons = factory()); }(this, (function () { 'use strict'; var onsElements = {}; /* 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. */ /** * Add vendor prefix. * * @param {String} name * @return {String} */ var prefix = function () { var styles = window.getComputedStyle(document.documentElement, ''); var prefix = (Array.prototype.slice.call(styles).join('').match(/-(moz|webkit|ms)-/) || styles.OLink === '' && ['', 'o'])[1]; return function (name) { return '-' + prefix + '-' + util$1.hyphenate(name); }; }(); /** * Minimal utility library for manipulating element's style. * Set element's style. * * @param {Element} element * @param {Object} styles * @return {Element} */ var styler = function styler(element, style) { Object.keys(style).forEach(function (key) { if (key in element.style) { element.style[key] = style[key]; } else if (prefix(key) in element.style) { element.style[prefix(key)] = style[key]; } else { util$1.warn('No such style property: ' + key); } }); return element; }; /** * @param {Element} element * @param {String} styles Space-separated CSS properties to remove */ styler.clear = function (element) { var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; var clearlist = styles.split(/\s+/).reduce(function (r, s) { return r.concat([util$1.hyphenate(s), prefix(s)]); }, []), keys = []; var _loop = function _loop(i) { var key = element.style[i]; if (clearlist.length === 0 || clearlist.some(function (s) { return key.indexOf(s) === 0; })) { keys.push(key); // Store the key to fix Safari style indexes } }; for (var i = element.style.length - 1; i >= 0; i--) { _loop(i); } keys.forEach(function (key) { return element.style[key] = ''; }); element.getAttribute('style') === '' && element.removeAttribute('style'); }; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; var createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var defineProperty = function (obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; var inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }; var objectWithoutProperties = function (obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }; var possibleConstructorReturn = function (self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }; var toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; /* 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. */ // Save HTMLElement object before Custom Elements polyfill patch global HTMLElement. var NativeHTMLElement = window.HTMLElement; /** * @object ons.platform * @category util * @description * [en]Utility methods to detect current platform.[/en] * [ja]現在実行されているプラットフォームを検知するためのユーティリティメソッドを収めたオブジェクトです。[/ja] */ var Platform = function () { /** * All elements will be rendered as if the app was running on this platform. * @type {String} */ function Platform() { classCallCheck(this, Platform); this._selectedPlatform = null; this._ignorePlatformSelect = false; } /** * @method select * @signature select(platform) * @param {string} platform Name of the platform. * [en]Possible values are: "opera", "firefox", "safari", "chrome", "ie", "android", "blackberry", "ios" or "wp".[/en] * [ja]"opera", "firefox", "safari", "chrome", "ie", "android", "blackberry", "ios", "wp"のいずれかを指定します。[/ja] * @description * [en]Sets the platform used to render the elements. Useful for testing.[/en] * [ja]要素を描画するために利用するプラットフォーム名を設定します。テストに便利です。[/ja] */ createClass(Platform, [{ key: 'select', value: function select(platform) { if (typeof platform === 'string') { this._selectedPlatform = platform.trim().toLowerCase(); } } }, { key: '_getSelectedPlatform', value: function _getSelectedPlatform() { return this._ignorePlatformSelect ? null : this._selectedPlatform; } }, { key: '_runOnActualPlatform', value: function _runOnActualPlatform(fn) { this._ignorePlatformSelect = true; var result = fn(); this._ignorePlatformSelect = false; return result; } //---------------- // General //---------------- /** * @method isWebView * @signature isWebView() * @description * [en]Returns whether app is running in Cordova.[/en] * [ja]Cordova内で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isWebView', value: function isWebView() { if (document.readyState === 'loading' || document.readyState == 'uninitialized') { throw new Error('isWebView() method is available after dom contents loaded.'); } return !!(window.cordova || window.phonegap || window.PhoneGap); } //---------------- // iOS devices //---------------- /** * @method isIPhone * @signature isIPhone() * @description * [en]Returns whether the device is iPhone.[/en] * [ja]iPhone上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isIPhone', value: function isIPhone() { return (/iPhone/i.test(navigator.userAgent) ); } /** * @method isIPhoneX * @signature isIPhoneX() * @description * [en]Returns whether the device is iPhone X.[/en] * [ja]iPhone X上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isIPhoneX', value: function isIPhoneX() { // iPhone 8 and iPhone X have a same user agent. We cannot avoid using window.screen. // This works well both in iOS Safari and (UI|WK)WebView of iPhone X. return this.isIPhone() && (window.screen.width === 375 && window.screen.height === 812 || window.screen.width === 812 && window.screen.height === 375); } /** * @method isIPad * @signature isIPad() * @description * [en]Returns whether the device is iPad.[/en] * [ja]iPad上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isIPad', value: function isIPad() { return (/iPad/i.test(navigator.userAgent) ); } /** * @return {Boolean} */ }, { key: 'isIPod', value: function isIPod() { return (/iPod/i.test(navigator.userAgent) ); } //---------------- // iOS versions //---------------- /** * @method isIOS * @signature isIOS() * @description * [en]Returns whether the OS is iOS.[/en] * [ja]iOS上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isIOS', value: function isIOS() { if (this._getSelectedPlatform()) { return this._getSelectedPlatform() === 'ios'; } if ((typeof device === 'undefined' ? 'undefined' : _typeof(device)) === 'object' && !/browser/i.test(device.platform)) { return (/iOS/i.test(device.platform) ); } else { return (/iPhone|iPad|iPod/i.test(navigator.userAgent) ); } } /** * @method isIOS7above * @signature isIOS7above() * @description * [en]Returns whether the iOS version is 7 or above.[/en] * [ja]iOS7以上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isIOS7above', value: function isIOS7above() { if ((typeof device === 'undefined' ? 'undefined' : _typeof(device)) === 'object' && !/browser/i.test(device.platform)) { return (/iOS/i.test(device.platform) && parseInt(device.version.split('.')[0]) >= 7 ); } else if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { var ver = (navigator.userAgent.match(/\b[0-9]+_[0-9]+(?:_[0-9]+)?\b/) || [''])[0].replace(/_/g, '.'); return parseInt(ver.split('.')[0]) >= 7; } return false; } //---------------- // iOS browsers //---------------- /** * @method isIOSSafari * @signature isIOSSafari() * @description * [en]Returns whether app is running in iOS Safari.[/en] * [ja]iOS Safariで実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isIOSSafari', value: function isIOSSafari() { var navigator = window.navigator; var ua = navigator.userAgent; return !!(this.isIOS() && ua.indexOf('Safari') !== -1 && ua.indexOf('Version') !== -1 && !navigator.standalone); } /** * @method isWKWebView * @signature isWKWebView() * @description * [en]Returns whether app is running in WKWebView.[/en] * [ja]WKWebViewで実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isWKWebView', value: function isWKWebView() { var lte9 = /constructor/i.test(NativeHTMLElement); return !!(this.isIOS() && window.webkit && window.webkit.messageHandlers && window.indexedDB && !lte9); } /** * @method isUIWebView * @signature isUIWebView() * @description * [en]Returns whether app is running in UIWebView.[/en] * [ja]UIWebViewで実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isUIWebView', value: function isUIWebView() { return !!(this.isIOS() && !this.isIOSSafari() && !this.isWKWebView()); } //---------------- // Android devices //---------------- /** * @method isAndroidPhone * @signature isAndroidPhone() * @description * [en]Returns whether the device is Android phone.[/en] * [ja]Android携帯上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isAndroidPhone', value: function isAndroidPhone() { return (/Android/i.test(navigator.userAgent) && /Mobile/i.test(navigator.userAgent) ); } /** * @method isAndroidTablet * @signature isAndroidTablet() * @description * [en]Returns whether the device is Android tablet.[/en] * [ja]Androidタブレット上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isAndroidTablet', value: function isAndroidTablet() { return (/Android/i.test(navigator.userAgent) && !/Mobile/i.test(navigator.userAgent) ); } //---------------- // Android versions //---------------- /** * @method isAndroid * @signature isAndroid() * @description * [en]Returns whether the OS is Android.[/en] * [ja]Android上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isAndroid', value: function isAndroid() { if (this._getSelectedPlatform()) { return this._getSelectedPlatform() === 'android'; } if ((typeof device === 'undefined' ? 'undefined' : _typeof(device)) === 'object' && !/browser/i.test(device.platform)) { return (/Android/i.test(device.platform) ); } else { return (/Android/i.test(navigator.userAgent) ); } } //---------------- // Other devices //---------------- /** * @return {Boolean} */ }, { key: 'isWP', value: function isWP() { if (this._getSelectedPlatform()) { return this._getSelectedPlatform() === 'wp'; } if ((typeof device === 'undefined' ? 'undefined' : _typeof(device)) === 'object' && !/browser/i.test(device.platform)) { return (/Win32NT|WinCE/i.test(device.platform) ); } else { return (/Windows Phone|IEMobile|WPDesktop/i.test(navigator.userAgent) ); } } /** * @method isBlackBerry * @signature isBlackBerry() * @description * [en]Returns whether the device is BlackBerry.[/en] * [ja]BlackBerry上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isBlackBerry', value: function isBlackBerry() { if (this._getSelectedPlatform()) { return this._getSelectedPlatform() === 'blackberry'; } if ((typeof device === 'undefined' ? 'undefined' : _typeof(device)) === 'object' && !/browser/i.test(device.platform)) { return (/BlackBerry/i.test(device.platform) ); } else { return (/BlackBerry|RIM Tablet OS|BB10/i.test(navigator.userAgent) ); } } //---------------- // Other browsers //---------------- /** * @method isOpera * @signature isOpera() * @description * [en]Returns whether the browser is Opera.[/en] * [ja]Opera上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isOpera', value: function isOpera() { if (this._getSelectedPlatform()) { return this._getSelectedPlatform() === 'opera'; } return !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; } /** * @method isFirefox * @signature isFirefox() * @description * [en]Returns whether the browser is Firefox.[/en] * [ja]Firefox上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isFirefox', value: function isFirefox() { if (this._getSelectedPlatform()) { return this._getSelectedPlatform() === 'firefox'; } return typeof InstallTrigger !== 'undefined'; } /** * @method isSafari * @signature isSafari() * @description * [en]Returns whether the browser is Safari.[/en] * [ja]Safari上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isSafari', value: function isSafari() { if (this._getSelectedPlatform()) { return this._getSelectedPlatform() === 'safari'; } return Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 || function (p) { return p.toString() === '[object SafariRemoteNotification]'; }(!window['safari'] || safari.pushNotification); } /** * @method isChrome * @signature isChrome() * @description * [en]Returns whether the browser is Chrome.[/en] * [ja]Chrome上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isChrome', value: function isChrome() { if (this._getSelectedPlatform()) { return this._getSelectedPlatform() === 'chrome'; } return !!window.chrome && !(!!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) && !(navigator.userAgent.indexOf(' Edge/') >= 0); } /** * @method isIE * @signature isIE() * @description * [en]Returns whether the browser is Internet Explorer.[/en] * [ja]Internet Explorer上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isIE', value: function isIE() { if (this._getSelectedPlatform()) { return this._getSelectedPlatform() === 'ie'; } return false || !!document.documentMode; } /** * @method isEdge * @signature isEdge() * @description * [en]Returns whether the browser is Edge.[/en] * [ja]Edge上で実行されているかどうかを返します。[/ja] * @return {Boolean} */ }, { key: 'isEdge', value: function isEdge() { if (this._getSelectedPlatform()) { return this._getSelectedPlatform() === 'edge'; } return navigator.userAgent.indexOf(' Edge/') >= 0; } //---------------- // Utility functions //---------------- /** * @return {String} */ }, { key: 'getMobileOS', value: function getMobileOS() { if (this.isAndroid()) { return 'android'; } else if (this.isIOS()) { return 'ios'; } else if (this.isWP()) { return 'wp'; } else { return 'other'; } } /** * @return {String} */ }, { key: 'getIOSDevice', value: function getIOSDevice() { if (this.isIPhone()) { return 'iphone'; } else if (this.isIPad()) { return 'ipad'; } else if (this.isIPod()) { return 'ipod'; } else { return 'na'; } } }]); return Platform; }(); var platform = new Platform(); /* 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. */ var error = function error(message) { return util$1.throw('In PageAttributeExpression: ' + message); }; var pageAttributeExpression = { _variables: {}, /** * Define a variable. * * @param {String} name Name of the variable * @param {String|Function} value Value of the variable. Can be a string or a function. The function must return a string. * @param {Boolean} overwrite If this value is false, an error will be thrown when trying to define a variable that has already been defined. */ defineVariable: function defineVariable(name, value) { var overwrite = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (typeof name !== 'string') { error('Variable name must be a string'); } else if (typeof value !== 'string' && typeof value !== 'function') { error('Variable value must be a string or a function'); } else if (this._variables.hasOwnProperty(name) && !overwrite) { error('"' + name + '" is already defined'); } this._variables[name] = value; }, /** * Get a variable. * * @param {String} name Name of the variable. * @return {String|Function|null} */ getVariable: function getVariable(name) { if (!this._variables.hasOwnProperty(name)) { return null; } return this._variables[name]; }, /** * Remove a variable. * * @param {String} name Name of the varaible. */ removeVariable: function removeVariable(name) { delete this._variables[name]; }, /** * Get all variables. * * @return {Object} */ getAllVariables: function getAllVariables() { return this._variables; }, _parsePart: function _parsePart(part) { var c = void 0, inInterpolation = false, currentIndex = 0; var tokens = []; if (part.length === 0) { error('Unable to parse empty string'); } for (var i = 0; i < part.length; i++) { c = part.charAt(i); if (c === '$' && part.charAt(i + 1) === '{') { if (inInterpolation) { error('Nested interpolation not supported'); } var token = part.substring(currentIndex, i); if (token.length > 0) { tokens.push(part.substring(currentIndex, i)); } currentIndex = i; inInterpolation = true; } else if (c === '}') { if (!inInterpolation) { error('} must be preceeded by ${'); } var _token = part.substring(currentIndex, i + 1); if (_token.length > 0) { tokens.push(part.substring(currentIndex, i + 1)); } currentIndex = i + 1; inInterpolation = false; } } if (inInterpolation) { error('Unterminated interpolation'); } tokens.push(part.substring(currentIndex, part.length)); return tokens; }, _replaceToken: function _replaceToken(token) { var re = /^\${(.*?)}$/, match = token.match(re); if (match) { var name = match[1].trim(); var variable = this.getVariable(name); if (variable === null) { error('Variable "' + name + '" does not exist'); } else if (typeof variable === 'string') { return variable; } else { var rv = variable(); if (typeof rv !== 'string') { error('Must return a string'); } return rv; } } else { return token; } }, _replaceTokens: function _replaceTokens(tokens) { return tokens.map(this._replaceToken.bind(this)); }, _parseExpression: function _parseExpression(expression) { return expression.split(',').map(function (part) { return part.trim(); }).map(this._parsePart.bind(this)).map(this._replaceTokens.bind(this)).map(function (part) { return part.join(''); }); }, /** * Evaluate an expression. * * @param {String} expression An page attribute expression. * @return {Array} */ evaluate: function evaluate(expression) { if (!expression) { return []; } return this._parseExpression(expression); } }; // Define default variables. pageAttributeExpression.defineVariable('mobileOS', platform.getMobileOS()); pageAttributeExpression.defineVariable('iOSDevice', platform.getIOSDevice()); pageAttributeExpression.defineVariable('runtime', function () { return platform.isWebView() ? 'cordova' : 'browser'; }); /* 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. */ var internal$1 = {}; internal$1.config = { autoStatusBarFill: true, animationsDisabled: false, warningsDisabled: false }; internal$1.nullElement = window.document.createElement('div'); /** * @return {Boolean} */ internal$1.isEnabledAutoStatusBarFill = function () { return !!internal$1.config.autoStatusBarFill; }; /** * @param {String} html * @return {String} */ internal$1.normalizePageHTML = function (html) { return ('' + html).trim(); }; internal$1.waitDOMContentLoaded = function (callback) { if (window.document.readyState === 'loading' || window.document.readyState == 'uninitialized') { var wrappedCallback = function wrappedCallback() { callback(); window.document.removeEventListener('DOMContentLoaded', wrappedCallback); }; window.document.addEventListener('DOMContentLoaded', wrappedCallback); } else { setImmediate(callback); } }; internal$1.autoStatusBarFill = function (action) { var onReady = function onReady() { if (internal$1.shouldFillStatusBar()) { action(); } document.removeEventListener('deviceready', onReady); }; if ((typeof device === 'undefined' ? 'undefined' : _typeof(device)) === 'object') { document.addEventListener('deviceready', onReady); } else if (['complete', 'interactive'].indexOf(document.readyState) === -1) { internal$1.waitDOMContentLoaded(onReady); } else { onReady(); } }; internal$1.shouldFillStatusBar = function () { return internal$1.isEnabledAutoStatusBarFill() && (platform.isWebView() && platform.isIOS7above() && !platform.isIPhoneX() || document.body.querySelector('.ons-status-bar-mock.ios')); }; internal$1.templateStore = { _storage: {}, /** * @param {String} key * @return {String/null} template */ get: function get$$1(key) { return internal$1.templateStore._storage[key] || null; }, /** * @param {String} key * @param {String} template */ set: function set$$1(key, template) { internal$1.templateStore._storage[key] = template; } }; window.document.addEventListener('_templateloaded', function (e) { if (e.target.nodeName.toLowerCase() === 'ons-template') { internal$1.templateStore.set(e.templateId, e.template); } }, false); internal$1.waitDOMContentLoaded(function () { register('script[type="text/ons-template"]'); register('script[type="text/template"]'); register('script[type="text/ng-template"]'); register('template'); function register(query) { var templates = window.document.querySelectorAll(query); for (var i = 0; i < templates.length; i++) { internal$1.templateStore.set(templates[i].getAttribute('id'), templates[i].textContent || templates[i].content); } } }); /** * @param {String} page * @return {Promise} */ internal$1.getTemplateHTMLAsync = function (page) { return new Promise(function (resolve, reject) { internal$1.waitDOMContentLoaded(function () { var cache = internal$1.templateStore.get(page); if (cache) { if (cache instanceof DocumentFragment) { return resolve(cache); } var html = typeof cache === 'string' ? cache : cache[1]; return resolve(internal$1.normalizePageHTML(html)); } var local = window.document.getElementById(page); if (local) { var _html = local.textContent || local.content; return resolve(_html); } var xhr = new XMLHttpRequest(); xhr.open('GET', page, true); xhr.onload = function () { var html = xhr.responseText; if (xhr.status >= 400 && xhr.status < 600) { reject(html); } else { // Refresh script tags var fragment = util$1.createFragment(html); util$1.arrayFrom(fragment.querySelectorAll('script')).forEach(function (el) { var script = document.createElement('script'); script.type = el.type || 'text/javascript'; script.appendChild(document.createTextNode(el.text || el.textContent || el.innerHTML)); el.parentNode.replaceChild(script, el); }); internal$1.templateStore.set(page, fragment); resolve(fragment); } }; xhr.onerror = function () { util$1.throw('Page template not found: ' + page); }; xhr.send(null); }); }); }; /** * @param {String} page * @return {Promise} */ internal$1.getPageHTMLAsync = function (page) { var pages = pageAttributeExpression.evaluate(page); var getPage = function getPage(page) { if (typeof page !== 'string') { return Promise.reject('Must specify a page.'); } return internal$1.getTemplateHTMLAsync(page).catch(function (error) { if (pages.length === 0) { return Promise.reject(error); } return getPage(pages.shift()); }); }; return getPage(pages.shift()); }; /* 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. */ var AnimatorFactory = function () { /** * @param {Object} opts * @param {Object} opts.animators The dictionary for animator classes * @param {Function} opts.baseClass The base class of animators * @param {String} [opts.baseClassName] The name of the base class of animators * @param {String} [opts.defaultAnimation] The default animation name * @param {Object} [opts.defaultAnimationOptions] The default animation options */ function AnimatorFactory(opts) { classCallCheck(this, AnimatorFactory); this._animators = opts.animators; this._baseClass = opts.baseClass; this._baseClassName = opts.baseClassName || opts.baseClass.name; this._animation = opts.defaultAnimation || 'default'; this._animationOptions = opts.defaultAnimationOptions || {}; if (!this._animators[this._animation]) { util$1.throw('No such animation: ' + this._animation); } } /** * @param {String} jsonString * @return {Object/null} */ createClass(AnimatorFactory, [{ key: 'setAnimationOptions', /** * @param {Object} options */ value: function setAnimationOptions(options) { this._animationOptions = options; } /** * @param {Object} options * @param {String} [options.animation] The animation name * @param {Object} [options.animationOptions] The animation options * @param {Object} defaultAnimator The default animator instance * @return {Object} An animator instance */ }, { key: 'newAnimator', value: function newAnimator() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var defaultAnimator = arguments[1]; var animator = null; if (options.animation instanceof this._baseClass) { return options.animation; } var Animator = null; if (typeof options.animation === 'string') { Animator = this._animators[options.animation]; } if (!Animator && defaultAnimator) { animator = defaultAnimator; } else { Animator = Animator || this._animators[this._animation]; var animationOpts = util$1.extend({}, this._animationOptions, options.animationOptions || {}, internal$1.config.animationsDisabled ? { duration: 0, delay: 0 } : {}); animator = new Animator(animationOpts); if (typeof animator === 'function') { animator = new animator(animationOpts); // eslint-disable-line new-cap } } if (!(animator instanceof this._baseClass)) { util$1.throw('"animator" is not an instance of ' + this._baseClassName); } return animator; } }], [{ key: 'parseAnimationOptionsString', value: function parseAnimationOptionsString(jsonString) { try { if (typeof jsonString === 'string') { var result = util$1.animationOptionsParse(jsonString); if ((typeof result === 'undefined' ? 'undefined' : _typeof(result)) === 'object' && result !== null) { return result; } else { console.error('"animation-options" attribute must be a JSON object string: ' + jsonString); } } return {}; } catch (e) { console.error('"animation-options" attribute must be a JSON object string: ' + jsonString); return {}; } } }]); return AnimatorFactory; }(); /* 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. */ var autoStyleEnabled = true; // Modifiers var modifiersMap = { 'quiet': 'material--flat', 'light': 'material--flat', 'outline': 'material--flat', 'cta': '', 'large--quiet': 'material--flat large', 'large--cta': 'large', 'noborder': '', 'tappable': '' }; var platforms = {}; platforms.android = function (element) { var elementName = element.tagName.toLowerCase(); if (!util$1.hasModifier(element, 'material')) { var oldModifier = element.getAttribute('modifier') || ''; var newModifier = oldModifier.trim().split(/\s+/).map(function (e) { return modifiersMap.hasOwnProperty(e) ? modifiersMap[e] : e; }); newModifier.unshift('material'); element.setAttribute('modifier', newModifier.join(' ').trim()); } var elements = ['ons-alert-dialog-button', 'ons-toolbar-button', 'ons-back-button', 'ons-button', 'ons-list-item', 'ons-fab', 'ons-speed-dial', 'ons-speed-dial-item', 'ons-tab']; // Effects if (elements.indexOf(elementName) !== -1 && !element.hasAttribute('ripple') && !element.querySelector('ons-ripple')) { if (elementName === 'ons-list-item') { if (element.hasAttribute('tappable')) { element.setAttribute('ripple', ''); element.removeAttribute('tappable'); } } else { element.setAttribute('ripple', ''); } } }; platforms.ios = function (element) { // Modifiers if (util$1.removeModifier(element, 'material')) { if (util$1.removeModifier(element, 'material--flat')) { util$1.addModifier(element, util$1.removeModifier(element, 'large') ? 'large--quiet' : 'quiet'); } if (!element.getAttribute('modifier')) { element.removeAttribute('modifier'); } } // Effects if (element.hasAttribute('ripple')) { if (element.tagName.toLowerCase() === 'ons-list-item') { element.setAttribute('tappable', ''); } element.removeAttribute('ripple'); } }; var unlocked = { android: true }; var getPlatform = function getPlatform(element, force) { if (autoStyleEnabled && !element.hasAttribute('disable-auto-styling')) { var mobileOS = platform.getMobileOS(); if (platforms.hasOwnProperty(mobileOS) && (unlocked.hasOwnProperty(mobileOS) || force)) { return mobileOS; } } return null; }; var prepare = function prepare(element, force) { var p = getPlatform(element, force); p && platforms[p](element); }; var mapModifier = function mapModifier(modifier, element, force) { if (getPlatform(element, force)) { return modifier.split(/\s+/).map(function (m) { return modifiersMap.hasOwnProperty(m) ? modifiersMap[m] : m; }).join(' '); } return modifier; }; var restoreModifier = function restoreModifier(element) { if (getPlatform(element) === 'android') { var modifier = element.getAttribute('modifier') || ''; var newModifier = mapModifier(modifier, element); if (!/(^|\s+)material($|\s+)/i.test(modifier)) { newModifier = 'material ' + newModifier; } if (newModifier !== modifier) { element.setAttribute('modifier', newModifier.trim()); return true; } } return false; }; var autoStyle = { isEnabled: function isEnabled() { return autoStyleEnabled; }, enable: function enable() { return autoStyleEnabled = true; }, disable: function disable() { return autoStyleEnabled = false; }, prepare: prepare, mapModifier: mapModifier, getPlatform: getPlatform, restoreModifier: restoreModifier }; /* 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. */ var ModifierUtil = function () { function ModifierUtil() { classCallCheck(this, ModifierUtil); } createClass(ModifierUtil, null, [{ key: 'diff', /** * @param {String} last * @param {String} current */ value: function diff(last, current) { last = makeDict(('' + last).trim()); current = makeDict(('' + current).trim()); var removed = Object.keys(last).reduce(function (result, token) { if (!current[token]) { result.push(token); } return result; }, []); var added = Object.keys(current).reduce(function (result, token) { if (!last[token]) { result.push(token); } return result; }, []); return { added: added, removed: removed }; function makeDict(modifier) { var dict = {}; ModifierUtil.split(modifier).forEach(function (token) { return dict[token] = token; }); return dict; } } /** * @param {Object} diff * @param {Array} diff.removed * @param {Array} diff.added * @param {Object} classList * @param {String} template */ }, { key: 'applyDiffToClassList', value: function applyDiffToClassList(diff, classList, template) { diff.added.map(function (modifier) { return template.replace(/\*/g, modifier); }).forEach(function (klass) { return klass.split(/\s+/).forEach(function (k) { return classList.add(k); }); }); diff.removed.map(function (modifier) { return template.replace(/\*/g, modifier); }).forEach(function (klass) { return klass.split(/\s+/).forEach(function (k) { return classList.remove(k); }); }); } /** * @param {Object} diff * @param {Array} diff.removed * @param {Array} diff.added * @param {HTMLElement} element * @param {Object} scheme */ }, { key: 'applyDiffToElement', value: function applyDiffToElement(diff, element, scheme) { Object.keys(scheme).forEach(function (selector) { var targetElements = !selector || util$1.match(element, selector) ? [element] : Array.prototype.filter.call(element.querySelectorAll(selector), function (targetElement) { return !util$1.findParent(targetElement, element.tagName, function (parent) { return parent === element; }); }); for (var i = 0; i < targetElements.length; i++) { ModifierUtil.applyDiffToClassList(diff, targetElements[i].classList, scheme[selector]); } }); } /** * @param {String} last * @param {String} current * @param {HTMLElement} element * @param {Object} scheme */ }, { key: 'onModifierChanged', value: function onModifierChanged(last, current, element, scheme) { ModifierUtil.applyDiffToElement(ModifierUtil.diff(last, current), element, scheme); autoStyle.restoreModifier(element); } }, { key: 'refresh', value: function refresh(element, scheme) { ModifierUtil.applyDiffToElement(ModifierUtil.diff('', element.getAttribute('modifier') || ''), element, scheme); } /** * @param {HTMLElement} element * @param {Object} scheme */ }, { key: 'initModifier', value: function initModifier(element, scheme) { var modifier = element.getAttribute('modifier'); if (typeof modifier !== 'string') { return; } ModifierUtil.applyDiffToElement({ removed: [], added: ModifierUtil.split(modifier) }, element, scheme); } }, { key: 'split', value: function split(modifier) { if (typeof modifier !== 'string') { return []; } return modifier.trim().split(/ +/).filter(function (token) { return token !== ''; }); } /** * Add modifier token to an element. */ }, { key: 'addModifier', value: function addModifier(element, modifierToken) { if (!element.hasAttribute('modifier')) { element.setAttribute('modifier', modifierToken); } else { var tokens = ModifierUtil.split(element.getAttribute('modifier')); if (tokens.indexOf(modifierToken) == -1) { tokens.push(modifierToken); element.setAttribute('modifier', tokens.join(' ')); } } } /** * Remove modifier token from an element. */ }, { key: 'removeModifier', value: function removeModifier(element, modifierToken) { if (element.hasAttribute('modifier')) { var tokens = ModifierUtil.split(element.getAttribute('modifier')); var index = tokens.indexOf(modifierToken); if (index !== -1) { tokens.splice(index, 1); element.setAttribute('modifier', tokens.join(' ')); } } } }]); return ModifierUtil; }(); /* 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. */ var util$3 = { _ready: false, _domContentLoaded: false, _onDOMContentLoaded: function _onDOMContentLoaded() { util$3._domContentLoaded = true; if (platform.isWebView()) { window.document.addEventListener('deviceready', function () { util$3._ready = true; }, false); } else { util$3._ready = true; } }, addBackButtonListener: function addBackButtonListener(fn) { if (!this._domContentLoaded) { throw new Error('This method is available after DOMContentLoaded'); } if (this._ready) { window.document.addEventListener('backbutton', fn, false); } else { window.document.addEventListener('deviceready', function () { window.document.addEventListener('backbutton', fn, false); }); } }, removeBackButtonListener: function removeBackButtonListener(fn) { if (!this._domContentLoaded) { throw new Error('This method is available after DOMContentLoaded'); } if (this._ready) { window.document.removeEventListener('backbutton', fn, false); } else { window.document.addEventListener('deviceready', function () { window.document.removeEventListener('backbutton', fn, false); }); } } }; window.addEventListener('DOMContentLoaded', function () { return util$3._onDOMContentLoaded(); }, false); var HandlerRepository = { _store: {}, _genId: function () { var i = 0; return function () { return i++; }; }(), set: function set$$1(element, handler) { if (element.dataset.deviceBackButtonHandlerId) { this.remove(element); } var id = element.dataset.deviceBackButtonHandlerId = HandlerRepository._genId(); this._store[id] = handler; }, remove: function remove(element) { if (element.dataset.deviceBackButtonHandlerId) { delete this._store[element.dataset.deviceBackButtonHandlerId]; delete element.dataset.deviceBackButtonHandlerId; } }, get: function get$$1(element) { if (!element.dataset.deviceBackButtonHandlerId) { return undefined; } var id = element.dataset.deviceBackButtonHandlerId; if (!this._store[id]) { throw new Error(); } return this._store[id]; }, has: function has(element) { if (!element.dataset) { return false; } var id = element.dataset.deviceBackButtonHandlerId; return !!this._store[id]; } }; var DeviceBackButtonDispatcher = function () { function DeviceBackButtonDispatcher() { classCallCheck(this, DeviceBackButtonDispatcher); this._isEnabled = false; this._boundCallback = this._callback.bind(this); } /** * Enable to handle 'backbutton' events. */ createClass(DeviceBackButtonDispatcher, [{ key: 'enable', value: function enable() { if (!this._isEnabled) { util$3.addBackButtonListener(this._boundCallback); this._isEnabled = true; } } /** * Disable to handle 'backbutton' events. */ }, { key: 'disable', value: function disable() { if (this._isEnabled) { util$3.removeBackButtonListener(this._boundCallback); this._isEnabled = false; } } /** * Fire a 'backbutton' event manually. */ }, { key: 'fireDeviceBackButtonEvent', value: function fireDeviceBackButtonEvent() { var event = document.createEvent('Event'); event.initEvent('backbutton', true, true); document.dispatchEvent(event); } }, { key: '_callback', value: function _callback() { this._dispatchDeviceBackButtonEvent(); } /** * @param {HTMLElement} element * @param {Function} callback */ }, { key: 'createHandler', value: function createHandler(element, callback) { if (!(element instanceof HTMLElement)) { throw new Error('element must be an instance of HTMLElement'); } if (!(callback instanceof Function)) { throw new Error('callback must be an instance of Function'); } var handler = { _callback: callback, _element: element, disable: function disable() { HandlerRepository.remove(element); }, setListener: function setListener(callback) { this._callback = callback; }, enable: function enable() { HandlerRepository.set(element, this); }, isEnabled: function isEnabled() { return HandlerRepository.get(element) === this; }, destroy: function destroy() { HandlerRepository.remove(element); this._callback = this._element = null; } }; handler.enable(); return handler; } }, { key: '_dispatchDeviceBackButtonEvent', value: function _dispatchDeviceBackButtonEvent() { var tree = this._captureTree(); var element = this._findHandlerLeafElement(tree); var handler = HandlerRepository.get(element); handler._callback(createEvent(element)); function createEvent(element) { return { _element: element, callParentHandler: function callParentHandler() { var parent = this._element.parentNode; while (parent) { handler = HandlerRe