MCPcopy Index your code
hub / github.com/ampproject/amphtml / setupElement_

Method setupElement_

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

* This method records the potentially fixed or sticky element. One of a more * critical functions - it records all selectors that may apply "fixed" * or "sticky" to this element to check them later. * * @param {!Element} element * @param {string} selector * @param {string} position

(
    element,
    selector,
    position,
    opt_forceTransfer,
    opt_lightboxMode
  )

Source from the content-addressed store, hash-verified

650 * @private
651 */
652 setupElement_(
653 element,
654 selector,
655 position,
656 opt_forceTransfer,
657 opt_lightboxMode
658 ) {
659 // Warn that pub-authored inline styles may be overridden by FixedLayer.
660 if (!opt_forceTransfer) {
661 this.warnAboutInlineStylesIfNecessary_(element);
662 }
663
664 // Ignore lightboxes because FixedLayer can interfere with their
665 // opening/closing animations (#19149).
666 if (isLightbox(element)) {
667 return false;
668 }
669 const isLightboxDescendant = closest(element, isLightbox);
670 if (!opt_lightboxMode && isLightboxDescendant) {
671 return false;
672 }
673
674 const elements = this.elements_;
675
676 // Avoid ancestor-descendant relationships in tracked elements to prevent
677 // "double top-offset" (#22860).
678 const removals = [];
679 for (let i = 0; i < elements.length; i++) {
680 const el = elements[i].element;
681 if (el === element) {
682 break;
683 }
684 // Early exit if element is a child of an already-tracked element...
685 if (el.contains(element)) {
686 return false;
687 }
688 // Remove the already-tracked element if it is a child of the new
689 // element...
690 if (element.contains(el)) {
691 removals.push(el);
692 }
693 }
694 for (let i = 0; i < removals.length; i++) {
695 this.removeElement(removals[i]);
696 }
697
698 let fe = null;
699 for (let i = 0; i < elements.length; i++) {
700 const el = elements[i];
701 if (el.element == element && el.position == position) {
702 fe = el;
703 break;
704 }
705 }
706 const isFixed = position == 'fixed';
707 if (fe) {
708 if (!fe.selectors.includes(selector)) {
709 // Already seen.

Callers 3

addElementMethod · 0.95
setupSelectors_Method · 0.95

Calls 7

removeElementMethod · 0.95
closestFunction · 0.90
isLightboxFunction · 0.85
containsMethod · 0.45
pushMethod · 0.45
setAttributeMethod · 0.45

Tested by

no test coverage detected