-
Notifications
You must be signed in to change notification settings - Fork 59
/
global-position-strategy.js
103 lines (103 loc) · 4.27 KB
/
global-position-strategy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"use strict";
var apply_transform_1 = require('@angular2-material/core/style/apply-transform');
/**
* A strategy for positioning overlays. Using this strategy, an overlay is given an
* explicit position relative to the browser's viewport.
*/
var GlobalPositionStrategy = (function () {
function GlobalPositionStrategy() {
this._cssPosition = 'absolute';
this._top = '';
this._bottom = '';
this._left = '';
this._right = '';
/** Array of individual applications of translateX(). Currently only for centering. */
this._translateX = [];
/** Array of individual applications of translateY(). Currently only for centering. */
this._translateY = [];
}
/** Sets the element to usee CSS position: fixed */
GlobalPositionStrategy.prototype.fixed = function () {
this._cssPosition = 'fixed';
return this;
};
/** Sets the element to usee CSS position: absolute. This is the default. */
GlobalPositionStrategy.prototype.absolute = function () {
this._cssPosition = 'absolute';
return this;
};
/** Sets the top position of the overlay. Clears any previously set vertical position. */
GlobalPositionStrategy.prototype.top = function (value) {
this._bottom = '';
this._translateY = [];
this._top = value;
return this;
};
/** Sets the left position of the overlay. Clears any previously set horizontal position. */
GlobalPositionStrategy.prototype.left = function (value) {
this._right = '';
this._translateX = [];
this._left = value;
return this;
};
/** Sets the bottom position of the overlay. Clears any previously set vertical position. */
GlobalPositionStrategy.prototype.bottom = function (value) {
this._top = '';
this._translateY = [];
this._bottom = value;
return this;
};
/** Sets the right position of the overlay. Clears any previously set horizontal position. */
GlobalPositionStrategy.prototype.right = function (value) {
this._left = '';
this._translateX = [];
this._right = value;
return this;
};
/**
* Centers the overlay horizontally with an optional offset.
* Clears any previously set horizontal position.
*/
GlobalPositionStrategy.prototype.centerHorizontally = function (offset) {
if (offset === void 0) { offset = '0px'; }
this._left = '50%';
this._right = '';
this._translateX = ['-50%', offset];
return this;
};
/**
* Centers the overlay vertically with an optional offset.
* Clears any previously set vertical position.
*/
GlobalPositionStrategy.prototype.centerVertically = function (offset) {
if (offset === void 0) { offset = '0px'; }
this._top = '50%';
this._bottom = '';
this._translateY = ['-50%', offset];
return this;
};
/**
* Apply the position to the element.
* @internal
*/
GlobalPositionStrategy.prototype.apply = function (element) {
element.style.position = this._cssPosition;
element.style.top = this._top;
element.style.left = this._left;
element.style.bottom = this._bottom;
element.style.right = this._right;
// TODO(jelbourn): we don't want to always overwrite the transform property here,
// because it will need to be used for animations.
var tranlateX = this._reduceTranslateValues('translateX', this._translateX);
var translateY = this._reduceTranslateValues('translateY', this._translateY);
apply_transform_1.applyCssTransform(element, tranlateX + " " + translateY);
return Promise.resolve();
};
/** Reduce a list of translate values to a string that can be used in the transform property */
GlobalPositionStrategy.prototype._reduceTranslateValues = function (translateFn, values) {
return values.map(function (t) { return (translateFn + "(" + t + ")"); }).join(' ');
};
return GlobalPositionStrategy;
}());
exports.GlobalPositionStrategy = GlobalPositionStrategy;
//# sourceMappingURL=/usr/local/google/home/jelbourn/material2/tmp/broccoli_type_script_compiler-input_base_path-IydvmmBU.tmp/0/core/overlay/position/global-position-strategy.js.map