<commit_before>/**
 * Smoothy
 * Written by: <NAME>
 * Version: 1.0.0
 * Licence: MIT
 * Requirements: None, it is a framework-free plugin
 * Site: https://github.com/kaloja/smoothy
 * Smoothy is inspired by:
 * https://github.com/GabrielDelepine/smooth-scroll,
 * http://gizma.com/easing,
 * https://github.com/callmecavs/jump.js
 */

(function (root, factory) {

    root.smoothy = factory();

})(this, function () {

    'use strict';

    var Smoothy = {

        data: {
            fixedHeader: false, // If user interface using fixed header.
            headerHeight: 0, // Set the height of your header to avoid your target being hidden behind it.
            speed: 1000, // Speed set in pixels per second.
            easing: true // Choose animation type, 'true' equal to 'easeInOutQuad' and 'false' equal to 'linear'.
        },

        settings: {},

        init: function () {
            this.extend();
            this.options();
        },

        // @source: https://gomakethings.com/vanilla-javascript-version-of-jquery-extend/
        extend: function () {
            var extended = {},
                deep = false,
                i = 0,
                length = arguments.length;

            // Check if a deep merge.
            if (Object.prototype.toString.call(arguments[0]) === '[object Boolean]') {
                deep = arguments[0];
                i++;
            };

            // Merge the object into the extended object.
            function merge(obj) {
                for (var prop in obj) {
                    if (Object.prototype.hasOwnProperty.call(obj, prop)) {

                        // If deep merge and property is an object, merge properties.
                        if (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {
                            extended[prop] = extend(true, extended[prop], obj[prop]);
                        } else {
                            extended[prop] = obj[prop];
                        }
                    }
                }
            };

            // Loop through each object and conduct a merge.
            for (; i < length; i++) {
                var obj = arguments[i];
                merge(obj);
            }

            return extended;
        },

        options: function (obj) {
            var data = Smoothy.extend(Smoothy.data, obj);
            Smoothy.settings = data;

            // Init the scroll function.
            this.scroll();
        },

        scroll: function () {
            var links = document.getElementsByTagName('a'),
                speed = Smoothy.settings.speed;

            for (var i = 0; i < links.length; i++) {
                var href = (links[i].attributes.href === undefined) ? null : links[i].attributes.href.value.toString();
                if (href !== null && href.length > 1 && href.indexOf('#') != -1) {

                    links[i].onclick = function () {
                        var href = this.attributes.href.value.toString(),
                            id = href.substr(href.indexOf('#') + 1),
                            timeStart,
                            timeElapsed,
                            element;

                        if (element = document.getElementById(id)) {
                            var start = getScrollTopDocument(),
                                distance = getScrollTopElement(element) - start,
                                duration = Math.abs(distance / speed) * 1000;
                        }

                        function easing(timeElapsed, start, distance, duration) {
                            if (Smoothy.settings.easing == false) {
                                return distance * timeElapsed / duration + start;
                            } else if (Smoothy.settings.easing == true) {
                                timeElapsed = timeElapsed / (duration / 2);
                                if (timeElapsed < 1) {
                                    return distance / 2 * timeElapsed * timeElapsed + start;
                                } else {
                                    timeElapsed--;
                                    return -distance / 2 * (timeElapsed * (timeElapsed - 2) - 1) + start;
                                }
                            }
                        }

                        requestAnimationFrame(function (time) {
                            timeStart = time;
                            animate(time);
                        });

                        function animate(time) {
                            timeElapsed = time - timeStart;
                            window.scrollTo(0, easing(timeElapsed, start, distance, duration));

                            if (timeElapsed < duration) {
                                requestAnimationFrame(animate);
                            } else {
                                end();
                            }
                        }

                        function end() {
                            window.scrollTo(0, start + distance);
                            cancelAnimationFrame(animate);
                        }

                        return false;
                    };
                }
            }<commit_msg>Added id to cancelAnimationFrame.<commit_after>/**
 * Smoothy
 * Written by: <NAME>
 * Version: 1.0.0
 * Licence: MIT
 * Requirements: None, it is a framework-free plugin
 * Site: https://github.com/kaloja/smoothy
 * Smoothy is inspired by:
 * https://github.com/GabrielDelepine/smooth-scroll,
 * http://gizma.com/easing,
 * https://github.com/callmecavs/jump.js
 */

(function (root, factory) {

    root.smoothy = factory();

})(this, function () {

    'use strict';

    var Smoothy = {

        data: {
            fixedHeader: false, // If user interface using fixed header.
            headerHeight: 0, // Set the height of your header to avoid your target being hidden behind it.
            speed: 1000, // Speed set in pixels per second.
            easing: true // Choose animation type, 'true' equal to 'easeInOutQuad' and 'false' equal to 'linear'.
        },

        settings: {},

        init: function () {
            this.extend();
            this.options();
        },

        // @source: https://gomakethings.com/vanilla-javascript-version-of-jquery-extend/
        extend: function () {
            var extended = {},
                deep = false,
                i = 0,
                length = arguments.length;

            // Check if a deep merge.
            if (Object.prototype.toString.call(arguments[0]) === '[object Boolean]') {
                deep = arguments[0];
                i++;
            };

            // Merge the object into the extended object.
            function merge(obj) {
                for (var prop in obj) {
                    if (Object.prototype.hasOwnProperty.call(obj, prop)) {

                        // If deep merge and property is an object, merge properties.
                        if (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {
                            extended[prop] = extend(true, extended[prop], obj[prop]);
                        } else {
                            extended[prop] = obj[prop];
                        }
                    }
                }
            };

            // Loop through each object and conduct a merge.
            for (; i < length; i++) {
                var obj = arguments[i];
                merge(obj);
            }

            return extended;
        },

        options: function (obj) {
            var data = Smoothy.extend(Smoothy.data, obj);
            Smoothy.settings = data;

            // Init the scroll function.
            this.scroll();
        },

        scroll: function () {
            var links = document.getElementsByTagName('a'),
                speed = Smoothy.settings.speed;

            for (var i = 0; i < links.length; i++) {
                var href = (links[i].attributes.href === undefined) ? null : links[i].attributes.href.value.toString();
                if (href !== null && href.length > 1 && href.indexOf('#') != -1) {

                    links[i].onclick = function () {
                        var href = this.attributes.href.value.toString(),
                            id = href.substr(href.indexOf('#') + 1),
                            timeStart,
                            timeElapsed,
                            animateId,
                            element;

                        if (element = document.getElementById(id)) {
                            var start = getScrollTopDocument(),
                                distance = getScrollTopElement(element) - start,
                                duration = Math.abs(distance / speed) * 1000;
                        }

                        function easing(timeElapsed, start, distance, duration) {
                            if (Smoothy.settings.easing == false) {
                                return distance * timeElapsed / duration + start;
                            } else if (Smoothy.settings.easing == true) {
                                timeElapsed = timeElapsed / (duration / 2);
                                if (timeElapsed < 1) {
                                    return distance / 2 * timeElapsed * timeElapsed + start;
                                } else {
                                    timeElapsed--;
                                    return -distance / 2 * (timeElapsed * (timeElapsed - 2) - 1) + start;
                                }
                            }
                        }

                        requestAnimationFrame(function (time) {
                            timeStart = time;
                            animate(time);
                        });

                        function animate(time) {
                            timeElapsed = time - timeStart;
                            window.scrollTo(0, easing(timeElapsed, start, distance, duration));

                            if (timeElapsed < duration) {
                                animateId = requestAnimationFrame(animate);
                            } else {
                                end();
                            }
                        }

                        function end() {
                            window.scrollTo(0, start + distance);
                            cancelAnimationFrame(animateId);
                        }

                        return false;
                    };
                }
            }
{'fraction_non_alphanumeric': 0.10181442135940584, 'fraction_numerical': 0.005076619347560402, 'mean_word_length': 1.0340344168260038, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1595147', 'n_tokens_mistral': 2592, 'n_tokens_neox': 2384, 'n_words': 611}