<commit_before>﻿import "../../lib/jquery.resize"; // makes jquery resize work on all elements
import { BloomApi } from "../../utils/bloomApi";

// Enhance: this could be turned into a Typescript Module with only two public methods

import theOneLocalizationManager from "../../lib/localizationManager/localizationManager";
import { ImageDescriptionAdapter } from "../toolbox/imageDescription/imageDescription";
import { getToolboxFrameExports } from "../editViewFrame";

declare function ResetRememberedSize(element: HTMLElement);

const kPlaybackOrderContainerSelector: string =
    ".bloom-playbackOrderControlsContainer";

export function cleanupImages() {
    $(".bloom-imageContainer").css("opacity", ""); //comes in on img containers from an old version of myimgscale, and is a major problem if the image is missing
    $(".bloom-imageContainer").css("overflow", ""); //review: also comes form myimgscale; is it a problem?
}

export function SetupImagesInContainer(container) {
    $(container)
        .find(".bloom-imageContainer > img") // the ">" here prevents finding img's of ui affordances deep in comics
        .each(function() {
            SetupImage(this);
        });

    $(container)
        .find(".bloom-imageContainer")
        .each(function() {
            SetupImageContainer(this);
        });

    //todo: this had problems. Check out the later approach, seen in draggableLabel (e.g. move handle on the inside, using a background image on a div)
    $(container)
        .find(".bloom-draggable")
        .mouseenter(function() {
            $(this).prepend(
                "<button class='moveButton' title='Move'></button>"
            );
            $(this)
                .find(".moveButton")
                .mousedown(function(e) {
                    //reviewSlog added the <any>
                    $(this)
                        .parent()
                        .trigger(<any>e);
                });
        });
    $(container)
        .find(".bloom-draggable")
        .mouseleave(function() {
            $(this)
                .find(".moveButton")
                .each(function() {
                    $(this).remove();
                });
        });

    $(container)
        .find("img")
        .each(function() {
            SetAlternateTextOnImages(this);
        });
}

export function SetupImage(image: JQuery) {
    // Remove any obsolete explicit image size and position left over from earlier versions of Bloom, before we had object-fit:contain.
    if (image.style) {
        image.style.width = "";
        image.style.height = "";
        image.style.marginLeft = "";
        image.style.marginTop = "";
    }
    if (image.removeAttribute) {
        image.removeAttribute("style");
        image.removeAttribute("width");
        image.removeAttribute("height");
    }
}

export function GetButtonModifier(container) {
    var buttonModifier = "";
    var imageButtonWidth = 87;
    var imageButtonHeight = 52;
    var $container = $(container);
    if ($container.height() < imageButtonHeight * 2) {
        buttonModifier = "smallButtonHeight";
    }<commit_msg>Fix adding picture container from "Change Layout" (BL-8983)<commit_after>﻿import "../../lib/jquery.resize"; // makes jquery resize work on all elements
import { BloomApi } from "../../utils/bloomApi";

// Enhance: this could be turned into a Typescript Module with only two public methods

import theOneLocalizationManager from "../../lib/localizationManager/localizationManager";
import { ImageDescriptionAdapter } from "../toolbox/imageDescription/imageDescription";
import { getToolboxFrameExports } from "../editViewFrame";

declare function ResetRememberedSize(element: HTMLElement);

const kPlaybackOrderContainerSelector: string =
    ".bloom-playbackOrderControlsContainer";

export function cleanupImages() {
    $(".bloom-imageContainer").css("opacity", ""); //comes in on img containers from an old version of myimgscale, and is a major problem if the image is missing
    $(".bloom-imageContainer").css("overflow", ""); //review: also comes form myimgscale; is it a problem?
}

export function SetupImagesInContainer(container) {
    $(container)
        .find(".bloom-imageContainer > img") // the ">" here prevents finding img's of ui affordances deep in comics
        .each(function() {
            SetupImage(this);
        });

    $(container)
        .find(".bloom-imageContainer")
        .each(function() {
            SetupImageContainer(this);
        });

    //todo: this had problems. Check out the later approach, seen in draggableLabel (e.g. move handle on the inside, using a background image on a div)
    $(container)
        .find(".bloom-draggable")
        .mouseenter(function() {
            $(this).prepend(
                "<button class='moveButton' title='Move'></button>"
            );
            $(this)
                .find(".moveButton")
                .mousedown(function(e) {
                    //reviewSlog added the <any>
                    $(this)
                        .parent()
                        .trigger(<any>e);
                });
        });
    $(container)
        .find(".bloom-draggable")
        .mouseleave(function() {
            $(this)
                .find(".moveButton")
                .each(function() {
                    $(this).remove();
                });
        });

    $(container)
        .find("img")
        .each(function() {
            SetAlternateTextOnImages(this);
        });
}

export function SetupImage(image: JQuery) {
    // Remove any obsolete explicit image size and position left over from earlier versions of Bloom, before we had object-fit:contain.
    if (image.style) {
        image.style.width = "";
        image.style.height = "";
        image.style.marginLeft = "";
        image.style.marginTop = "";
    }
    if (image.removeAttribute) {
        if (image.getAttribute && image.getAttribute("style") === "") {
            image.removeAttribute("style");
        }
        image.removeAttribute("width");
        image.removeAttribute("height");
    }
}

export function GetButtonModifier(container) {
    var buttonModifier = "";
    var imageButtonWidth = 87;
    var imageButtonHeight = 52;
    var $container = $(container);
    if ($container.height() < imageButtonHeight * 2) {
        buttonModifier = "smallButtonHeight";
    }
{'fraction_non_alphanumeric': 0.13028499843407454, 'fraction_numerical': 0.002192295646727216, 'mean_word_length': 2.287184765826042, 'pattern_counts': {'":': 0, '<': 13, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1075926', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1636, 'n_words': 434}