123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- 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 ModifierUtil from '../../ons/internal/modifier-util';
- import AnimatorFactory from '../../ons/internal/animator-factory';
- import OverlaySplitterAnimator from './overlay-animator';
- import PushSplitterAnimator from './push-animator';
- import RevealSplitterAnimator from './reveal-animator';
- import BaseElement from '../base/base-element';
- import deviceBackButtonDispatcher from '../../ons/internal/device-back-button-dispatcher';
- import contentReady from '../../ons/content-ready';
-
- var _animatorDict = {
- default: OverlaySplitterAnimator,
- overlay: OverlaySplitterAnimator,
- push: PushSplitterAnimator,
- reveal: RevealSplitterAnimator
- };
-
-
-
- var SplitterElement = function (_BaseElement) {
- _inherits(SplitterElement, _BaseElement);
-
- _createClass(SplitterElement, [{
- key: '_getSide',
- value: function _getSide(side) {
- var element = util.findChild(this, function (e) {
- return util.match(e, 'ons-splitter-side') && e.getAttribute('side') === side;
- });
- return element;
- }
-
-
-
-
- }, {
- key: '_onDeviceBackButton',
- value: function _onDeviceBackButton(event) {
- this._sides.some(function (s) {
- return s.isOpen ? s.close() : false;
- }) || event.callParentHandler();
- }
- }, {
- key: '_onModeChange',
- value: function _onModeChange(e) {
- var _this2 = this;
-
- if (e.target.parentNode) {
- contentReady(this, function () {
- _this2._layout();
- });
- }
- }
- }, {
- key: '_layout',
- value: function _layout() {
- var _this3 = this;
-
- this._sides.forEach(function (side) {
- if (_this3.content) {
- _this3.content.style[side.side] = side.mode === 'split' ? side.style.width : 0;
- }
- });
- }
- }, {
- key: 'left',
- get: function get() {
- return this._getSide('left');
- }
-
-
-
- }, {
- key: 'right',
- get: function get() {
- return this._getSide('right');
- }
-
-
-
-
- }, {
- key: 'side',
- get: function get() {
- return util.findChild(this, 'ons-splitter-side');
- }
- }, {
- key: '_sides',
- get: function get() {
- return [this.left, this.right].filter(function (e) {
- return e;
- });
- }
-
-
-
- }, {
- key: 'content',
- get: function get() {
- return util.findChild(this, 'ons-splitter-content');
- }
- }, {
- key: 'topPage',
- get: function get() {
- return this.content._content;
- }
- }, {
- key: 'mask',
- get: function get() {
- return util.findChild(this, 'ons-splitter-mask');
- }
-
-
-
-
- }, {
- key: 'onDeviceBackButton',
- get: function get() {
- return this._backButtonHandler;
- },
- set: function set(callback) {
- if (this._backButtonHandler) {
- this._backButtonHandler.destroy();
- }
-
- this._backButtonHandler = deviceBackButtonDispatcher.createHandler(this, callback);
- }
- }]);
-
- function SplitterElement() {
- _classCallCheck(this, SplitterElement);
-
- var _this = _possibleConstructorReturn(this, (SplitterElement.__proto__ || _Object$getPrototypeOf(SplitterElement)).call(this));
-
- _this._onModeChange = _this._onModeChange.bind(_this);
-
- contentReady(_this, function () {
- !_this.mask && _this.appendChild(document.createElement('ons-splitter-mask'));
- _this._layout();
- });
- return _this;
- }
-
- _createClass(SplitterElement, [{
- key: 'connectedCallback',
- value: function connectedCallback() {
- this.onDeviceBackButton = this._onDeviceBackButton.bind(this);
- this.addEventListener('modechange', this._onModeChange, false);
- }
- }, {
- key: 'disconnectedCallback',
- value: function disconnectedCallback() {
- this._backButtonHandler.destroy();
- this._backButtonHandler = null;
- this.removeEventListener('modechange', this._onModeChange, false);
- }
- }, {
- key: 'attributeChangedCallback',
- value: function attributeChangedCallback(name, last, current) {}
- }, {
- key: '_show',
- value: function _show() {
- util.propagateAction(this, '_show');
- }
- }, {
- key: '_hide',
- value: function _hide() {
- util.propagateAction(this, '_hide');
- }
- }, {
- key: '_destroy',
- value: function _destroy() {
- util.propagateAction(this, '_destroy');
- this.remove();
- }
- }], [{
- key: 'registerAnimator',
- value: function registerAnimator(name, Animator) {
- if (!(Animator instanceof SplitterAnimator)) {
- util.throwAnimator('Splitter');
- }
- _animatorDict[name] = Animator;
- }
- }, {
- key: 'SplitterAnimator',
- get: function get() {
- return SplitterAnimator;
- }
- }, {
- key: 'animators',
- get: function get() {
- return _animatorDict;
- }
- }]);
-
- return SplitterElement;
- }(BaseElement);
-
- export default SplitterElement;
-
-
- onsElements.Splitter = SplitterElement;
- customElements.define('ons-splitter', SplitterElement);
|