Skip to content

Commit bd49897

Browse files
committed
chore(material): clean up old workarounds with new features.
1 parent 7c52bc9 commit bd49897

File tree

21 files changed

+223
-227
lines changed

21 files changed

+223
-227
lines changed

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ gulp.task('benchpress.bundle', ['build/clean.benchpress.bundle', 'build.js.cjs']
11691169
BENCHPRESS_BUNDLE_CONFIG.dest,
11701170
cb
11711171
);
1172-
})
1172+
});
11731173

11741174

11751175
// register cleanup listener for ctrl+c/kill used to quit any persistent task (autotest or serve tasks)

modules/angular2_material/src/components/checkbox/checkbox.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import {Component, View, Attribute, ViewEncapsulation} from 'angular2/angular2';
22
import {isPresent} from 'angular2/src/facade/lang';
3-
import {KEY_SPACE} from 'angular2_material/src/core/constants';
3+
import {KeyCodes} from 'angular2_material/src/core/key_codes';
44
import {KeyboardEvent} from 'angular2/src/facade/browser';
55
import {NumberWrapper} from 'angular2/src/facade/lang';
66

77
@Component({
88
selector: 'md-checkbox',
99
properties: ['checked', 'disabled'],
1010
host: {
11-
'(keydown)': 'onKeydown($event)',
12-
'[tabindex]': 'tabindex',
13-
'[attr.role]': '"checkbox"',
11+
'role': 'checkbox',
1412
'[attr.aria-checked]': 'checked',
15-
'[attr.aria-disabled]': 'disabled'
13+
'[attr.aria-disabled]': 'disabled',
14+
'[tabindex]': 'tabindex',
15+
'(keydown)': 'onKeydown($event)',
1616
}
1717
})
1818
@View({
@@ -25,27 +25,27 @@ export class MdCheckbox {
2525
checked: boolean;
2626

2727
/** Whether this checkbox is disabled. */
28-
_disabled: boolean;
28+
disabled_: boolean;
2929

3030
/** Setter for tabindex */
3131
tabindex: number;
3232

3333
constructor(@Attribute('tabindex') tabindex: string) {
3434
this.checked = false;
3535
this.tabindex = isPresent(tabindex) ? NumberWrapper.parseInt(tabindex, 10) : 0;
36-
this._disabled = false;
36+
this.disabled_ = false;
3737
}
3838

3939
get disabled() {
40-
return this._disabled;
40+
return this.disabled_;
4141
}
4242

4343
set disabled(value) {
44-
this._disabled = isPresent(value) && value !== false;
44+
this.disabled_ = isPresent(value) && value !== false;
4545
}
4646

4747
onKeydown(event: KeyboardEvent) {
48-
if (event.keyCode == KEY_SPACE) {
48+
if (event.keyCode == KeyCodes.SPACE) {
4949
event.preventDefault();
5050
this.toggle(event);
5151
}

modules/angular2_material/src/components/dialog/dialog.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {ObservableWrapper, Promise, PromiseWrapper} from 'angular2/src/facade/as
1616
import {isPresent, Type} from 'angular2/src/facade/lang';
1717
import {DOM} from 'angular2/src/dom/dom_adapter';
1818
import {MouseEvent, KeyboardEvent} from 'angular2/src/facade/browser';
19-
import {KEY_ESC} from 'angular2_material/src/core/constants';
19+
import {KeyCodes} from 'angular2_material/src/core/key_codes';
2020

2121
// TODO(jelbourn): Opener of dialog can control where it is rendered.
2222
// TODO(jelbourn): body scrolling is disabled while dialog is open.
@@ -44,7 +44,6 @@ export class MdDialog {
4444
* Opens a modal dialog.
4545
* @param type The component to open.
4646
* @param elementRef The logical location into which the component will be opened.
47-
* @param parentInjector
4847
* @param options
4948
* @returns Promise for a reference to the dialog.
5049
*/
@@ -69,11 +68,6 @@ export class MdDialog {
6968
var dialogElement = containerRef.location.nativeElement;
7069
DOM.appendChild(DOM.query('body'), dialogElement);
7170

72-
// TODO(jelbourn): Use hostProperties binding to set these once #1539 is fixed.
73-
// Configure properties on the host element.
74-
DOM.addClass(dialogElement, 'md-dialog');
75-
DOM.setAttribute(dialogElement, 'tabindex', '0');
76-
7771
// TODO(jelbourn): Do this with hostProperties (or another rendering abstraction) once
7872
// ready.
7973
if (isPresent(config.width)) {
@@ -119,11 +113,11 @@ export class MdDialog {
119113
}
120114

121115
alert(message: string, okMessage: string): Promise<any> {
122-
throw "Not implemented";
116+
throw 'Not implemented';
123117
}
124118

125119
confirm(message: string, okMessage: string, cancelMessage: string): Promise<any> {
126-
throw "Not implemented";
120+
throw 'Not implemented';
127121
}
128122
}
129123

@@ -209,9 +203,14 @@ export class MdDialogConfig {
209203
*/
210204
@Component({
211205
selector: 'md-dialog-container',
212-
host: {'(body:^keydown)': 'documentKeypress($event)'},
206+
host: {
207+
'class': 'md-dialog',
208+
'tabindex': '0',
209+
'(body:^keydown)': 'documentKeypress($event)',
210+
},
213211
})
214212
@View({
213+
encapsulation: ViewEncapsulation.NONE,
215214
templateUrl: 'package:angular2_material/src/components/dialog/dialog.html',
216215
directives: [forwardRef(() => MdDialogContent)]
217216
})
@@ -232,7 +231,7 @@ class MdDialogContainer {
232231
}
233232

234233
documentKeypress(event: KeyboardEvent) {
235-
if (event.keyCode == KEY_ESC) {
234+
if (event.keyCode == KeyCodes.ESCAPE) {
236235
this.dialogRef.close();
237236
}
238237
}
@@ -243,7 +242,9 @@ class MdDialogContainer {
243242
* location
244243
* for where the dialog content will be loaded.
245244
*/
246-
@Directive({selector: 'md-dialog-content'})
245+
@Directive({
246+
selector: 'md-dialog-content',
247+
})
247248
class MdDialogContent {
248249
constructor(@Host() @SkipSelf() dialogContainer: MdDialogContainer, elementRef: ElementRef) {
249250
dialogContainer.contentRef = elementRef;
@@ -253,9 +254,11 @@ class MdDialogContent {
253254
/** Component for the dialog "backdrop", a transparent overlay over the rest of the page. */
254255
@Component({
255256
selector: 'md-backdrop',
256-
host: {'(click)': 'onClick()'},
257+
host: {
258+
'(click)': 'onClick()',
259+
},
257260
})
258-
@View({template: ''})
261+
@View({template: '', encapsulation: ViewEncapsulation.NONE})
259262
class MdBackdrop {
260263
dialogRef: MdDialogRef;
261264

modules/angular2_material/src/components/grid_list/grid_list.ts

Lines changed: 60 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ import {Math} from 'angular2/src/facade/math';
1616
// TODO(jelbourn): Conditional (responsive) column count / row size.
1717
// TODO(jelbourn): Re-layout on window resize / media change (debounced).
1818
// TODO(jelbourn): gridTileHeader and gridTileFooter.
19-
// TODO(jelbourn): rowHeightMode enum (after TS conversion).
19+
20+
/** Row hieght mode options. Use a static class b/c TypeScript enums are strictly number-based. */
21+
class RowHeightMode {
22+
static FIT = 'fit';
23+
static FIXED = 'fixed';
24+
static RATIO = 'ratio';
25+
}
26+
2027

2128
@Component({
2229
selector: 'md-grid-list',
@@ -64,19 +71,19 @@ export class MdGridList {
6471

6572
/** Set internal representation of row height from the user-provided value. */
6673
set rowHeight(value) {
67-
if (value === 'fit') {
68-
this.rowHeightMode = 'fit';
74+
if (value === RowHeightMode.FIT) {
75+
this.rowHeightMode = RowHeightMode.FIT;
6976
} else if (StringWrapper.contains(value, ':')) {
70-
var ratioParts = value.split(':');
77+
let ratioParts = value.split(':');
7178
if (ratioParts.length !== 2) {
7279
throw `md-grid-list: invalid ratio given for row-height: "${value}"`;
7380
}
7481

75-
this.rowHeightMode = 'ratio';
82+
this.rowHeightMode = RowHeightMode.RATIO;
7683
this.rowHeightRatio =
7784
NumberWrapper.parseFloat(ratioParts[0]) / NumberWrapper.parseFloat(ratioParts[1]);
7885
} else {
79-
this.rowHeightMode = 'fixed';
86+
this.rowHeightMode = RowHeightMode.FIXED;
8087
this.fixedRowHeight = value;
8188
}
8289
}
@@ -87,20 +94,13 @@ export class MdGridList {
8794

8895
/** Computes and applies the size and position for all children grid tiles. */
8996
layoutTiles() {
90-
var tracker = new TileCoordinator(this.cols, this.tiles);
97+
let tracker = new TileCoordinator(this.cols, this.tiles);
9198
this.rows = tracker.rowCount;
9299

93-
for (var i = 0; i < this.tiles.length; i++) {
94-
var pos = tracker.positions[i];
95-
var tile = this.tiles[i];
96-
var style = this.getTileStyle(tile, pos.row, pos.col);
97-
98-
tile.styleWidth = style.width;
99-
tile.styleHeight = style.height;
100-
tile.styleTop = style.top;
101-
tile.styleLeft = style.left;
102-
tile.styleMarginTop = style.marginTop;
103-
tile.stylePaddingTop = style.paddingTop;
100+
for (let i = 0; i < this.tiles.length; i++) {
101+
let pos = tracker.positions[i];
102+
let tile = this.tiles[i];
103+
tile.style = this.getTileStyle(tile, pos.row, pos.col);
104104
}
105105
}
106106

@@ -164,55 +164,50 @@ export class MdGridList {
164164
/** Gets the style properties to be applied to a tile for the given row and column index. */
165165
getTileStyle(tile: MdGridTile, rowIndex: number, colIndex: number): TileStyle {
166166
// Percent of the available horizontal space that one column takes up.
167-
var percentWidthPerTile = 100 / this.cols;
167+
let percentWidthPerTile = 100 / this.cols;
168168

169169
// Fraction of the vertical gutter size that each column takes up.
170170
// For example, if there are 5 columns, each column uses 4/5 = 0.8 times the gutter width.
171-
var gutterWidthFractionPerTile = (this.cols - 1) / this.cols;
171+
let gutterWidthFractionPerTile = (this.cols - 1) / this.cols;
172172

173173
// Base horizontal size of a column.
174-
var baseTileWidth = this.getBaseTileSize(percentWidthPerTile, gutterWidthFractionPerTile);
174+
let baseTileWidth = this.getBaseTileSize(percentWidthPerTile, gutterWidthFractionPerTile);
175175

176176
// The width and horizontal position of each tile is always calculated the same way, but the
177177
// height and vertical position depends on the rowMode.
178-
var tileStyle = new TileStyle();
178+
let tileStyle = new TileStyle();
179179
tileStyle.left = this.getTilePosition(baseTileWidth, colIndex);
180180
tileStyle.width = this.getTileSize(baseTileWidth, tile.colspan);
181181

182-
// TODO: make cases enums when we support enums
183-
switch (this.rowHeightMode) {
184-
case 'fixed':
185-
// In fixed mode, simply use the given row height.
186-
tileStyle.top = this.getTilePosition(this.fixedRowHeight, rowIndex);
187-
tileStyle.height = this.getTileSize(this.fixedRowHeight, tile.rowspan);
188-
break;
189-
190-
case 'ratio':
191-
var percentHeightPerTile = percentWidthPerTile / this.rowHeightRatio;
192-
var baseTileHeight = this.getBaseTileSize(percentHeightPerTile, gutterWidthFractionPerTile);
182+
if (this.rowHeightMode == RowHeightMode.FIXED) {
183+
// In fixed mode, simply use the given row height.
184+
tileStyle.top = this.getTilePosition(this.fixedRowHeight, rowIndex);
185+
tileStyle.height = this.getTileSize(this.fixedRowHeight, tile.rowspan);
186+
}
193187

194-
// Use paddingTop and marginTop to maintain the given aspect ratio, as
195-
// a percentage-based value for these properties is applied versus the *width* of the
196-
// containing block. See http://www.w3.org/TR/CSS2/box.html#margin-properties
197-
tileStyle.marginTop = this.getTilePosition(baseTileHeight, rowIndex);
198-
tileStyle.paddingTop = this.getTileSize(baseTileHeight, tile.rowspan);
199-
break;
188+
if (this.rowHeightMode == RowHeightMode.RATIO) {
189+
let percentHeightPerTile = percentWidthPerTile / this.rowHeightRatio;
190+
let baseTileHeight = this.getBaseTileSize(percentHeightPerTile, gutterWidthFractionPerTile);
200191

201-
case 'fit':
202-
// Percent of the available vertical space that one row takes up.
203-
var percentHeightPerTile = 100 / this.cols;
192+
// Use paddingTop and marginTop to maintain the given aspect ratio, as
193+
// a percentage-based value for these properties is applied versus the *width* of the
194+
// containing block. See http://www.w3.org/TR/CSS2/box.html#margin-properties
195+
tileStyle.marginTop = this.getTilePosition(baseTileHeight, rowIndex);
196+
tileStyle.paddingTop = this.getTileSize(baseTileHeight, tile.rowspan);
197+
}
204198

205-
// Fraction of the horizontal gutter size that each column takes up.
206-
var gutterHeightFractionPerTile = (this.rows - 1) / this.rows;
199+
if (this.rowHeightMode == RowHeightMode.FIT) {
200+
// Percent of the available vertical space that one row takes up.
201+
let percentHeightPerTile = 100 / this.cols;
207202

208-
// Base vertical size of a column.
209-
var baseTileHeight =
210-
this.getBaseTileSize(percentHeightPerTile, gutterHeightFractionPerTile);
203+
// Fraction of the horizontal gutter size that each column takes up.
204+
let gutterHeightFractionPerTile = (this.rows - 1) / this.rows;
211205

212-
tileStyle.top = this.getTilePosition(baseTileHeight, rowIndex);
213-
tileStyle.height = this.getTileSize(baseTileHeight, tile.rowspan);
206+
// Base vertical size of a column.
207+
let baseTileHeight = this.getBaseTileSize(percentHeightPerTile, gutterHeightFractionPerTile);
214208

215-
break;
209+
tileStyle.top = this.getTilePosition(baseTileHeight, rowIndex);
210+
tileStyle.height = this.getTileSize(baseTileHeight, tile.rowspan);
216211
}
217212

218213
return tileStyle;
@@ -223,13 +218,13 @@ export class MdGridList {
223218
selector: 'md-grid-tile',
224219
properties: ['rowspan', 'colspan'],
225220
host: {
226-
'[style.height]': 'styleHeight',
227-
'[style.width]': 'styleWidth',
228-
'[style.top]': 'styleTop',
229-
'[style.left]': 'styleLeft',
230-
'[style.marginTop]': 'styleMarginTop',
231-
'[style.paddingTop]': 'stylePaddingTop',
232-
'[attr.role]': '"listitem"'
221+
'role': 'listitem',
222+
'[style.height]': 'style.height',
223+
'[style.width]': 'style.width',
224+
'[style.top]': 'style.top',
225+
'[style.left]': 'style.left',
226+
'[style.marginTop]': 'style.marginTop',
227+
'[style.paddingTop]': 'style.paddingTop',
233228
},
234229
lifecycle: [LifecycleEvent.onDestroy, LifecycleEvent.onChange]
235230
})
@@ -242,13 +237,7 @@ export class MdGridTile {
242237
_rowspan: number;
243238
_colspan: number;
244239

245-
styleHeight: string;
246-
styleWidth: string;
247-
styleTop: string;
248-
styleLeft: string;
249-
styleMarginTop: string;
250-
stylePaddingTop: string;
251-
240+
style: TileStyle;
252241
isRegisteredWithGridList: boolean;
253242

254243
constructor(@SkipSelf() @Host() gridList: MdGridList) {
@@ -257,6 +246,7 @@ export class MdGridTile {
257246
// Tiles default to 1x1, but rowspan and colspan can be changed via binding.
258247
this.rowspan = 1;
259248
this.colspan = 1;
249+
this.style = new TileStyle();
260250
}
261251

262252
set rowspan(value) {
@@ -330,7 +320,7 @@ class TileCoordinator {
330320
this.tracker = ListWrapper.createFixedSize(numColumns);
331321
ListWrapper.fill(this.tracker, 0);
332322

333-
this.positions = ListWrapper.map(tiles, tile => this._trackTile(tile));
323+
this.positions = tiles.map(tile => this._trackTile(tile));
334324
}
335325

336326
/** Gets the number of rows occupied by tiles. */
@@ -345,8 +335,8 @@ class TileCoordinator {
345335
}
346336

347337
// Start index is inclusive, end index is exclusive.
348-
var gapStartIndex = -1;
349-
var gapEndIndex = -1;
338+
let gapStartIndex = -1;
339+
let gapEndIndex = -1;
350340

351341
// Look for a gap large enough to fit the given tile. Empty spaces are marked with a zero.
352342
do {
@@ -389,7 +379,7 @@ class TileCoordinator {
389379
this.rowIndex++;
390380

391381
// Decrement all spaces by one to reflect moving down one row.
392-
for (var i = 0; i < this.tracker.length; i++) {
382+
for (let i = 0; i < this.tracker.length; i++) {
393383
this.tracker[i] = Math.max(0, this.tracker[i] - 1);
394384
}
395385
}
@@ -399,7 +389,7 @@ class TileCoordinator {
399389
* The gap ends when a non-zero value is found.
400390
*/
401391
_findGapEndIndex(gapStartIndex: number): number {
402-
for (var i = gapStartIndex + 1; i < this.tracker.length; i++) {
392+
for (let i = gapStartIndex + 1; i < this.tracker.length; i++) {
403393
if (this.tracker[i] != 0) {
404394
return i;
405395
}
@@ -411,7 +401,7 @@ class TileCoordinator {
411401

412402
/** Update the tile tracker to account for the given tile in the given space. */
413403
_markTilePosition(start, tile) {
414-
for (var i = 0; i < tile.colspan; i++) {
404+
for (let i = 0; i < tile.colspan; i++) {
415405
this.tracker[start + i] = tile.rowspan;
416406
}
417407
}

0 commit comments

Comments
 (0)