12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277 |
- import _typeof from 'babel-runtime/helpers/typeof';
- import _setImmediate from 'babel-runtime/core-js/set-immediate';
- import _Promise from 'babel-runtime/core-js/promise';
- import _WeakMap from 'babel-runtime/core-js/weak-map';
- import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
- import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
- import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
- import _createClass from 'babel-runtime/helpers/createClass';
- import _inherits from 'babel-runtime/helpers/inherits';
-
-
- import onsElements from '../../ons/elements';
- import util from '../../ons/util';
- import internal from '../../ons/internal';
- import SwipeReveal from '../../ons/internal/swipe-reveal';
- import AnimatorFactory from '../../ons/internal/animator-factory';
- import NavigatorAnimator from './animator';
- import IOSSlideNavigatorAnimator from './ios-slide-animator';
- import IOSLiftNavigatorAnimator from './ios-lift-animator';
- import IOSFadeNavigatorAnimator from './ios-fade-animator';
- import MDSlideNavigatorAnimator from './md-slide-animator';
- import MDLiftNavigatorAnimator from './md-lift-animator';
- import MDFadeNavigatorAnimator from './md-fade-animator';
- import NoneNavigatorAnimator from './none-animator';
- import platform from '../../ons/platform';
- import contentReady from '../../ons/content-ready';
- import BaseElement from '../base/base-element';
- import deviceBackButtonDispatcher from '../../ons/internal/device-back-button-dispatcher';
- import { PageLoader, defaultPageLoader, instantPageLoader } from '../../ons/page-loader';
-
- var _animatorDict = {
- 'default': function _default() {
- return platform.isAndroid() ? MDFadeNavigatorAnimator : IOSSlideNavigatorAnimator;
- },
- 'slide': function slide() {
- return platform.isAndroid() ? MDSlideNavigatorAnimator : IOSSlideNavigatorAnimator;
- },
- 'lift': function lift() {
- return platform.isAndroid() ? MDLiftNavigatorAnimator : IOSLiftNavigatorAnimator;
- },
- 'fade': function fade() {
- return platform.isAndroid() ? MDFadeNavigatorAnimator : IOSFadeNavigatorAnimator;
- },
- 'slide-ios': IOSSlideNavigatorAnimator,
- 'slide-md': MDSlideNavigatorAnimator,
- 'lift-ios': IOSLiftNavigatorAnimator,
- 'lift-md': MDLiftNavigatorAnimator,
- 'fade-ios': IOSFadeNavigatorAnimator,
- 'fade-md': MDFadeNavigatorAnimator,
- 'none': NoneNavigatorAnimator
- };
-
- var rewritables = {
-
-
- ready: function ready(navigatorElement, callback) {
- callback();
- }
- };
-
- var verifyPageElement = function verifyPageElement(el) {
- return el.nodeName !== 'ONS-PAGE' && util.throw('Only page elements can be children of navigator');
- };
-
-
-
- var NavigatorElement = function (_BaseElement) {
- _inherits(NavigatorElement, _BaseElement);
-
- _createClass(NavigatorElement, [{
- key: 'animatorFactory',
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- get: function get() {
- return this._animatorFactory;
- }
- }]);
-
- function NavigatorElement() {
- _classCallCheck(this, NavigatorElement);
-
- var _this = _possibleConstructorReturn(this, (NavigatorElement.__proto__ || _Object$getPrototypeOf(NavigatorElement)).call(this));
-
- _this._isRunning = false;
- _this._initialized = false;
- _this._pageLoader = defaultPageLoader;
- _this._pageMap = new _WeakMap();
-
- _this._updateAnimatorFactory();
- return _this;
- }
-
-
-
-
-
- _createClass(NavigatorElement, [{
- key: '_getPageTarget',
- value: function _getPageTarget() {
- return this._page || this.getAttribute('page');
- }
-
-
-
-
- }, {
- key: 'connectedCallback',
- value: function connectedCallback() {
- var _this2 = this;
-
- this.onDeviceBackButton = this._onDeviceBackButton.bind(this);
-
- if (!platform.isAndroid() || this.getAttribute('swipeable') === 'force') {
- var swipeAnimator = void 0;
-
- this._swipe = new SwipeReveal({
- element: this,
- getThreshold: function getThreshold() {
- return Math.max(0.2, parseFloat(_this2.getAttribute('swipe-threshold')) || 0);
- },
-
- swipeMax: function swipeMax() {
- _this2._onSwipe && _this2._onSwipe(1, { duration: swipeAnimator.durationSwipe, timing: swipeAnimator.timingSwipe });
- _this2[_this2.swipeMax ? 'swipeMax' : 'popPage']({ animator: swipeAnimator });
- swipeAnimator = null;
- },
- swipeMid: function swipeMid(distance, width) {
- _this2._onSwipe && _this2._onSwipe(distance / width);
- swipeAnimator.translate(distance, width, _this2.topPage.previousElementSibling, _this2.topPage);
- },
- swipeMin: function swipeMin() {
- _this2._onSwipe && _this2._onSwipe(0, { duration: swipeAnimator.durationRestore, timing: swipeAnimator.timingSwipe });
- swipeAnimator.restore(_this2.topPage.previousElementSibling, _this2.topPage);
- swipeAnimator = null;
- },
-
- ignoreSwipe: function ignoreSwipe(event, distance) {
-
- if (!_this2._isRunning && _this2.children.length > 1) {
-
-
- var area = parseInt(_this2.getAttribute('swipe-target-width') || 25, 10);
- if (event.gesture.direction === 'right' && area > distance) {
-
-
- var isBB = function isBB(el) {
- return (/ons-back-button/i.test(el.tagName)
- );
- };
- if (!isBB(event.target) && !util.findParent(event.target, isBB, function (p) {
- return (/ons-page/i.test(p.tagName)
- );
- })) {
-
-
- var animation = (_this2.topPage.pushedOptions || {}).animation || _this2.animatorFactory._animation;
- var Animator = _animatorDict[animation] instanceof Function ? _animatorDict[animation].call() : _animatorDict[animation];
-
- if (typeof Animator !== 'undefined' && Animator.swipeable) {
- swipeAnimator = new Animator();
- return false;
- }
- }
- }
- }
-
- return true;
- }
- });
-
- this.attributeChangedCallback('swipeable');
- }
-
- if (this._initialized) {
- return;
- }
-
- this._initialized = true;
-
- var deferred = util.defer();
- this.loaded = deferred.promise;
-
- rewritables.ready(this, function () {
- var show = !util.hasAnyComponentAsParent(_this2);
- var options = { animation: 'none', show: show };
-
- if (_this2.pages.length === 0 && _this2._getPageTarget()) {
- _this2.pushPage(_this2._getPageTarget(), options).then(function () {
- return deferred.resolve();
- });
- } else if (_this2.pages.length > 0) {
- for (var i = 0; i < _this2.pages.length; i++) {
- verifyPageElement(_this2.pages[i]);
- }
-
- if (_this2.topPage) {
- contentReady(_this2.topPage, function () {
- return setTimeout(function () {
- deferred.resolve();
- show && _this2.topPage._show();
- _this2._updateLastPageBackButton();
- }, 0);
- });
- }
- } else {
- contentReady(_this2, function () {
- if (_this2.pages.length === 0 && _this2._getPageTarget()) {
- _this2.pushPage(_this2._getPageTarget(), options).then(function () {
- return deferred.resolve();
- });
- } else {
- deferred.resolve();
- }
- });
- }
- });
- }
- }, {
- key: '_updateAnimatorFactory',
- value: function _updateAnimatorFactory() {
- this._animatorFactory = new AnimatorFactory({
- animators: _animatorDict,
- baseClass: NavigatorAnimator,
- baseClassName: 'NavigatorAnimator',
- defaultAnimation: this.getAttribute('animation')
- });
- }
- }, {
- key: 'disconnectedCallback',
- value: function disconnectedCallback() {
- this._backButtonHandler.destroy();
- this._backButtonHandler = null;
-
- this._swipe && this._swipe.dispose();
- this._swipe = null;
- }
- }, {
- key: 'attributeChangedCallback',
- value: function attributeChangedCallback(name, last, current) {
- switch (name) {
- case 'animation':
- this._updateAnimatorFactory();
- break;
- case 'swipeable':
- this._swipe && this._swipe.update();
- break;
- }
- }
-
-
-
-
- }, {
- key: 'popPage',
- value: function popPage() {
- var _this3 = this;
-
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
-
- var _preparePageAndOption = this._preparePageAndOptions(null, options);
-
- options = _preparePageAndOption.options;
-
-
- if (util.isInteger(options.times) && options.times > 1) {
- this._removePages(options.times);
- }
-
- var popUpdate = function popUpdate() {
- return new _Promise(function (resolve) {
- _this3._pageLoader.unload(_this3.pages[_this3.pages.length - 1]);
- resolve();
- });
- };
-
- return this._popPage(options, popUpdate);
- }
- }, {
- key: '_popPage',
- value: function _popPage(options) {
- var _this4 = this;
-
- var update = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
- return _Promise.resolve();
- };
-
- if (this._isRunning) {
- return _Promise.reject('popPage is already running.');
- }
-
- if (this.pages.length <= 1) {
- return _Promise.reject('ons-navigator\'s page stack is empty.');
- }
-
- if (this._emitPrePopEvent()) {
- return _Promise.reject('Canceled in prepop event.');
- }
-
- var length = this.pages.length;
-
- this._isRunning = true;
-
- this.pages[length - 2].updateBackButton(length - 2 > 0);
-
- return new _Promise(function (resolve) {
- var leavePage = _this4.pages[length - 1];
- var enterPage = _this4.pages[length - 2];
-
- options = util.extend({}, _this4.options || {}, leavePage.pushedOptions || {}, options);
-
- if (options.data) {
- enterPage.data = util.extend({}, enterPage.data || {}, options.data || {});
- }
-
- var done = function done() {
- update().then(function () {
- _this4._isRunning = false;
-
- enterPage._show();
- util.triggerElementEvent(_this4, 'postpop', { leavePage: leavePage, enterPage: enterPage, navigator: _this4 });
-
- options.callback && options.callback(enterPage);
-
- resolve(enterPage);
- });
- };
-
- leavePage._hide();
- enterPage.style.display = '';
-
- var animator = options.animator || _this4._animatorFactory.newAnimator(options);
- animator.pop(_this4.pages[length - 2], _this4.pages[length - 1], done);
- }).catch(function () {
- return _this4._isRunning = false;
- });
- }
-
-
-
-
- }, {
- key: 'pushPage',
- value: function pushPage(page) {
- var _this5 = this;
-
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
-
- var _preparePageAndOption2 = this._preparePageAndOptions(page, options);
-
- page = _preparePageAndOption2.page;
- options = _preparePageAndOption2.options;
-
-
- var prepare = function prepare(pageElement) {
- verifyPageElement(pageElement);
- _this5._pageMap.set(pageElement, page);
- pageElement = util.extend(pageElement, {
- data: options.data
- });
- pageElement.style.visibility = 'hidden';
- };
-
- if (options.pageHTML) {
- return this._pushPage(options, function () {
- return new _Promise(function (resolve) {
- instantPageLoader.load({ page: options.pageHTML, parent: _this5, params: options.data }, function (pageElement) {
- prepare(pageElement);
- resolve();
- });
- });
- });
- }
-
- return this._pushPage(options, function () {
- return new _Promise(function (resolve) {
- _this5._pageLoader.load({ page: page, parent: _this5, params: options.data }, function (pageElement) {
- prepare(pageElement);
- resolve();
- });
- });
- });
- }
- }, {
- key: '_pushPage',
- value: function _pushPage() {
- var _this6 = this;
-
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var update = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
- return _Promise.resolve();
- };
-
- if (this._isRunning) {
- return _Promise.reject('pushPage is already running.');
- }
-
- if (this._emitPrePushEvent()) {
- return _Promise.reject('Canceled in prepush event.');
- }
-
- this._isRunning = true;
-
- var animationOptions = AnimatorFactory.parseAnimationOptionsString(this.getAttribute('animation-options'));
- options = util.extend({}, this.options || {}, { animationOptions: animationOptions }, options);
-
- var animator = this._animatorFactory.newAnimator(options);
-
- return update().then(function () {
- var pageLength = _this6.pages.length;
-
- var enterPage = _this6.pages[pageLength - 1];
- var leavePage = options.leavePage || _this6.pages[pageLength - 2];
-
- verifyPageElement(enterPage);
-
- enterPage.updateBackButton(pageLength > (options._replacePage ? 2 : 1));
-
- enterPage.pushedOptions = util.extend({}, enterPage.pushedOptions || {}, options || {});
- enterPage.data = util.extend({}, enterPage.data || {}, options.data || {});
- enterPage.unload = enterPage.unload || options.unload;
-
- return new _Promise(function (resolve) {
- var done = function done() {
- _this6._isRunning = false;
-
- options.show !== false && _setImmediate(function () {
- return enterPage._show();
- });
- util.triggerElementEvent(_this6, 'postpush', { leavePage: leavePage, enterPage: enterPage, navigator: _this6 });
-
- if (leavePage) {
- leavePage.style.display = 'none';
- }
-
- options.callback && options.callback(enterPage);
-
- resolve(enterPage);
- };
-
- enterPage.style.visibility = '';
- if (leavePage) {
- leavePage._hide();
- animator.push(enterPage, leavePage, done);
- } else {
- done();
- }
- });
- }).catch(function (error) {
- _this6._isRunning = false;
- throw error;
- });
- }
-
-
-
-
- }, {
- key: 'replacePage',
- value: function replacePage(page) {
- var _this7 = this;
-
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
-
- return this.pushPage(page, options).then(function (resolvedValue) {
- if (_this7.pages.length > 1) {
- _this7._pageLoader.unload(_this7.pages[_this7.pages.length - 2]);
- }
- _this7._updateLastPageBackButton();
-
- return _Promise.resolve(resolvedValue);
- });
- }
-
-
-
-
- }, {
- key: 'insertPage',
- value: function insertPage(index, page) {
- var _this8 = this;
-
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
-
- var _preparePageAndOption3 = this._preparePageAndOptions(page, options);
-
- page = _preparePageAndOption3.page;
- options = _preparePageAndOption3.options;
-
- index = this._normalizeIndex(index);
-
- if (index >= this.pages.length) {
- return this.pushPage(page, options);
- }
-
- page = typeof options.pageHTML === 'string' ? options.pageHTML : page;
- var loader = typeof options.pageHTML === 'string' ? instantPageLoader : this._pageLoader;
-
- return new _Promise(function (resolve) {
- loader.load({ page: page, parent: _this8 }, function (pageElement) {
- verifyPageElement(pageElement);
- _this8._pageMap.set(pageElement, page);
- pageElement = util.extend(pageElement, {
- data: options.data,
- pushedOptions: options
- });
-
- options.animationOptions = util.extend({}, AnimatorFactory.parseAnimationOptionsString(_this8.getAttribute('animation-options')), options.animationOptions || {});
-
- pageElement.style.display = 'none';
- _this8.insertBefore(pageElement, _this8.pages[index]);
- _this8.topPage.updateBackButton(true);
-
- setTimeout(function () {
- pageElement = null;
- resolve(_this8.pages[index]);
- }, 1000 / 60);
- });
- });
- }
-
-
-
-
- }, {
- key: 'removePage',
- value: function removePage(index) {
- var _this9 = this;
-
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
-
- index = this._normalizeIndex(index);
-
- if (index < this.pages.length - 1) {
- return new _Promise(function (resolve) {
- var leavePage = _this9.pages[index];
- var enterPage = _this9.topPage;
-
- _this9._pageMap.delete(leavePage);
- _this9._pageLoader.unload(leavePage);
- if (_this9.pages.length === 1) {
-
- _this9.topPage.updateBackButton(false);
- }
-
- resolve(enterPage);
- });
- } else {
- return this.popPage(options);
- }
- }
-
-
-
-
- }, {
- key: 'resetToPage',
- value: function resetToPage(page) {
- var _this10 = this;
-
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
-
- var _preparePageAndOption4 = this._preparePageAndOptions(page, options);
-
- page = _preparePageAndOption4.page;
- options = _preparePageAndOption4.options;
-
-
- if (!options.animator && !options.animation && !options.pop) {
- options.animation = 'none';
- }
-
- if (!options.page && !options.pageHTML && this._getPageTarget()) {
- page = options.page = this._getPageTarget();
- }
-
- if (options.pop) {
- this._removePages();
- return this.insertPage(0, page, { data: options.data }).then(function () {
- return _this10.popPage(options);
- });
- }
-
-
- var callback = options.callback;
- options.callback = function (newPage) {
- _this10._removePages();
- newPage.updateBackButton(false);
- callback && callback(newPage);
- };
-
- return this.pushPage(page, options);
- }
-
-
-
-
- }, {
- key: 'bringPageTop',
- value: function bringPageTop(item) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
-
- if (['number', 'string'].indexOf(typeof item === 'undefined' ? 'undefined' : _typeof(item)) === -1) {
- util.throw('First argument must be a page name or the index of an existing page. You supplied ' + item);
- }
- var index = typeof item === 'number' ? this._normalizeIndex(item) : this._lastIndexOfPage(item);
- var page = this.pages[index];
-
- if (index < 0) {
- return this.pushPage(item, options);
- }
-
- var _preparePageAndOption5 = this._preparePageAndOptions(page, options);
-
- options = _preparePageAndOption5.options;
-
-
- if (index === this.pages.length - 1) {
- return _Promise.resolve(page);
- }
- if (!page) {
- util.throw('Failed to find item ' + item);
- }
- if (this._isRunning) {
- return _Promise.reject('pushPage is already running.');
- }
- if (this._emitPrePushEvent()) {
- return _Promise.reject('Canceled in prepush event.');
- }
-
- page.style.display = '';
- page.style.visibility = 'hidden';
- page.parentNode.appendChild(page);
- return this._pushPage(options);
- }
- }, {
- key: '_preparePageAndOptions',
- value: function _preparePageAndOptions(page) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
-
- if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) != 'object') {
- util.throw('options must be an object. You supplied ' + options);
- }
-
- if ((page === null || page === undefined) && options.page) {
- page = options.page;
- }
-
- options = util.extend({}, this.options || {}, options, { page: page });
-
- return { page: page, options: options };
- }
- }, {
- key: '_removePages',
- value: function _removePages(times) {
- var pages = this.pages;
- var until = times === undefined ? 0 : pages.length - times;
- until = until < 0 ? 1 : until;
-
- for (var i = pages.length - 2; i >= until; i--) {
- this._pageMap.delete(pages[i]);
- this._pageLoader.unload(pages[i]);
- }
- }
- }, {
- key: '_updateLastPageBackButton',
- value: function _updateLastPageBackButton() {
- var index = this.pages.length - 1;
- if (index >= 0) {
- this.pages[index].updateBackButton(index > 0);
- }
- }
- }, {
- key: '_normalizeIndex',
- value: function _normalizeIndex(index) {
- return index >= 0 ? index : Math.abs(this.pages.length + index) % this.pages.length;
- }
- }, {
- key: '_onDeviceBackButton',
- value: function _onDeviceBackButton(event) {
- if (this.pages.length > 1) {
- this.popPage();
- } else {
- event.callParentHandler();
- }
- }
- }, {
- key: '_lastIndexOfPage',
- value: function _lastIndexOfPage(pageName) {
- var index = void 0;
- for (index = this.pages.length - 1; index >= 0; index--) {
- if (pageName === this._pageMap.get(this.pages[index])) {
- break;
- }
- }
- return index;
- }
- }, {
- key: '_emitPreEvent',
- value: function _emitPreEvent(name) {
- var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
-
- var isCanceled = false;
-
- util.triggerElementEvent(this, 'pre' + name, util.extend({
- navigator: this,
- currentPage: this.pages[this.pages.length - 1],
- cancel: function cancel() {
- return isCanceled = true;
- }
- }, data));
-
- return isCanceled;
- }
- }, {
- key: '_emitPrePushEvent',
- value: function _emitPrePushEvent() {
- return this._emitPreEvent('push');
- }
- }, {
- key: '_emitPrePopEvent',
- value: function _emitPrePopEvent() {
- var l = this.pages.length;
- return this._emitPreEvent('pop', {
- leavePage: this.pages[l - 1],
- enterPage: this.pages[l - 2]
- });
- }
-
-
-
- }, {
- key: '_createPageElement',
- value: function _createPageElement(templateHTML) {
- var pageElement = util.createElement(internal.normalizePageHTML(templateHTML));
- verifyPageElement(pageElement);
- return pageElement;
- }
-
-
-
-
- }, {
- key: '_show',
- value: function _show() {
- var _this11 = this;
-
- this.loaded.then(function () {
- return _this11.topPage && _this11.topPage._show();
- });
- }
- }, {
- key: '_hide',
- value: function _hide() {
- this.topPage && this.topPage._hide();
- }
- }, {
- key: '_destroy',
- value: function _destroy() {
- for (var i = this.pages.length - 1; i >= 0; i--) {
- this._pageLoader.unload(this.pages[i]);
- }
-
- this.remove();
- }
-
-
-
-
- }, {
- key: 'pageLoader',
- get: function get() {
- return this._pageLoader;
- },
- set: function set(pageLoader) {
- if (!(pageLoader instanceof PageLoader)) {
- util.throwPageLoader();
- }
- this._pageLoader = pageLoader;
- }
- }, {
- key: 'page',
- get: function get() {
- return this._page;
- },
- set: function set(page) {
- this._page = page;
- }
- }, {
- key: 'onDeviceBackButton',
- get: function get() {
- return this._backButtonHandler;
- },
- set: function set(callback) {
- if (this._backButtonHandler) {
- this._backButtonHandler.destroy();
- }
-
- this._backButtonHandler = deviceBackButtonDispatcher.createHandler(this, callback);
- }
-
-
-
-
- }, {
- key: 'topPage',
- get: function get() {
- var last = this.lastElementChild;
- while (last && last.tagName !== 'ONS-PAGE') {
- last = last.previousElementSibling;
- }
- return last;
- }
-
-
-
-
- }, {
- key: 'pages',
- get: function get() {
- return util.arrayFrom(this.children).filter(function (element) {
- return element.tagName === 'ONS-PAGE';
- });
- }
-
-
-
-
- }, {
- key: 'onSwipe',
- get: function get() {
- return this._onSwipe;
- },
- set: function set(value) {
- if (value && !(value instanceof Function)) {
- util.throw('"onSwipe" must be a function');
- }
- this._onSwipe = value;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- }, {
- key: 'options',
- get: function get() {
- return this._options;
- },
- set: function set(object) {
- this._options = object;
- }
- }, {
- key: '_isRunning',
- set: function set(value) {
- this.setAttribute('_is-running', value ? 'true' : 'false');
- },
- get: function get() {
- return JSON.parse(this.getAttribute('_is-running'));
- }
- }], [{
- key: 'registerAnimator',
- value: function registerAnimator(name, Animator) {
- if (!(Animator.prototype instanceof NavigatorAnimator)) {
- util.throwAnimator('Navigator');
- }
-
- _animatorDict[name] = Animator;
- }
- }, {
- key: 'observedAttributes',
- get: function get() {
- return ['animation', 'swipeable'];
- }
- }, {
- key: 'animators',
- get: function get() {
- return _animatorDict;
- }
- }, {
- key: 'NavigatorAnimator',
- get: function get() {
- return NavigatorAnimator;
- }
- }, {
- key: 'events',
- get: function get() {
- return ['prepush', 'postpush', 'prepop', 'postpop'];
- }
- }, {
- key: 'rewritables',
- get: function get() {
- return rewritables;
- }
- }]);
-
- return NavigatorElement;
- }(BaseElement);
-
- export default NavigatorElement;
-
-
- onsElements.Navigator = NavigatorElement;
- customElements.define('ons-navigator', NavigatorElement);
|