-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathwormhole.js
106 lines (83 loc) · 2.68 KB
/
wormhole.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
104
105
106
import { guidFor } from '@ember/object/internals';
let deduplicateChildElementIds = (parentElem) => {
if (!parentElem) {
return;
}
let childrenWithUniqueIds = parentElem[0].querySelectorAll('[id]');
if (childrenWithUniqueIds.length) {
for (let el of childrenWithUniqueIds) {
el.setAttribute('id', `${guidFor(el)}-${el.id}`);
}
}
};
export default function wormhole(context) {
let { use } = context;
let oldWormholeElement, newWormholeElement;
if (this.oldElement) {
oldWormholeElement = this.oldElement.find(
'.liquid-wormhole-element:last-child'
);
this.oldElement = null;
if (oldWormholeElement.length > 0) {
const newChild = oldWormholeElement.clone();
newChild.addClass('liquid-wormhole-temp-element');
deduplicateChildElementIds(newChild);
oldWormholeElement.css({ visibility: 'hidden' });
oldWormholeElement.find('.liquid-child').css({ visibility: 'hidden' });
const offset = oldWormholeElement.offset();
newChild.css({
position: 'absolute',
top: offset.top,
left: offset.left,
bottom: '',
right: '',
margin: '0px',
transform: '',
});
newChild.appendTo(oldWormholeElement.parent());
this.oldElement = newChild;
}
}
if (this.newElement) {
newWormholeElement = this.newElement.find(
'.liquid-wormhole-element:last-child'
);
this.newElement = null;
if (newWormholeElement.length > 0) {
const newChild = newWormholeElement.clone();
newWormholeElement.css({ visibility: 'hidden' });
newWormholeElement.find('.liquid-child').css({ visibility: 'hidden' });
deduplicateChildElementIds(newChild);
const offset = newWormholeElement.offset();
newChild.css({
position: 'absolute',
top: offset.top,
left: offset.left,
bottom: '',
right: '',
margin: '0px',
transform: '',
});
newChild.appendTo(newWormholeElement.parent());
this.newElement = newChild;
}
}
var animation;
if (typeof use.handler === 'function') {
animation = use.handler;
} else {
animation = context.lookup(use.name);
}
return animation.apply(this, use.args).finally(() => {
if (this.oldElement && oldWormholeElement) {
this.oldElement.remove();
oldWormholeElement.css({ visibility: 'visible' });
oldWormholeElement.find('.liquid-child').css({ visibility: 'visible' });
}
if (this.newElement && newWormholeElement) {
this.newElement.remove();
newWormholeElement.css({ visibility: 'visible' });
newWormholeElement.find('.liquid-child').css({ visibility: 'visible' });
}
});
}