import _toConsumableArray from 'babel-runtime/helpers/toConsumableArray'; 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 _get from 'babel-runtime/helpers/get'; import _inherits from 'babel-runtime/helpers/inherits'; /* 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. */ import onsElements from '../ons/elements'; import util from '../ons/util'; import autoStyle from '../ons/autostyle'; import ModifierUtil from '../ons/internal/modifier-util'; import BaseCheckboxElement from './base/base-checkbox'; import contentReady from '../ons/content-ready'; import GestureDetector from '../ons/gesture-detector'; var scheme = { '': 'switch--*', '.switch__input': 'switch--*__input', '.switch__handle': 'switch--*__handle', '.switch__toggle': 'switch--*__toggle' }; var locations = { ios: [1, 21], material: [0, 16] }; /** * @element ons-switch * @category form * @description * [en] * Switch component. The switch can be toggled both by dragging and tapping. * * Will automatically displays a Material Design switch on Android devices. * [/en] * [ja]スイッチを表示するコンポーネントです。[/ja] * @modifier material * [en]Material Design switch[/en] * [ja][/ja] * @codepen LpXZQQ * @tutorial vanilla/Reference/switch * @guide theming.html#modifiers [en]More details about the `modifier` attribute[/en][ja]modifier属性の使い方[/ja] * @example * * * */ var SwitchElement = function (_BaseCheckboxElement) { _inherits(SwitchElement, _BaseCheckboxElement); function SwitchElement() { _classCallCheck(this, SwitchElement); var _this = _possibleConstructorReturn(this, (SwitchElement.__proto__ || _Object$getPrototypeOf(SwitchElement)).call(this)); contentReady(_this, function () { _this.attributeChangedCallback('modifier', null, _this.getAttribute('modifier')); }); _this._onChange = _this._onChange.bind(_this); _this._onRelease = _this._onRelease.bind(_this); _this._lastTimeStamp = 0; return _this; } _createClass(SwitchElement, [{ key: '_getPosition', /* Own props */ value: function _getPosition(e) { var l = this._locations; return Math.min(l[1], Math.max(l[0], this._startX + e.gesture.deltaX)); } }, { key: '_emitChangeEvent', value: function _emitChangeEvent() { util.triggerElementEvent(this, 'change', { value: this.checked, switch: this, isInteractive: true }); } }, { key: '_onChange', value: function _onChange(event) { if (event && event.stopPropagation) { event.stopPropagation(); } this._emitChangeEvent(); } }, { key: '_onClick', value: function _onClick(ev) { if (ev.target.classList.contains(this.defaultElementClass + '__touch') || ev.timeStamp - this._lastTimeStamp < 50 // Prevent second click triggered by