123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
- import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
- import _createClass from 'babel-runtime/helpers/createClass';
- import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
- import _inherits from 'babel-runtime/helpers/inherits';
-
-
- import onsElements from '../ons/elements';
- import orientation from '../ons/orientation';
- import platform from '../ons/platform';
- import BaseElement from './base/base-element';
- import contentReady from '../ons/content-ready';
-
-
-
- var IfElement = function (_BaseElement) {
- _inherits(IfElement, _BaseElement);
-
-
-
-
-
-
-
- function IfElement() {
- _classCallCheck(this, IfElement);
-
- var _this = _possibleConstructorReturn(this, (IfElement.__proto__ || _Object$getPrototypeOf(IfElement)).call(this));
-
- contentReady(_this, function () {
- if (platform._getSelectedPlatform() !== null) {
- _this._platformUpdate();
- } else if (!_this._isAllowedPlatform()) {
- while (_this.childNodes[0]) {
- _this.childNodes[0].remove();
- }
- _this._platformUpdate();
- }
- });
-
- _this._onOrientationChange();
- return _this;
- }
-
- _createClass(IfElement, [{
- key: 'connectedCallback',
- value: function connectedCallback() {
- orientation.on('change', this._onOrientationChange.bind(this));
- }
- }, {
- key: 'attributeChangedCallback',
- value: function attributeChangedCallback(name) {
- if (name === 'orientation') {
- this._onOrientationChange();
- }
- }
- }, {
- key: 'disconnectedCallback',
- value: function disconnectedCallback() {
- orientation.off('change', this._onOrientationChange);
- }
- }, {
- key: '_platformUpdate',
- value: function _platformUpdate() {
- this.style.display = this._isAllowedPlatform() ? '' : 'none';
- }
- }, {
- key: '_isAllowedPlatform',
- value: function _isAllowedPlatform() {
- return !this.getAttribute('platform') || this.getAttribute('platform').split(/\s+/).indexOf(platform.getMobileOS()) >= 0;
- }
- }, {
- key: '_onOrientationChange',
- value: function _onOrientationChange() {
- if (this.hasAttribute('orientation') && this._isAllowedPlatform()) {
- var conditionalOrientation = this.getAttribute('orientation').toLowerCase();
- var currentOrientation = orientation.isPortrait() ? 'portrait' : 'landscape';
-
- this.style.display = conditionalOrientation === currentOrientation ? '' : 'none';
- }
- }
- }], [{
- key: 'observedAttributes',
- get: function get() {
- return ['orientation'];
- }
- }]);
-
- return IfElement;
- }(BaseElement);
-
- export default IfElement;
-
-
- onsElements.If = IfElement;
- customElements.define('ons-if', IfElement);
|