event.js 4.25 KB
Newer Older
Takumi Imai committed
1 2 3 4 5 6
/**
 * js for event behavior
 *
 * @since cms:1.4.3.2&1.4.3.3 web:1.0
 */

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
$(function () {
    hide_del_btn();
});
/** Handle press the Add button */
$('.add').on('click', function () {
    var base = $(this).parent().parent().parent('.tb-item');
    base.find('.del').show();
    // clone input form
    base.clone(true).insertAfter(base);

    // Scroll to added element
    $('html,body').animate({ scrollTop: base.next().offset().top });

    // Input form accordion display
    base.parent().parent('.tb').find('.ac-tb-form').show();
});
/** Handle press the Delete button */
$('.del').on('click', function () {
    var base = $(this).parent().parent().parent('.tb-item');
    var tbwrap = base.parent('.tb-wrap');
    var tb = tbwrap.parent('.tb');

    // Delete area
    base.remove();
    // Hidden delete button
    hide_del_btn();
    // Form area display switch
    tbWrapClear(tbwrap);

    // Hide collapse icon
    if (tb.find('.ac-tb-form').is(':hidden')) {
        tb.find('.fold-area').addClass('hide');
    }
});

/** handle Press the close button */
$('.close-window').on('click', function () {
    window.close();
});

/** Hide delete button when there is only one tablespace form */
function hide_del_btn() {
    $('.tb-wrap').each(function (i, elem) {
        var len = $(elem).find('.tb-item').length;
        // When there is one item in the table
        if (len <= 1) {
            $(elem).find('.del').hide();
            $(this).children('.tb-item').removeClass('visually-hidden');
            // Input form accordion hidden
            $(this).parent().find('.ac-tb-form').hide();
        }
    });
}
/** Handle when deleting while closing the accordion */
function tbWrapClear(tbwrap) {
    // If you delete the form while closing the accordion
    // Hide parent element if all child elements are hidden
    if (tbwrap.children(':not(.visually-hidden)').length == 0) {
        tbwrap.addClass('visually-hidden');
    } else {
        tbwrap.removeClass('visually-hidden');
    }
}

/** input form accordion */
$('.ac-tb-form').on('click', function () {
    var tb = $(this).parent().parent().parent('.tb');
    var elems = tb.find('.tb-wrap').find('.tb-item');
    var tbwrap = tb.find('.tb-wrap');
    if (!$(this).hasClass('hide')) {
        elems.each(function (i) {
            i = i + 1;
            if (i != elems.size()) {
                $(this).addClass('visually-hidden');
            }
        });
        $(this).text('開く');

        // Form area display switch
        tbWrapClear(tbwrap);

        // Collapse icon view
        tb.find('.fold-area').removeClass('hide');
    } else {
        elems.removeClass('visually-hidden');
        $(this).text('閉じる');

        // Form area display switch
        tbWrapClear(tbwrap);

        // Hide collapse icon
        tb.find('.fold-area').addClass('hide');
    }
    // opening and closing
    $(this).toggleClass('hide');
});

/** toggle switch */
$('.toggle').on('click', function () {
    $(this).toggleClass('checked');
    if (!$('input[name="check"]').prop('checked')) {
        $('.toggle input').prop('checked', true);
    } else {
        $('.toggle input').prop('checked', false);
    }
});

/** Menu display */
$('.c-dropdown-trigger').on('click', function () {
    $('[data-target="' + $(this).attr('id') + '"]').toggleClass('show');
    $('.mask').removeClass('hide');
});

/** Close menu */
$('.mask').on('click', function () {
    $('.mask').addClass('hide');
    $('.c-dropdown-menu').removeClass('show');
});

/** Select card list */
$('.select-card-list .card .select-label').on('click', function () {
    $(this).closest('.select-card-list').find('.card').removeClass('selected');
    $(this).closest('.card').addClass('selected');
});

/** List display switching (list display) */
$('.view-menu .view-list-btn').on('click', function () {
    $('.view-block-btn').removeClass('active');
    $('.view-list-btn').addClass('active');
    $('.view-content').removeClass('view-block');
    $('.view-content').addClass('view-list');
});

/** List display switching (grid display) */
$('.view-menu .view-block-btn').on('click', function () {
    $('.view-list-btn').removeClass('active');
    $('.view-block-btn').addClass('active');
    $('.view-content').removeClass('view-list');
    $('.view-content').addClass('view-block');
});