1 | import { Directive, ElementRef, HostBinding, forwardRef, HostListener, Input } from '@angular/core';
|
2 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
3 | export var RADIO_CONTROL_VALUE_ACCESSOR = {
|
4 | provide: NG_VALUE_ACCESSOR,
|
5 | useExisting: forwardRef(function () { return ButtonRadioDirective; }),
|
6 | multi: true
|
7 | };
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export var ButtonRadioDirective = (function () {
|
13 | function ButtonRadioDirective(el) {
|
14 | this.onChange = Function.prototype;
|
15 | this.onTouched = Function.prototype;
|
16 | this.el = el;
|
17 | }
|
18 | Object.defineProperty(ButtonRadioDirective.prototype, "isActive", {
|
19 | get: function () {
|
20 | return this.btnRadio === this.value;
|
21 | },
|
22 | enumerable: true,
|
23 | configurable: true
|
24 | });
|
25 | ButtonRadioDirective.prototype.onClick = function () {
|
26 | if (this.el.nativeElement.attributes.disabled) {
|
27 | return;
|
28 | }
|
29 | if (this.uncheckable && this.btnRadio === this.value) {
|
30 | this.value = undefined;
|
31 | }
|
32 | else {
|
33 | this.value = this.btnRadio;
|
34 | }
|
35 | this.onTouched();
|
36 | this.onChange(this.value);
|
37 | };
|
38 | ButtonRadioDirective.prototype.ngOnInit = function () {
|
39 | this.uncheckable = typeof this.uncheckable !== 'undefined';
|
40 | };
|
41 | ButtonRadioDirective.prototype.onBlur = function () {
|
42 | this.onTouched();
|
43 | };
|
44 |
|
45 |
|
46 | ButtonRadioDirective.prototype.writeValue = function (value) {
|
47 | this.value = value;
|
48 | };
|
49 | ButtonRadioDirective.prototype.registerOnChange = function (fn) {
|
50 | this.onChange = fn;
|
51 | };
|
52 | ButtonRadioDirective.prototype.registerOnTouched = function (fn) {
|
53 | this.onTouched = fn;
|
54 | };
|
55 | ButtonRadioDirective.decorators = [
|
56 | { type: Directive, args: [{ selector: '[btnRadio]', providers: [RADIO_CONTROL_VALUE_ACCESSOR] },] },
|
57 | ];
|
58 |
|
59 | ButtonRadioDirective.ctorParameters = function () { return [
|
60 | { type: ElementRef, },
|
61 | ]; };
|
62 | ButtonRadioDirective.propDecorators = {
|
63 | 'btnRadio': [{ type: Input },],
|
64 | 'uncheckable': [{ type: Input },],
|
65 | 'value': [{ type: Input },],
|
66 | 'isActive': [{ type: HostBinding, args: ['class.active',] },],
|
67 | 'onClick': [{ type: HostListener, args: ['click',] },],
|
68 | };
|
69 | return ButtonRadioDirective;
|
70 | }());
|
71 |
|
\ | No newline at end of file |