-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathliquid-container.js
More file actions
146 lines (126 loc) · 3.55 KB
/
liquid-container.js
File metadata and controls
146 lines (126 loc) · 3.55 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import Component from '@ember/component';
import Growable from "liquid-fire/growable";
import { measure } from "./liquid-measured";
import layout from "liquid-fire/templates/components/liquid-container";
import $ from 'jquery';
export default Component.extend(Growable, {
layout,
classNames: ['liquid-container'],
lockSize(elt, want) {
elt.outerWidth(want.width);
elt.outerHeight(want.height);
},
unlockSize() {
let doUnlock = () => {
this.updateAnimatingClass(false);
if (this.element) {
this.element.style.width = '';
this.element.style.height = '';
}
};
if (this._scaling) {
this._scaling.then(doUnlock);
} else {
doUnlock();
}
},
// We're doing this manually instead of via classNameBindings
// because it depends on upward-data-flow, which generates warnings
// under Glimmer.
updateAnimatingClass(on){
if (this.isDestroyed) {
return;
}
if (on) {
this.element.classList.add('liquid-animating');
} else {
this.element.classList.remove('liquid-animating');
}
},
didInsertElement() {
this._super(...arguments);
this._wasInserted = true;
},
actions: {
willTransition(versions) {
if (!this._wasInserted) {
return;
}
// Remember our own size before anything changes
let elt = $(this.element);
this._cachedSize = measure(elt);
// And make any children absolutely positioned with fixed sizes.
for (let i = 0; i < versions.length; i++) {
goAbsolute(versions[i]);
}
},
afterChildInsertion(versions) {
let elt = $(this.element);
let enableGrowth = this.get('enableGrowth') !== false;
// Measure children
let sizes = [];
for (let i = 0; i < versions.length; i++) {
if (versions[i].view) {
let childElt = $(versions[i].view.element);
sizes[i] = measure(childElt);
}
}
// Measure ourself again to see how big the new children make
// us.
let want = {
width: Math.max(...sizes.map(size => size.width)),
height: Math.max(...sizes.map(size => size.height)),
};
let have = this._cachedSize || want;
// Make ourself absolute
if (enableGrowth) {
this.lockSize(elt, have);
} else {
this.lockSize(elt, {
height: Math.max(want.height, have.height),
width: Math.max(want.width, have.width)
});
}
// Apply '.liquid-animating' to liquid-container allowing
// any customizable CSS control while an animating is occuring
this.updateAnimatingClass(true);
// Make the children absolute and fixed size.
for (let i = 0; i < versions.length; i++) {
goAbsolute(versions[i], sizes[i]);
}
// Kick off our growth animation
if (enableGrowth) {
this._scaling = this.animateGrowth(elt, have, want);
}
},
afterTransition(versions) {
for (let i = 0; i < versions.length; i++) {
goStatic(versions[i]);
}
this.unlockSize();
}
}
});
function goAbsolute(version, size) {
if (!version.view) {
return;
}
let elt = $(version.view.element);
let pos = elt.position();
if (!size) {
size = measure(elt);
}
elt.outerWidth(size.width);
elt.outerHeight(size.height);
elt.css({
position: 'absolute',
top: pos.top,
left: pos.left
});
}
function goStatic(version) {
if (version.view && !version.view.isDestroyed) {
let elt = $(version.view.element);
elt.css({width: '', height: '', position: ''});
}
}