appointments.js
3 days ago
attendees.js
3 days ago
colorManipulation.js
3 days ago
customer.js
3 days ago
date.js
3 days ago
defaultCustomize.js
3 days ago
employee.js
3 days ago
events.js
3 days ago
formFieldsTemplates.js
3 days ago
formatting.js
3 days ago
helper.js
3 days ago
image.js
3 days ago
integrationApple.js
3 days ago
integrationGoogle.js
3 days ago
integrationOutlook.js
3 days ago
integrationStripe.js
3 days ago
integrationZoom.js
3 days ago
licence.js
3 days ago
phone.js
3 days ago
pricing.js
3 days ago
recurring.js
3 days ago
responsive.js
3 days ago
scrollElements.js
3 days ago
settings.js
3 days ago
translationsElementPlus.js
3 days ago
utilHeaderHeight.js
3 days ago
utilHeaderHeight.js
131 lines
| 1 | function getStickyOrFixedHeaderHeight(options = {}) { |
| 2 | let root = options.root |
| 3 | let win = options.win || window |
| 4 | let edgeSlop = typeof options.edgeSlop === 'number' ? options.edgeSlop : 4 |
| 5 | let headerThreshold = typeof options.headerThreshold === 'number' ? options.headerThreshold : 200 |
| 6 | let elementsFromPointMaxDepth = |
| 7 | typeof options.elementsFromPointMaxDepth === 'number' ? options.elementsFromPointMaxDepth : 24 |
| 8 | let ancestorMaxDepth = |
| 9 | typeof options.ancestorMaxDepth === 'number' ? options.ancestorMaxDepth : 14 |
| 10 | |
| 11 | let doc = win.document |
| 12 | let body = root && root.nodeType === 9 ? root.body : root |
| 13 | if (!body) { |
| 14 | body = doc.body |
| 15 | } |
| 16 | |
| 17 | if (!body || typeof body.querySelectorAll !== 'function') { |
| 18 | return 0 |
| 19 | } |
| 20 | |
| 21 | let candidates = collectTopChromeCandidates( |
| 22 | body, |
| 23 | doc, |
| 24 | elementsFromPointMaxDepth, |
| 25 | ancestorMaxDepth, |
| 26 | ) |
| 27 | |
| 28 | let maxBottom = 0 |
| 29 | |
| 30 | candidates.forEach((el) => { |
| 31 | let rect = el.getBoundingClientRect() |
| 32 | if (rect.width <= 0 || rect.height <= 0) { |
| 33 | return |
| 34 | } |
| 35 | if (rect.top > headerThreshold) { |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | let style = win.getComputedStyle(el) |
| 40 | let position = style.position |
| 41 | |
| 42 | if (position !== 'fixed' && position !== 'sticky') { |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | if ( |
| 47 | style.display === 'none' || |
| 48 | style.visibility === 'hidden' || |
| 49 | parseFloat(style.opacity) === 0 |
| 50 | ) { |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | let top = rect.top |
| 55 | let parsedTop = parseFloat(style.top) |
| 56 | let anchorTop = Number.isFinite(parsedTop) ? parsedTop : 0 |
| 57 | |
| 58 | if (position === 'fixed') { |
| 59 | if (top >= anchorTop - edgeSlop && top <= anchorTop + edgeSlop) { |
| 60 | maxBottom = Math.max(maxBottom, rect.bottom) |
| 61 | } |
| 62 | } else if (position === 'sticky') { |
| 63 | if (top <= anchorTop + edgeSlop && top >= anchorTop - edgeSlop) { |
| 64 | maxBottom = Math.max(maxBottom, rect.bottom) |
| 65 | } |
| 66 | } |
| 67 | }) |
| 68 | |
| 69 | return Math.round(maxBottom) |
| 70 | } |
| 71 | |
| 72 | function collectTopChromeCandidates(body, doc, elementsFromPointMaxDepth, ancestorMaxDepth) { |
| 73 | let set = new Set() |
| 74 | let semantic = body.querySelectorAll('header, [role="banner"], .site-header, nav, #wpadminbar') |
| 75 | |
| 76 | for (let i = 0; i < semantic.length; i++) { |
| 77 | set.add(semantic[i]) |
| 78 | } |
| 79 | |
| 80 | let kids = body.children |
| 81 | for (let i = 0; i < kids.length; i++) { |
| 82 | set.add(kids[i]) |
| 83 | } |
| 84 | |
| 85 | if (typeof doc.elementsFromPoint !== 'function') { |
| 86 | return set |
| 87 | } |
| 88 | |
| 89 | let win = doc.defaultView |
| 90 | if (!win) { |
| 91 | return set |
| 92 | } |
| 93 | |
| 94 | let w = win.innerWidth || 0 |
| 95 | let xs = w > 24 ? [8, Math.floor(w / 2), w - 8] : [Math.max(1, Math.floor(w / 2))] |
| 96 | let y = 2 |
| 97 | |
| 98 | for (let x = 0; x < xs.length; x++) { |
| 99 | let stack = doc.elementsFromPoint(xs[x], y) |
| 100 | if (!stack || !stack.length) { |
| 101 | continue |
| 102 | } |
| 103 | |
| 104 | let limit = Math.min(stack.length, elementsFromPointMaxDepth) |
| 105 | for (let i = 0; i < limit; i++) { |
| 106 | addAncestorsWithinBody(set, stack[i], body, ancestorMaxDepth) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | return set |
| 111 | } |
| 112 | |
| 113 | function addAncestorsWithinBody(set, el, body, maxDepth) { |
| 114 | let node = el |
| 115 | let depth = 0 |
| 116 | |
| 117 | while (node && node !== body && depth < maxDepth) { |
| 118 | if (node.nodeType === 1) { |
| 119 | set.add(node) |
| 120 | } |
| 121 | node = node.parentElement |
| 122 | depth++ |
| 123 | } |
| 124 | |
| 125 | if (node === body && body.nodeType === 1) { |
| 126 | set.add(body) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | export { getStickyOrFixedHeaderHeight } |
| 131 |