1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | import * as tslib_1 from "tslib";
|
24 | import { MDCFoundation } from '@material/base/foundation';
|
25 | import { strings } from './constants';
|
26 | var MDCGridListFoundation = (function (_super) {
|
27 | tslib_1.__extends(MDCGridListFoundation, _super);
|
28 |
|
29 | function MDCGridListFoundation(adapter) {
|
30 | var _this = _super.call(this, tslib_1.__assign({}, MDCGridListFoundation.defaultAdapter, adapter)) || this;
|
31 | _this.resizeFrame_ = 0;
|
32 | _this.resizeHandler_ = _this.alignCenter.bind(_this);
|
33 | return _this;
|
34 | }
|
35 | Object.defineProperty(MDCGridListFoundation, "strings", {
|
36 | get: function () {
|
37 | return strings;
|
38 | },
|
39 | enumerable: true,
|
40 | configurable: true
|
41 | });
|
42 | Object.defineProperty(MDCGridListFoundation, "defaultAdapter", {
|
43 | get: function () {
|
44 | return {
|
45 | deregisterResizeHandler: function () { return undefined; },
|
46 | getNumberOfTiles: function () { return 0; },
|
47 | getOffsetWidth: function () { return 0; },
|
48 | getOffsetWidthForTileAtIndex: function () { return 0; },
|
49 | registerResizeHandler: function () { return undefined; },
|
50 | setStyleForTilesElement: function () { return undefined; },
|
51 | };
|
52 | },
|
53 | enumerable: true,
|
54 | configurable: true
|
55 | });
|
56 | MDCGridListFoundation.prototype.init = function () {
|
57 | this.alignCenter();
|
58 | this.adapter_.registerResizeHandler(this.resizeHandler_);
|
59 | };
|
60 | MDCGridListFoundation.prototype.destroy = function () {
|
61 | this.adapter_.deregisterResizeHandler(this.resizeHandler_);
|
62 | };
|
63 | MDCGridListFoundation.prototype.alignCenter = function () {
|
64 | var _this = this;
|
65 | cancelAnimationFrame(this.resizeFrame_);
|
66 | this.resizeFrame_ = requestAnimationFrame(function () {
|
67 | _this.alignCenter_();
|
68 | _this.resizeFrame_ = 0;
|
69 | });
|
70 | };
|
71 | MDCGridListFoundation.prototype.alignCenter_ = function () {
|
72 | if (this.adapter_.getNumberOfTiles() === 0) {
|
73 | return;
|
74 | }
|
75 | var gridWidth = this.adapter_.getOffsetWidth();
|
76 | var itemWidth = this.adapter_.getOffsetWidthForTileAtIndex(0);
|
77 | var tilesWidth = itemWidth * Math.floor(gridWidth / itemWidth);
|
78 | this.adapter_.setStyleForTilesElement('width', tilesWidth + "px");
|
79 | };
|
80 | return MDCGridListFoundation;
|
81 | }(MDCFoundation));
|
82 | export { MDCGridListFoundation };
|
83 |
|
84 | export default MDCGridListFoundation;
|
85 |
|
\ | No newline at end of file |