<commit_before>var _ = require('_'),
    overload = require('overload'),
    O = overload.O,

    _utils = require('../utils'),

    _docElem = document.documentElement;

var _getPosition = function(elem) {
    return {
        top: elem.offsetTop || 0,
        left: elem.offsetLeft || 0
    };
};

var _getOffset = function(elem) {
    var rect = elem.getBoundingClientRect();
    return {
        top: (rect.top + document.body.scrollTop) || 0,
        left: (rect.left + document.body.scrollLeft) || 0
    };
};

var _setOffset = function(elem, idx, pos) {
    var position = elem.style.position || 'static',
        props = {};

    // set position first, in-case top/left are set even on static elem
    if (position === 'static') { elem.style.position = 'relative'; }

    var curOffset = _getOffset(elem);
        curCSSTop = elem.style.top;
        curCSSLeft = elem.style.left;
        calculatePosition = (position === 'absolute' || position === 'fixed') && (curCSSTop === 'auto' || curCSSLeft === 'auto');

    if (_.isFunction(pos)) {
        pos = pos.call(elem, idx, curOffset);
    }

    var curTop, curLeft;
    // need to be able to calculate position if either top or left is auto and position is either absolute or fixed
    if (calculatePosition) {
        curPosition = _getPosition(elem);
        curTop = curPosition.top;
        curLeft = curPosition.left;
    } else {
        curTop = parseFloat(curCSSTop) || 0;<commit_msg>Check if elem is attached<commit_after>var _ = require('_'),
    overload = require('overload'),
    O = overload.O,

    _utils = require('../utils'),

    _docElem = document.documentElement;

var _getPosition = function(elem) {
    return {
        top: elem.offsetTop || 0,
        left: elem.offsetLeft || 0
    };
};

var _getOffset = function(elem) {
    var rect = _utils.isAttached(elem) ? elem.getBoundingClientRect() : {};

    return {
        top: (rect.top + document.body.scrollTop) || 0,
        left: (rect.left + document.body.scrollLeft) || 0
    };
};

var _setOffset = function(elem, idx, pos) {
    var position = elem.style.position || 'static',
        props = {};

    // set position first, in-case top/left are set even on static elem
    if (position === 'static') { elem.style.position = 'relative'; }

    var curOffset = _getOffset(elem);
        curCSSTop = elem.style.top;
        curCSSLeft = elem.style.left;
        calculatePosition = (position === 'absolute' || position === 'fixed') && (curCSSTop === 'auto' || curCSSLeft === 'auto');

    if (_.isFunction(pos)) {
        pos = pos.call(elem, idx, curOffset);
    }

    var curTop, curLeft;
    // need to be able to calculate position if either top or left is auto and position is either absolute or fixed
    if (calculatePosition) {
        curPosition = _getPosition(elem);
        curTop = curPosition.top;
        curLeft = curPosition.left;
    } else {
        curTop = parseFloat(curCSSTop) || 0;
{'fraction_non_alphanumeric': 0.13941655359565808, 'fraction_numerical': 0.0033921302578018998, 'mean_word_length': 2.672478206724782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7356335', 'n_tokens_mistral': 914, 'n_tokens_neox': 889, 'n_words': 242}