<commit_before>/*!
 *
 * # BiB/i Extension: C+Arrows
 *
 * - Copyright (c) <NAME> - http://bibi.epub.link/ or https://github.com/satorumurmur/bibi
 * - Licensed under the MIT license. - http://www.opensource.org/licenses/mit-license.php
 */

Bibi.x({

    name: "C+Arrows",
    description: "Floating Buttons for Scrolling and Page-Flipping",
    author: "<NAME> (@satorumurmur)",
    version: Bibi["version"],
    build: Bibi["build"]

})(function() {

    C.Arrows = O.Body.appendChild(
        sML.create("div", { id: "bibi-arrows" }, { display: S["arrows"] == "hidden" ? "none" : "" })
    );
    C.Arrows.Back = C.Arrows.appendChild(
        sML.create("div", { title: "Back",    className: "bibi-arrow", id: "bibi-arrow-back",
            DistanceToMove: -1,
            isActive: function() {
                return (R.Current.Pages.StartPage != R.Pages[0] || R.Current.Pages.StartPageRatio != 100);
            }
        })
    );
    C.Arrows.Forward = C.Arrows.appendChild(
        sML.create("div", { title: "Forward", className: "bibi-arrow", id: "bibi-arrow-forward",
            DistanceToMove: +1,
            isActive: function() {
                return (R.Current.Pages.EndPage != R.Pages[R.Pages.length - 1] || R.Current.Pages.EndPageRatio != 100);
            }
        })
    );

    [C.Arrows.Back, C.Arrows.Forward].forEach(function(Arrow) {
        if(!O.SmartPhone) {
            Arrow.addEventListener("mouseover", function() { if(Arrow.isActive()) sML.addClass(Arrow, "flickering"); });
            Arrow.addEventListener("mouseout",  function() { sML.removeClass(Arrow, "flickering"); });
        }
        Arrow.addEventListener("click", function() {
            if(!Arrow.isActive()) return false;
            E.dispatch("bibi:command:move", Arrow.DistanceToMove);
            sML.addClass(Arrow, "firing");
            if(Arrow.Timer) clearTimeout(Arrow.Timer);
            Arrow.Timer = setTimeout(function() {
                sML.removeClass(Arrow, "firing")
            }, 200);
        });
    });

    C.Arrows.navigate = function() {
        R.getCurrent();
        C.Arrows.check();
        setTimeout(function() {
            R.getCurrent();
            [C.Arrows.Back, C.Arrows.Forward].forEach(function(Arrow) {
                if(Arrow.isActive()) sML.addClass(Arrow, "glowing");
            });
            setTimeout(function() {
                [C.Arrows.Back, C.Arrows.Forward].forEach(function(Arrow) {
                    sML.removeClass(Arrow, "glowing");
                });
            }, 1234);
        }, 420);
    };

    C.Arrows.check = function() {
        [C.Arrows.Back, C.Arrows.Forward].forEach(function(Arrow) {
            if(Arrow.isActive()) sML.removeClass(Arrow, "inactive"); else sML.addClass(Arrow, "inactive");
        });
    };

    E.add("bibi:start",    C.Arrows.navigate);
    E.add("bibi:relayout", C.Arrows.navigate);
    E.add("bibi:scrolled", C.Arrows.check);

    E.dispatch("bibi:createArrows");<commit_msg>Fix and optimize behavior of flipping-arrows on smartphones.<commit_after>/*!
 *
 * # BiB/i Extension: C+Arrows
 *
 * - Copyright (c) <NAME> - http://bibi.epub.link/ or https://github.com/satorumurmur/bibi
 * - Licensed under the MIT license. - http://www.opensource.org/licenses/mit-license.php
 */

Bibi.x({

    name: "C+Arrows",
    description: "Floating Buttons for Scrolling and Page-Flipping",
    author: "<NAME> (@satorumurmur)",
    version: Bibi["version"],
    build: Bibi["build"]

})(function() {

    C.Arrows = O.Body.appendChild(
        sML.create("div", { id: "bibi-arrows" }, { display: S["arrows"] == "hidden" ? "none" : "" })
    );
    C.Arrows.Back = C.Arrows.appendChild(
        sML.create("div", { title: "Back",    className: "bibi-arrow", id: "bibi-arrow-back",
            DistanceToMove: -1,
            isActive: function() {
                return (R.Current.Pages.StartPage != R.Pages[0] || R.Current.Pages.StartPageRatio != 100);
            }
        })
    );
    C.Arrows.Forward = C.Arrows.appendChild(
        sML.create("div", { title: "Forward", className: "bibi-arrow", id: "bibi-arrow-forward",
            DistanceToMove: +1,
            isActive: function() {
                return (R.Current.Pages.EndPage != R.Pages[R.Pages.length - 1] || R.Current.Pages.EndPageRatio != 100);
            }
        })
    );

    [C.Arrows.Back, C.Arrows.Forward].forEach(function(Arrow) {
        if(!O.Handheld) {
            Arrow.addEventListener("mouseover", function() { if(Arrow.isActive()) sML.addClass(Arrow, "flickering"); });
            Arrow.addEventListener("mouseout",  function() { sML.removeClass(Arrow, "flickering"); });
        }
        Arrow.addEventListener("click", function() {
            if(!Arrow.isActive()) return false;
            E.dispatch("bibi:command:move", Arrow.DistanceToMove);
            sML.addClass(Arrow, "firing");
            if(Arrow.Timer) clearTimeout(Arrow.Timer);
            Arrow.Timer = setTimeout(function() {
                sML.removeClass(Arrow, "firing");
            }, 200);
        });
    });

    C.Arrows.navigate = function() {
        R.getCurrent();
        C.Arrows.check();
        setTimeout(function() {
            R.getCurrent();
            [C.Arrows.Back, C.Arrows.Forward].forEach(function(Arrow) {
                if(Arrow.isActive()) sML.addClass(Arrow, "glowing");
            });
            setTimeout(function() {
                [C.Arrows.Back, C.Arrows.Forward].forEach(function(Arrow) {
                    sML.removeClass(Arrow, "glowing");
                });
            }, 1234);
        }, 420);
    };

    C.Arrows.check = function() {
        [C.Arrows.Back, C.Arrows.Forward].forEach(function(Arrow) {
            if(Arrow.isActive()) sML.removeClass(Arrow, "inactive"); else sML.addClass(Arrow, "inactive");
        });
    };

    E.add("bibi:start",    C.Arrows.navigate);
    E.add("bibi:relayout", C.Arrows.navigate);
    E.add("bibi:scrolled", C.Arrows.check);

    E.dispatch("bibi:createArrows");
{'fraction_non_alphanumeric': 0.17485885088010628, 'fraction_numerical': 0.006642311524410495, 'mean_word_length': 2.2556756756756755, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1203119', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1943, 'n_words': 292}