<commit_before>define(function () {
    var dw, dh, rw, rh, lx, ly;

    var Zoom = function (element) {
        this.target = element;

        if (this.isOpen === undefined) {
            this._init();
        }
    };

    Zoom.prototype._init = function () {
        var self = this;

        this.target.className += ' zoom';

        this._cache = {};
        this.link = {};
        this.image = {};

        this.flyout = document.createElement('div');
        this.flyout.className = 'zoom-flyout';

        this.notice = document.createElement('div');
        this.notice.className = 'zoom-notice';

        this.target.addEventListener('click', function (event) {
            event.preventDefault();
        }, true);

        this.target.addEventListener('mouseover', function (event) {
            if (!self.isOpen) {
                event.preventDefault();
                self._show(this, event);
            }
        }, true);

        this.target.addEventListener('mousemove', function (event) {
            if (self.isOpen) {
                event.preventDefault();
                self._move(event);
            }
        }, true);

        this.target.addEventListener('mouseout', function (event) {
            if (self.isOpen) {
                event.preventDefault();
                self.hide();
            }
        }, true);
    };

    Zoom.prototype._show = function (link, e) {
        var w1, h1, w2, h2;
        var self = this;

        // Swap image
        if (link.href !== this.link.href) {
            this.link = link;
            this.image = link.querySelector('img');

            this._swap(link.href, function () {
                self._show(link, e);
            });

            return;
        }

        this.target.appendChild(this.flyout);

        // Find offset relative to viewport
        this.offset = (function (element) {
<commit_msg>Issue #851: Fix zoom script issue when flyout is triggered before initialization finishes<commit_after>define(function () {
    var dw, dh, rw, rh, lx, ly;

    var Zoom = function (element) {
        this.target = element;

        if (typeof this.isOpen === 'undefined') {
            this._init();
        }
    };

    Zoom.prototype._init = function () {
        var self = this;

        this.target.className += ' zoom';

        this._cache = {};
        this.link = {};
        this.image = {};

        this.flyout = document.createElement('div');
        this.flyout.className = 'zoom-flyout';

        this.notice = document.createElement('div');
        this.notice.className = 'zoom-notice';

        this.target.addEventListener('click', function (event) {
            event.preventDefault();
        }, true);

        this.target.addEventListener('mouseover', function (event) {
            if (!self.isOpen) {
                event.preventDefault();
                self._show(this, event);
            }
        }, true);

        this.target.addEventListener('mousemove', function (event) {
            if (self.isOpen) {
                event.preventDefault();
                self._move(event);
            }
        }, true);

        this.target.addEventListener('mouseout', function (event) {
            if (self.isOpen) {
                event.preventDefault();
                self.hide();
            }
        }, true);
    };

    Zoom.prototype._show = function (link, e) {
        var w1, h1, w2, h2;
        var self = this;

        // Swap image
        if (link.href !== this.link.href) {
            this.link = link;
            this.image = link.querySelector('img');

            this._swap(link.href, function () {
                self._show(link, e);
            });

            return;
        }

        if (typeof this.zoom === 'undefined') {
            return;
        }

        this.target.appendChild(this.flyout);

        // Find offset relative to viewport
        this.offset = (function (element) {

{'fraction_non_alphanumeric': 0.13500506585612967, 'fraction_numerical': 0.002786220871327254, 'mean_word_length': 1.557642487046632, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6568210', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1037, 'n_words': 220}