<commit_before>(function ($) {
    Drupal.behaviors.islandora_paged_tei_seadragon_update_page = {
        attach: function (context, settings) {
            // TEI pane's width can't be set via CSS.
            $("#paged-tei-seadragon-viewer-tei").height($(".openseadragon-canvas").height());

            // Function for handling page changes.
            Drupal.settings.islandora_paged_tei_seadragon_update_page = function (pid, page_number) {
                $.ajax({
                    url: Drupal.settings.basePath + "islandora/rest/v1/object/"
                        + pid + "/datastream/JP2/token?" + $.param({"uses": 2}),
                    cache: false,
                    success: function(token) {
                        // Update seadragon.
                        settings.islandoraOpenSeadragon.resourceUri =
                            location.protocol + "//" + location.host + "/" +
                            Drupal.settings.basePath + "islandora/object/" + pid
                            + "/datastream/JP2/view?token=" + token;
                        tile_source = new OpenSeadragon.DjatokaTileSource(
                            settings.islandoraOpenSeadragon.settings.djatokaServerBaseURL,
                            settings.islandoraOpenSeadragon.resourceUri,
                            settings.islandoraOpenSeadragon
                        );
                        Drupal.settings.islandora_open_seadragon_viewer.open(tile_source);
                        // Updating the PID to keep it consistent, it isn't used.
                        settings.islandoraOpenSeadragon.pid = pid;
                        // Scroll TEI silently fails on bad transforms
                        if ($("div[data-paged-viewer-page='" + page_number + "']").position() != null) {
                            $("#paged-tei-seadragon-viewer-tei").scrollTop(
                                $("div[data-paged-viewer-page='" + page_number + "']").position().top +
                                $("#paged-tei-seadragon-viewer-tei").scrollTop()
                            );
                        }
                        // Update current URL.
                        // @todo preserve query params here.
                        var params = {};
                        params.islandora_paged_content_page = page_number;
                        history.pushState({}, "", location.pathname + "?" + $.param(params));
                        // Swap out datastream download links.
                        $(".paged-tei-seadragon-viewer-download-datastreams").empty();
                        var iteration;
                        var page_dsids = Drupal.settings.islandora_paged_tei_seadragon.page_dsids;
                        for (iteration = 0; iteration < page_dsids.length; ++iteration) {
                            var dsid = page_dsids[iteration];
                            $.ajax({
                                url: Drupal.settings.basePath + "islandora/rest/v1/object/"
                                    + pid + "/datastream/" + dsid + "?" + $.param({"content": "FALSE"}),
                                cache: false,
                                success: function(datastream_info) {
                                    var kilobyte = 1024;
                                    var megabyte = kilobyte * 1024;
                                    var gigabyte = megabyte * 1024;
                                    var terabyte = gigabyte * 1024;
                                    var bytes = datastream_info.size;
                                    var size = 0;

                                    // Round is less precise than Islandora's PHP side.
                                    if ((bytes >= 0) && (bytes < kilobyte)) {
                                        size = bytes + ' B';
                                    }
                                    else if ((bytes >= kilobyte) && (bytes < megabyte)) {
                                        size = Math.round(bytes / kilobyte) + ' KiB';
                                    }
                                    else if ((bytes >= megabyte) && (bytes < gigabyte)) {
                                        size = Math.round(bytes / megabyte) + ' MiB';
                                    }
                                    else if ((bytes >= gigabyte) && (bytes < terabyte)) {
                                        size = Math.round(bytes / gigabyte) + ' GiB';
                                    }
                                    else if (bytes >= terabyte) {
                                        size = Math.round(bytes / terabyte) + ' TiB';
                                    }
                                    else {
                                        size = bytes + ' B';
                                    }
                                    download = "<div>" + Drupal.settings.islandora_paged_tei_seadragon.download_prefix<commit_msg>ajax race condition should be handled<commit_after>(function ($) {
    Drupal.behaviors.islandora_paged_tei_seadragon_update_page = {
        attach: function (context, settings) {
            // TEI pane's width can't be set via CSS.
            $("#paged-tei-seadragon-viewer-tei").height($(".openseadragon-canvas").height());
            // Function for handling page changes.
            Drupal.settings.islandora_paged_tei_seadragon_update_page = function (pid, page_number) {
                // Drop out here if we are the most current request.
                if (pid == Drupal.settings.islandora_paged_tei_seadragon.current_page) {
                    return;
                }
                // Update current URL.
                // @todo preserve query params here.
                var params = {};
                params.islandora_paged_content_page = page_number;
                history.pushState({}, "", location.pathname + "?" + $.param(params));
                // Update current page to prevent race conditions.
                Drupal.settings.islandora_paged_tei_seadragon.current_page = pid;

                // Update page rendering.
                $.ajax({
                    url: Drupal.settings.basePath + "islandora/rest/v1/object/"
                        + pid + "/datastream/JP2/token?" + $.param({"uses": 2}),
                    cache: false,
                    success: function(token) {
                        // Drop out here if we are not the most current request.
                        if (pid != Drupal.settings.islandora_paged_tei_seadragon.current_page) {
                            return;
                        }
                        // Update seadragon.
                        settings.islandoraOpenSeadragon.resourceUri =
                            location.protocol + "//" + location.host + "/" +
                            Drupal.settings.basePath + "islandora/object/" + pid
                            + "/datastream/JP2/view?token=" + token;
                        tile_source = new OpenSeadragon.DjatokaTileSource(
                            settings.islandoraOpenSeadragon.settings.djatokaServerBaseURL,
                            settings.islandoraOpenSeadragon.resourceUri,
                            settings.islandoraOpenSeadragon
                        );
                        Drupal.settings.islandora_open_seadragon_viewer.open(tile_source);
                        // Updating the PID to keep it consistent, it isn't used.
                        settings.islandoraOpenSeadragon.pid = pid;
                        // Scroll TEI silently fails on bad transforms
                        if ($("div[data-paged-viewer-page='" + page_number + "']").position() != null) {
                            $("#paged-tei-seadragon-viewer-tei").scrollTop(
                                $("div[data-paged-viewer-page='" + page_number + "']").position().top +
                                $("#paged-tei-seadragon-viewer-tei").scrollTop()
                            );
                        }

                        // Swap out datastream download links.
                        $(".paged-tei-seadragon-viewer-download-datastreams").empty();
                        var iteration;
                        var page_dsids = Drupal.settings.islandora_paged_tei_seadragon.page_dsids;
                        for (iteration = 0; iteration < page_dsids.length; ++iteration) {
                            var dsid = page_dsids[iteration];
                            $.ajax({
                                url: Drupal.settings.basePath + "islandora/rest/v1/object/"
                                    + pid + "/datastream/" + dsid + "?" + $.param({"content": "FALSE"}),
                                cache: false,
                                success: function(datastream_info) {
                                    // Drop out here if we are not the most current request.
                                    if (pid != Drupal.settings.islandora_paged_tei_seadragon.current_page) {
                                        return;
                                    }
                                    var kilobyte = 1024;
                                    var megabyte = kilobyte * 1024;
                                    var gigabyte = megabyte * 1024;
                                    var terabyte = gigabyte * 1024;
                                    var bytes = datastream_info.size;
                                    var size = 0;

                                    // Round is less precise than Islandora's PHP side.
                                    if ((bytes >= 0) && (bytes < kilobyte)) {
                                        size = bytes + ' B';
                                    }
                                    else if ((bytes >= kilobyte) && (bytes < megabyte)) {
                                        size = Math.round(bytes / kilobyte) + ' KiB';
                                    }
                                    else if ((bytes >= megabyte) && (bytes < gigabyte)) {
                                        size = Math.round(bytes / megabyte) + ' MiB';
                                    }
                                    else if ((bytes >= gigabyte) && (bytes < terabyte)) {
                                        size = Math.round(bytes / gigabyte) + ' GiB';
                                    }
                                    else if (bytes >= terabyte) {
                                        size = Math.round(bytes / terabyte) + ' TiB';
                                    }
                                    else {
                                        size = bytes + ' B';
                                    }
                                    download = "<div>" + Drupal.settings.islandora_paged_tei_seadragon.download_prefix
{'fraction_non_alphanumeric': 0.0945099484156227, 'fraction_numerical': 0.004421518054532056, 'mean_word_length': 0.9693451841102848, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 90, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5477631', 'n_tokens_mistral': 2651, 'n_tokens_neox': 2492, 'n_words': 484}