MCPcopy
hub / github.com/ampproject/amphtml / transferTo

Method transferTo

src/service/fixed-layer.js:1071–1124  ·  view source on GitHub ↗

@override

(fe, index, state)

Source from the content-addressed store, hash-verified

1069
1070 /** @override */
1071 transferTo(fe, index, state) {
1072 const {element} = fe;
1073 if (element.parentElement == this.layer_) {
1074 return;
1075 }
1076
1077 dev().fine(TAG, 'transfer to fixed:', fe.id, fe.element);
1078 user().warn(
1079 TAG,
1080 'In order to improve scrolling performance in Safari,' +
1081 ' we now move the element to a fixed positioning layer:',
1082 fe.element
1083 );
1084
1085 if (!fe.placeholder) {
1086 // Never been transferred before: ensure that it's properly configured.
1087 setStyle(element, 'pointer-events', 'initial');
1088 const placeholder = (fe.placeholder =
1089 this.doc_.createElement('i-amphtml-fpa'));
1090 toggle(placeholder, false);
1091 placeholder.setAttribute('i-amphtml-fixedid', fe.id);
1092 }
1093
1094 // Calculate z-index based on the declared z-index and DOM position.
1095 setStyle(
1096 element,
1097 'zIndex',
1098 `calc(${10000 + index} + ${state.zIndex || 0})`
1099 );
1100
1101 // Identify lightboxed elements so they can be visible when the transfer
1102 // layer is "hidden", and hidden with the transfer layer is "visible".
1103 if (fe.lightboxed) {
1104 element.classList.add(LIGHTBOX_ELEMENT_CLASS);
1105 }
1106
1107 element.parentElement.replaceChild(fe.placeholder, element);
1108 this.layer_.appendChild(element);
1109
1110 // Test if the element still matches one of the `fixed` selectors. If not
1111 // return it back to BODY.
1112 const matches = fe.selectors.some((selector) =>
1113 this.matches_(element, selector)
1114 );
1115 if (!matches) {
1116 user().warn(
1117 TAG,
1118 'Failed to move the element to the fixed position layer.' +
1119 ' This is most likely due to the compound CSS selector:',
1120 fe.element
1121 );
1122 this.returnFrom(fe);
1123 }
1124 }
1125
1126 /** @override */
1127 returnFrom(fe) {

Callers

nothing calls this directly

Calls 10

matches_Method · 0.95
returnFromMethod · 0.95
devFunction · 0.90
userFunction · 0.90
setStyleFunction · 0.90
toggleFunction · 0.90
fineMethod · 0.80
warnMethod · 0.80
setAttributeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected