<commit_before>@using Lombiq.HelpfulExtensions.Extensions.Bootstrap.Models
@using OrchardCore.DisplayManagement
@using OrchardCore.DisplayManagement.Implementation
@{
    if (Model is not IShape shape || shape.As<BootstrapSplitButton>() is not { } viewModel) { return; }

    var classes = $"btn btn-{(string.IsNullOrWhiteSpace(viewModel.Type) ? "primary" : viewModel.Type)}";
    var options = viewModel.Options.AsList();
    var disabled = !options.Any();
}

<div class="btn-group bootstrapSplitButton @viewModel.WrapperClasses">
    <button type="button"
            class="bootstrapSplitButton__main @classes @viewModel.ButtonClasses"
            disabled="@disabled">
        @(string.IsNullOrWhiteSpace(viewModel.Text) ? options.FirstOrDefault().Text : viewModel.Text)
    </button>
    <button type="button"
            class="dropdown-toggle dropdown-toggle-split bootstrapSplitButton__dropdownButton @classes @viewModel.ToggleClasses"
            disabled="@disabled"
            aria-expanded="false">
        <span class="visually-hidden">@T["Toggle Dropdown"]</span>
    </button>
    <div class="w-100 h-100 fixed-bottom bootstrapSplitButton__screen"></div>
    <ul class="bootstrapSplitButton__dropdownMenu dropdown-menu @viewModel.DropdownClasses">
        @foreach (var option in options)
        {
            <li class="bootstrapSplitButton__dropdownMenuItem">
                @if (option.Text?.Trim().StartsWith("---") == true)
                {
                    <hr class="dropdown-divider">
                }
                else
                {
                    <a href="@option.Url" class="dropdown-item">@option.Text</a>
                }
            </li>
        }
    </ul>
</div>

<script asp-name="BootstrapSplitButtonScript" at="Foot">
Array.from(document.querySelectorAll('.bootstrapSplitButton'))
    .forEach((block) => {
        const toggler = block.querySelector('.bootstrapSplitButton__dropdownButton');
        const menu = block.querySelector('.bootstrapSplitButton__dropdownMenu');

        const screen = block.querySelector('.bootstrapSplitButton__screen');
        screen.style.zIndex = 'auto';
        screen.hidden = true;
        screen.addEventListener('click', () => toggler.click());

        block.querySelector('.bootstrapSplitButton__main')
            .addEventListener('click', () => block.querySelector('a.dropdown-item').click());

        toggler
            .addEventListener('click', (event) => {
                const expanded = event.target.getAttribute('aria-expanded') === 'false';
                event.target.setAttribute('aria-expanded', expanded);
                screen.hidden = !expanded;
                menu.classList[expanded ? 'add' : 'remove']('show');
                menu.style.marginTop = toggler.offsetHeight + 'px';
            });
    });
</script><commit_msg>Use shadowOffset.<commit_after>@using Lombiq.HelpfulExtensions.Extensions.Bootstrap.Models
@using OrchardCore.DisplayManagement
@using OrchardCore.DisplayManagement.Implementation
@{
    if (Model is not IShape shape || shape.As<BootstrapSplitButton>() is not { } viewModel) { return; }

    var type = string.IsNullOrWhiteSpace(viewModel.Type) ? "primary" : viewModel.Type;
    var classes = $"btn btn-{type}";
    var options = viewModel.Options.AsList();
    var disabled = !options.Any();
    var shadowOffset = type == "primary" ? 0 : 8;
}

<div class="btn-group bootstrapSplitButton @viewModel.WrapperClasses">
    <button type="button"
            class="bootstrapSplitButton__main @classes @viewModel.ButtonClasses"
            disabled="@disabled">
        @(string.IsNullOrWhiteSpace(viewModel.Text) ? options.FirstOrDefault().Text : viewModel.Text)
    </button>
    <button type="button"
            class="dropdown-toggle dropdown-toggle-split bootstrapSplitButton__dropdownButton @classes @viewModel.ToggleClasses"
            disabled="@disabled"
            aria-expanded="false">
        <span class="visually-hidden">@T["Toggle Dropdown"]</span>
    </button>
    <div class="w-100 h-100 fixed-bottom bootstrapSplitButton__screen"></div>
    <ul class="bootstrapSplitButton__dropdownMenu dropdown-menu @viewModel.DropdownClasses">
        @foreach (var option in options)
        {
            <li class="bootstrapSplitButton__dropdownMenuItem">
                @if (option.Text?.Trim().StartsWith("---") == true)
                {
                    <hr class="dropdown-divider">
                }
                else
                {
                    <a href="@option.Url" class="dropdown-item">@option.Text</a>
                }
            </li>
        }
    </ul>
</div>

<script asp-name="BootstrapSplitButtonScript" at="Foot">
Array.from(document.querySelectorAll('.bootstrapSplitButton'))
    .forEach((block) => {
        const toggler = block.querySelector('.bootstrapSplitButton__dropdownButton');
        const menu = block.querySelector('.bootstrapSplitButton__dropdownMenu');

        const screen = block.querySelector('.bootstrapSplitButton__screen');
        screen.style.zIndex = 'auto';
        screen.hidden = true;
        screen.addEventListener('click', () => toggler.click());

        block.querySelector('.bootstrapSplitButton__main')
            .addEventListener('click', () => block.querySelector('a.dropdown-item').click());

        toggler
            .addEventListener('click', (event) => {
                const expanded = event.target.getAttribute('aria-expanded') === 'false';
                event.target.setAttribute('aria-expanded', expanded);
                screen.hidden = !expanded;
                menu.classList[expanded ? 'add' : 'remove']('show');
                menu.style.marginTop = (toggler.offsetHeight + @shadowOffset) + 'px';
            });
    });
</script>
{'fraction_non_alphanumeric': 0.13668567478831864, 'fraction_numerical': 0.002419215482979091, 'mean_word_length': 2.775603392041748, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 51, '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': '7037377', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1507, 'n_words': 260}