UNPKG

3.84 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2016 Google Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23import * as tslib_1 from "tslib";
24import { MDCFoundation } from '@material/base/foundation';
25import { strings } from './constants';
26var MDCGridListFoundation = /** @class */ (function (_super) {
27 tslib_1.__extends(MDCGridListFoundation, _super);
28 /* istanbul ignore next: optional argument is not a branch statement */
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));
82export { MDCGridListFoundation };
83// tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
84export default MDCGridListFoundation;
85//# sourceMappingURL=foundation.js.map
\No newline at end of file