123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566 |
- import _extends from 'babel-runtime/helpers/extends';
- import _typeof from 'babel-runtime/helpers/typeof';
- import _Promise from 'babel-runtime/core-js/promise';
-
-
- 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';
-
-
- 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');
- };
-
-
- ons.isReady = function () {
- return !ons._readyLock.isLocked();
- };
-
-
- ons.isWebView = ons.platform.isWebView;
-
-
- ons.ready = function (callback) {
- if (ons.isReady()) {
- callback();
- } else {
- ons._readyLock.waitUnlock(callback);
- }
- };
-
-
- ons.setDefaultDeviceBackButtonListener = function (listener) {
- if (!ons.isReady()) {
- readyError(true);
- }
- ons._defaultDeviceBackButtonHandler.setListener(listener);
- };
-
-
- ons.disableDeviceBackButtonHandler = function () {
- if (!ons.isReady()) {
- readyError(true);
- }
- internal.dbbDispatcher.disable();
- };
-
-
- ons.enableDeviceBackButtonHandler = function () {
- if (!ons.isReady()) {
- readyError(true);
- }
- internal.dbbDispatcher.enable();
- };
-
- ons.fireDeviceBackButtonEvent = function () {
- internal.dbbDispatcher.fireDeviceBackButtonEvent();
- };
-
-
- ons.enableAutoStatusBarFill = function () {
- if (ons.isReady()) {
- readyError(false);
- }
- internal.config.autoStatusBarFill = true;
- };
-
-
- ons.disableAutoStatusBarFill = function () {
- if (ons.isReady()) {
- readyError(false);
- }
- internal.config.autoStatusBarFill = false;
- };
-
-
- 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 '<i class="' + _i.split('-')[0] + ' ' + _i + '"></i>';
- };
- 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('<div class="ons-status-bar-mock ' + (android ? 'android' : 'ios') + '">' + ('<div>' + left + '</div><div>' + center + '</div><div>' + right + '</div>') + '</div>'), document.body.firstChild);
- }
- };
-
- document.body ? mock() : internal.waitDOMContentLoaded(mock);
- };
-
-
- ons.disableAnimations = function () {
- internal.config.animationsDisabled = true;
- };
-
-
- ons.enableAnimations = function () {
- internal.config.animationsDisabled = false;
- };
-
- ons._disableWarnings = function () {
- internal.config.warningsDisabled = true;
- };
-
- ons._enableWarnings = function () {
- internal.config.warningsDisabled = false;
- };
-
-
- ons.disableAutoStyling = autoStyle.disable;
-
-
- ons.enableAutoStyling = autoStyle.enable;
-
-
- ons.disableIconAutoPrefix = function () {
- util.checkMissingImport('Icon');
- elements.Icon.setAutoPrefix(false);
- };
-
-
- ons.forceUIWebViewScrollFix = function () {
- var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
-
- internal.config.forceUIWebViewScrollFix = force;
- };
-
-
- 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();
- }
- }
- });
- };
-
-
- 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);
- }));
- };
-
-
- ons.createElement = function (template) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
-
- template = template.trim();
-
- var create = function create(html) {
- var element = ons._util.createElement(html);
- element.remove();
-
- if (options.append) {
- var target = options.append instanceof HTMLElement ? options.append : document.body;
- target.insertBefore(element, options.insertBefore || null);
- options.link instanceof Function && options.link(element);
- }
-
- return element;
- };
-
- return template.charAt(0) === '<' ? create(template) : internal.getPageHTMLAsync(template).then(create);
- };
-
-
-
-
- ons.createPopover = ons.createDialog = ons.createAlertDialog = function (template) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- return ons.createElement(template, _extends({ append: true }, options));
- };
-
-
- ons.openActionSheet = actionSheet;
-
-
- ons.resolveLoadingPlaceholder = function (page, link) {
- var elements = ons._util.arrayFrom(window.document.querySelectorAll('[ons-loading-placeholder]'));
- if (elements.length === 0) {
- util.throw('No ons-loading-placeholder exists');
- }
-
- elements.filter(function (element) {
- return !element.getAttribute('page');
- }).forEach(function (element) {
- element.setAttribute('ons-loading-placeholder', page);
- ons._resolveLoadingPlaceholder(element, page, link);
- });
- };
-
- ons._setupLoadingPlaceHolders = function () {
- ons.ready(function () {
- var elements = ons._util.arrayFrom(window.document.querySelectorAll('[ons-loading-placeholder]'));
-
- elements.forEach(function (element) {
- var page = element.getAttribute('ons-loading-placeholder');
- if (typeof page === 'string') {
- ons._resolveLoadingPlaceholder(element, page);
- }
- });
- });
- };
-
- ons._resolveLoadingPlaceholder = function (parent, page) {
- var link = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (el, done) {
- return done();
- };
-
- page && ons.createElement(page).then(function (element) {
- element.style.display = 'none';
- parent.appendChild(element);
- link(element, function () {
- while (parent.firstChild && parent.firstChild !== element) {
- parent.removeChild(parent.firstChild);
- }
- element.style.display = '';
- });
- }).catch(function (error) {
- return _Promise.reject('Unabled to resolve placeholder: ' + error);
- });
- };
-
- function waitDeviceReady() {
- var unlockDeviceReady = ons._readyLock.lock();
- window.addEventListener('DOMContentLoaded', function () {
- if (ons.isWebView()) {
- window.document.addEventListener('deviceready', unlockDeviceReady, false);
- } else {
- unlockDeviceReady();
- }
- }, false);
- }
-
-
- var getCS = 'currentScript' in document ? function () {
- return document.currentScript;
- } : function () {
- return document.scripts[document.scripts.length - 1];
- };
- ons.getScriptPage = function () {
- return getCS() && /ons-page/i.test(getCS().parentElement.tagName) && getCS().parentElement || null;
- };
-
- export default ons;
|