| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- (function (factory) {
- if (typeof module === "object" && typeof module.exports === "object") {
- var v = factory(require, exports);
- if (v !== undefined) module.exports = v;
- }
- else if (typeof define === "function" && define.amd) {
- define(["require", "exports", "@angular/core", "@angular/forms", "../../config/config", "../../platform/dom-controller", "../../util/form", "../../gestures/gesture-controller", "../../tap-click/haptic", "../../util/util", "../../util/base-input", "../item/item", "../../platform/key", "../../platform/platform", "./toggle-gesture"], factory);
- }
- })(function (require, exports) {
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var core_1 = require("@angular/core");
- var forms_1 = require("@angular/forms");
- var config_1 = require("../../config/config");
- var dom_controller_1 = require("../../platform/dom-controller");
- var form_1 = require("../../util/form");
- var gesture_controller_1 = require("../../gestures/gesture-controller");
- var haptic_1 = require("../../tap-click/haptic");
- var util_1 = require("../../util/util");
- var base_input_1 = require("../../util/base-input");
- var item_1 = require("../item/item");
- var key_1 = require("../../platform/key");
- var platform_1 = require("../../platform/platform");
- var toggle_gesture_1 = require("./toggle-gesture");
- /**
- * @name Toggle
- * @description
- * A toggle technically is the same thing as an HTML checkbox input,
- * except it looks different and is easier to use on a touch device.
- * Toggles can also have colors assigned to them, by adding any color
- * attribute.
- *
- * See the [Angular Docs](https://angular.io/docs/ts/latest/guide/forms.html)
- * for more info on forms and inputs.
- *
- * @usage
- * ```html
- *
- * <ion-list>
- *
- * <ion-item>
- * <ion-label>Pepperoni</ion-label>
- * <ion-toggle [(ngModel)]="pepperoni"></ion-toggle>
- * </ion-item>
- *
- * <ion-item>
- * <ion-label>Sausage</ion-label>
- * <ion-toggle [(ngModel)]="sausage" disabled="true"></ion-toggle>
- * </ion-item>
- *
- * <ion-item>
- * <ion-label>Mushrooms</ion-label>
- * <ion-toggle [(ngModel)]="mushrooms"></ion-toggle>
- * </ion-item>
- *
- * </ion-list>
- * ```
- *
- * @demo /docs/demos/src/toggle/
- * @see {@link /docs/components#toggle Toggle Component Docs}
- */
- var Toggle = (function (_super) {
- __extends(Toggle, _super);
- function Toggle(form, config, _plt, elementRef, renderer, _haptic, item, _gestureCtrl, _domCtrl, _zone) {
- var _this = _super.call(this, config, elementRef, renderer, 'toggle', false, form, item, null) || this;
- _this._plt = _plt;
- _this._haptic = _haptic;
- _this._gestureCtrl = _gestureCtrl;
- _this._domCtrl = _domCtrl;
- _this._zone = _zone;
- _this._activated = false;
- return _this;
- }
- Object.defineProperty(Toggle.prototype, "checked", {
- /**
- * @input {boolean} If true, the element is selected.
- */
- get: function () {
- return this.value;
- },
- set: function (val) {
- this.value = val;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @hidden
- */
- Toggle.prototype.ngAfterContentInit = function () {
- this._initialize();
- this._gesture = new toggle_gesture_1.ToggleGesture(this._plt, this, this._gestureCtrl, this._domCtrl);
- this._gesture.listen();
- };
- /**
- * @hidden
- */
- Toggle.prototype._inputUpdated = function () { };
- /**
- * @hidden
- */
- Toggle.prototype._inputNormalize = function (val) {
- return util_1.isTrueProperty(val);
- };
- /**
- * @hidden
- */
- Toggle.prototype._onDragStart = function (startX) {
- var _this = this;
- (void 0) /* assert */;
- (void 0) /* console.debug */;
- this._zone.run(function () {
- _this._startX = startX;
- _this._fireFocus();
- _this._activated = true;
- });
- };
- /**
- * @hidden
- */
- Toggle.prototype._onDragMove = function (currentX) {
- var _this = this;
- if (!this._startX) {
- (void 0) /* assert */;
- return;
- }
- if (this._shouldToggle(currentX, -15)) {
- this._zone.run(function () {
- _this.value = !_this.value;
- _this._startX = currentX;
- _this._haptic.selection();
- });
- }
- };
- /**
- * @hidden
- */
- Toggle.prototype._onDragEnd = function (endX) {
- var _this = this;
- if (!this._startX) {
- (void 0) /* assert */;
- return;
- }
- (void 0) /* console.debug */;
- this._zone.run(function () {
- if (_this._shouldToggle(endX, 4)) {
- _this.value = !_this.value;
- _this._haptic.selection();
- }
- _this._activated = false;
- _this._fireBlur();
- _this._startX = null;
- });
- };
- /**
- * @hidden
- */
- Toggle.prototype._shouldToggle = function (currentX, margin) {
- var isLTR = !this._plt.isRTL;
- var startX = this._startX;
- if (this._value) {
- return (isLTR && (startX + margin > currentX)) ||
- (!isLTR && (startX - margin < currentX));
- }
- else {
- return (isLTR && (startX - margin < currentX)) ||
- (!isLTR && (startX + margin > currentX));
- }
- };
- /**
- * @hidden
- */
- Toggle.prototype._keyup = function (ev) {
- if (ev.keyCode === key_1.KEY_SPACE || ev.keyCode === key_1.KEY_ENTER) {
- (void 0) /* console.debug */;
- ev.preventDefault();
- ev.stopPropagation();
- this.value = !this.value;
- }
- };
- /**
- * @hidden
- */
- Toggle.prototype.ngOnDestroy = function () {
- _super.prototype.ngOnDestroy.call(this);
- this._gesture && this._gesture.destroy();
- };
- Toggle.decorators = [
- { type: core_1.Component, args: [{
- selector: 'ion-toggle',
- template: '<div class="toggle-icon">' +
- '<div class="toggle-inner"></div>' +
- '</div>' +
- '<button role="checkbox" ' +
- 'type="button" ' +
- 'ion-button="item-cover" ' +
- '[id]="id" ' +
- '[attr.aria-checked]="_value" ' +
- '[attr.aria-labelledby]="_labelId" ' +
- '[attr.aria-disabled]="_disabled" ' +
- 'class="item-cover" disable-activated>' +
- '</button>',
- host: {
- '[class.toggle-disabled]': '_disabled',
- '[class.toggle-checked]': '_value',
- '[class.toggle-activated]': '_activated',
- },
- providers: [{ provide: forms_1.NG_VALUE_ACCESSOR, useExisting: Toggle, multi: true }],
- encapsulation: core_1.ViewEncapsulation.None,
- },] },
- ];
- /** @nocollapse */
- Toggle.ctorParameters = function () { return [
- { type: form_1.Form, },
- { type: config_1.Config, },
- { type: platform_1.Platform, },
- { type: core_1.ElementRef, },
- { type: core_1.Renderer, },
- { type: haptic_1.Haptic, },
- { type: item_1.Item, decorators: [{ type: core_1.Optional },] },
- { type: gesture_controller_1.GestureController, },
- { type: dom_controller_1.DomController, },
- { type: core_1.NgZone, },
- ]; };
- Toggle.propDecorators = {
- 'checked': [{ type: core_1.Input },],
- '_keyup': [{ type: core_1.HostListener, args: ['keyup', ['$event'],] },],
- };
- return Toggle;
- }(base_input_1.BaseInput));
- exports.Toggle = Toggle;
- });
- //# sourceMappingURL=toggle.js.map
|