1 | var __extends = (this && this.__extends) || function (d, b) {
|
2 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
3 | function __() { this.constructor = d; }
|
4 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
5 | };
|
6 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
7 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
8 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
9 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
10 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
11 | };
|
12 | var __metadata = (this && this.__metadata) || function (k, v) {
|
13 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
14 | };
|
15 | import { NgModule, ChangeDetectionStrategy, Component, ElementRef, Input, Renderer, ViewEncapsulation } from '@angular/core';
|
16 | import { HttpModule } from '@angular/http';
|
17 | import { MdError } from '@angular2-material/core';
|
18 | import { MdIconRegistry } from './icon-registry';
|
19 | export { MdIconRegistry } from './icon-registry';
|
20 |
|
21 | export var MdIconInvalidNameError = (function (_super) {
|
22 | __extends(MdIconInvalidNameError, _super);
|
23 | function MdIconInvalidNameError(iconName) {
|
24 | _super.call(this, "Invalid icon name: \"" + iconName + "\"");
|
25 | }
|
26 | return MdIconInvalidNameError;
|
27 | }(MdError));
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | export var MdIcon = (function () {
|
62 | function MdIcon(_element, _renderer, _mdIconRegistry) {
|
63 | this._element = _element;
|
64 | this._renderer = _renderer;
|
65 | this._mdIconRegistry = _mdIconRegistry;
|
66 | this.hostAriaLabel = '';
|
67 | }
|
68 | |
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | MdIcon.prototype._splitIconName = function (iconName) {
|
82 | if (!iconName) {
|
83 | return ['', ''];
|
84 | }
|
85 | var parts = iconName.split(':');
|
86 | switch (parts.length) {
|
87 | case 1:
|
88 |
|
89 | return ['', parts[0]];
|
90 | case 2:
|
91 | return parts;
|
92 | default:
|
93 | throw new MdIconInvalidNameError(iconName);
|
94 | }
|
95 | };
|
96 |
|
97 | MdIcon.prototype.ngOnChanges = function (changes) {
|
98 | var _this = this;
|
99 | var changedInputs = Object.keys(changes);
|
100 |
|
101 | if (changedInputs.indexOf('svgIcon') != -1 || changedInputs.indexOf('svgSrc') != -1) {
|
102 | if (this.svgIcon) {
|
103 | var _a = this._splitIconName(this.svgIcon), namespace = _a[0], iconName = _a[1];
|
104 | this._mdIconRegistry.getNamedSvgIcon(iconName, namespace).subscribe(function (svg) { return _this._setSvgElement(svg); }, function (err) { return console.log("Error retrieving icon: " + err); });
|
105 | }
|
106 | else if (this.svgSrc) {
|
107 | this._mdIconRegistry.getSvgIconFromUrl(this.svgSrc).subscribe(function (svg) { return _this._setSvgElement(svg); }, function (err) { return console.log("Error retrieving icon: " + err); });
|
108 | }
|
109 | }
|
110 | if (this._usingFontIcon()) {
|
111 | this._updateFontIconClasses();
|
112 | }
|
113 | this._updateAriaLabel();
|
114 | };
|
115 |
|
116 | MdIcon.prototype.ngOnInit = function () {
|
117 |
|
118 |
|
119 | if (this._usingFontIcon()) {
|
120 | this._updateFontIconClasses();
|
121 | }
|
122 | };
|
123 |
|
124 | MdIcon.prototype.ngAfterViewChecked = function () {
|
125 |
|
126 |
|
127 | this._updateAriaLabel();
|
128 | };
|
129 | MdIcon.prototype._updateAriaLabel = function () {
|
130 | var ariaLabel = this._getAriaLabel();
|
131 | if (ariaLabel) {
|
132 | this._renderer.setElementAttribute(this._element.nativeElement, 'aria-label', ariaLabel);
|
133 | }
|
134 | };
|
135 | MdIcon.prototype._getAriaLabel = function () {
|
136 |
|
137 |
|
138 |
|
139 | var label = this.hostAriaLabel ||
|
140 | this.alt ||
|
141 | this.fontIcon ||
|
142 | this._splitIconName(this.svgIcon)[1];
|
143 | if (label) {
|
144 | return label;
|
145 | }
|
146 |
|
147 | if (this._usingFontIcon()) {
|
148 | var text = this._element.nativeElement.textContent;
|
149 | if (text) {
|
150 | return text;
|
151 | }
|
152 | }
|
153 |
|
154 | return null;
|
155 | };
|
156 | MdIcon.prototype._usingFontIcon = function () {
|
157 | return !(this.svgIcon || this.svgSrc);
|
158 | };
|
159 | MdIcon.prototype._setSvgElement = function (svg) {
|
160 | var layoutElement = this._element.nativeElement;
|
161 |
|
162 |
|
163 |
|
164 | layoutElement.innerHTML = '';
|
165 | this._renderer.projectNodes(layoutElement, [svg]);
|
166 | };
|
167 | MdIcon.prototype._updateFontIconClasses = function () {
|
168 | if (!this._usingFontIcon()) {
|
169 | return;
|
170 | }
|
171 | var elem = this._element.nativeElement;
|
172 | var fontSetClass = this.fontSet ?
|
173 | this._mdIconRegistry.classNameForFontAlias(this.fontSet) :
|
174 | this._mdIconRegistry.getDefaultFontSetClass();
|
175 | if (fontSetClass != this._previousFontSetClass) {
|
176 | if (this._previousFontSetClass) {
|
177 | this._renderer.setElementClass(elem, this._previousFontSetClass, false);
|
178 | }
|
179 | if (fontSetClass) {
|
180 | this._renderer.setElementClass(elem, fontSetClass, true);
|
181 | }
|
182 | this._previousFontSetClass = fontSetClass;
|
183 | }
|
184 | if (this.fontIcon != this._previousFontIconClass) {
|
185 | if (this._previousFontIconClass) {
|
186 | this._renderer.setElementClass(elem, this._previousFontIconClass, false);
|
187 | }
|
188 | if (this.fontIcon) {
|
189 | this._renderer.setElementClass(elem, this.fontIcon, true);
|
190 | }
|
191 | this._previousFontIconClass = this.fontIcon;
|
192 | }
|
193 | };
|
194 | __decorate([
|
195 | Input(),
|
196 | __metadata('design:type', String)
|
197 | ], MdIcon.prototype, "svgSrc", void 0);
|
198 | __decorate([
|
199 | Input(),
|
200 | __metadata('design:type', String)
|
201 | ], MdIcon.prototype, "svgIcon", void 0);
|
202 | __decorate([
|
203 | Input(),
|
204 | __metadata('design:type', String)
|
205 | ], MdIcon.prototype, "fontSet", void 0);
|
206 | __decorate([
|
207 | Input(),
|
208 | __metadata('design:type', String)
|
209 | ], MdIcon.prototype, "fontIcon", void 0);
|
210 | __decorate([
|
211 | Input(),
|
212 | __metadata('design:type', String)
|
213 | ], MdIcon.prototype, "alt", void 0);
|
214 | __decorate([
|
215 | Input('aria-label'),
|
216 | __metadata('design:type', String)
|
217 | ], MdIcon.prototype, "hostAriaLabel", void 0);
|
218 | MdIcon = __decorate([
|
219 | Component({template: '<ng-content></ng-content>',
|
220 | selector: 'md-icon',
|
221 | styles: ["/** The width/height of the icon element. */ /** This works because we're using ViewEncapsulation.None. If we used the default encapsulation, the selector would need to be \":host\". */ md-icon { background-repeat: no-repeat; display: inline-block; fill: currentColor; height: 24px; width: 24px; } /*# sourceMappingURL=icon.css.map */ "],
|
222 | host: {
|
223 | 'role': 'img',
|
224 | },
|
225 | encapsulation: ViewEncapsulation.None,
|
226 | changeDetection: ChangeDetectionStrategy.OnPush,
|
227 | }),
|
228 | __metadata('design:paramtypes', [ElementRef, Renderer, MdIconRegistry])
|
229 | ], MdIcon);
|
230 | return MdIcon;
|
231 | }());
|
232 | export var MdIconModule = (function () {
|
233 | function MdIconModule() {
|
234 | }
|
235 | MdIconModule.forRoot = function () {
|
236 | return {
|
237 | ngModule: MdIconModule,
|
238 | providers: [MdIconRegistry],
|
239 | };
|
240 | };
|
241 | MdIconModule = __decorate([
|
242 | NgModule({
|
243 | imports: [HttpModule],
|
244 | exports: [MdIcon],
|
245 | declarations: [MdIcon],
|
246 | }),
|
247 | __metadata('design:paramtypes', [])
|
248 | ], MdIconModule);
|
249 | return MdIconModule;
|
250 | }());
|
251 |
|
252 |
|