MCPcopy
hub / github.com/hokein/electron-sample-apps / eltOffset

Function eltOffset

mini-code-editor/cm/lib/codemirror.js:2938–2953  ·  view source on GitHub ↗
(node, screen)

Source from the content-addressed store, hash-verified

2936 // Find the position of an element by following the offsetParent chain.
2937 // If screen==true, it returns screen (rather than page) coordinates.
2938 function eltOffset(node, screen) {
2939 var bod = node.ownerDocument.body;
2940 var x = 0, y = 0, skipBody = false;
2941 for (var n = node; n; n = n.offsetParent) {
2942 var ol = n.offsetLeft, ot = n.offsetTop;
2943 // Firefox reports weird inverted offsets when the body has a border.
2944 if (n == bod) { x += Math.abs(ol); y += Math.abs(ot); }
2945 else { x += ol, y += ot; }
2946 if (screen && computedStyle(n).position == "fixed")
2947 skipBody = true;
2948 }
2949 var e = screen && !skipBody ? null : bod;
2950 for (var n = node.parentNode; n != e; n = n.parentNode)
2951 if (n.scrollLeft != null) { x -= n.scrollLeft; y -= n.scrollTop;}
2952 return {left: x, top: y};
2953 }
2954 // Use the faster and saner getBoundingClientRect method when possible.
2955 if (document.documentElement.getBoundingClientRect != null) eltOffset = function(node, screen) {
2956 // Take the parts of bounding client rect that we are interested in so we are able to edit if need be,

Callers 4

CodeMirrorFunction · 0.85
updateSelectionFunction · 0.85
pageCoordsFunction · 0.85
posFromMouseFunction · 0.85

Calls 1

computedStyleFunction · 0.85

Tested by

no test coverage detected