مدیاویکی:Common.js: تفاوت میان نسخه‌ها

از ویکی داد
پرش به ناوبری پرش به جستجو
بدون خلاصۀ ویرایش
برچسب: برگردانده‌شده
بدون خلاصۀ ویرایش
برچسب: واگردانی دستی
 
خط ۲۳۷: خط ۲۳۷:


     });
     });
} );
/* =========================================================
  ویکی‌داد — منوی موبایل
  ========================================================= */
/* ---------------------------------------------------------
  منوی موبایل در حالت عادی مخفی است
  --------------------------------------------------------- */
.wd-mobile-menu {
    display: none;
}
/* =========================================================
  فقط موبایل
  ========================================================= */
@media screen and (max-width: 767px) {
    /* -----------------------------------------------------
      نوار منوی موبایل
      ----------------------------------------------------- */
    .wd-mobile-menu {
        display: block;
        width: 100%;
        margin: 0 0 18px 0;
        direction: rtl;
        text-align: right;
        font-family:
            "Vazirmatn",
            "IRANSans",
            Tahoma,
            Arial,
            sans-serif;
    }
    /* -----------------------------------------------------
      دکمه منو
      ----------------------------------------------------- */
    .wd-mobile-menu-button {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        min-height: 48px;
        padding: 10px 15px;
        background: #ffffff;
        border: 1px solid #dfe7e5;
        border-right: 4px solid #168477;
        border-radius: 9px;
        color: #11695f;
        font-size: 15px;
        font-weight: bold;
        line-height: 1.8;
        cursor: pointer;
        box-shadow:
            0 2px 10px rgba(20,60,55,0.05);
        transition:
            background 0.15s ease,
            border-color 0.15s ease;
    }
    .wd-mobile-menu-button:hover,
    .wd-mobile-menu-button:focus {
        background: #f5faf8;
        border-color: #168477;
        outline: none;
    }
    /* آیکون همبرگری */
    .wd-mobile-menu-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        margin-left: 8px;
        background: #edf7f4;
        border-radius: 7px;
        color: #168477;
        font-size: 20px;
        line-height: 1;
    }
    /* فلش */
    .wd-mobile-menu-arrow {
        font-size: 15px;
        color: #78909c;
        transition:
            transform 0.2s ease;
    }
    .wd-mobile-menu.is-open
    .wd-mobile-menu-arrow {
        transform: rotate(180deg);
    }
    /* -----------------------------------------------------
      محتوای منو
      ----------------------------------------------------- */
    .wd-mobile-menu-content {
        display: none;
        margin-top: 7px;
        padding: 7px;
        background: #ffffff;
        border: 1px solid #dfe7e5;
        border-radius: 9px;
        box-shadow:
            0 4px 16px rgba(20,60,55,0.07);
    }
    .wd-mobile-menu.is-open
    .wd-mobile-menu-content {
        display: block;
    }
    /* -----------------------------------------------------
      لینک‌های منو
      ----------------------------------------------------- */
    .wd-mobile-menu-content a {
        display: block;
        width: 100%;
        padding: 11px 13px;
        margin: 2px 0;
        border-radius: 7px;
        color: #37474f !important;
        font-size: 15px;
        font-weight: normal;
        line-height: 1.8;
        text-decoration: none !important;
        transition:
            background 0.15s ease,
            color 0.15s ease;
    }
    .wd-mobile-menu-content a:hover,
    .wd-mobile-menu-content a:focus {
        background: #f1f8f6;
        color: #11695f !important;
    }
    /* -----------------------------------------------------
      لینک فعال
      ----------------------------------------------------- */
    .wd-mobile-menu-content a.wd-mobile-active {
        background: #edf7f4;
        color: #11695f !important;
        font-weight: bold;
    }
    /* -----------------------------------------------------
      جداکننده
      ----------------------------------------------------- */
    .wd-mobile-menu-divider {
        height: 1px;
        margin: 7px 10px;
        background: #e7eeec;
    }
    /* -----------------------------------------------------
      گروه اصلی
      ----------------------------------------------------- */
    .wd-mobile-menu-title {
        padding: 7px 13px 5px;
        color: #78909c;
        font-size: 11px;
        font-weight: bold;
        line-height: 1.8;
    }
}
/* =========================================================
  ویکی‌داد — منوی موبایل
  ========================================================= */
$( function () {
    /*
    * -----------------------------------------------------
    * فقط در موبایل منو ساخته می‌شود
    * -----------------------------------------------------
    */
    if ( window.innerWidth > 767 ) {
        return;
    }
    /*
    * اگر منو قبلاً ساخته شده، دوباره نساز
    */
    if ( $( '.wd-mobile-menu' ).length ) {
        return;
    }
    /*
    * -----------------------------------------------------
    * ساخت منوی موبایل
    * -----------------------------------------------------
    */
    var menu = $(
        '<div class="wd-mobile-menu">' +
            '<button type="button" ' +
                'class="wd-mobile-menu-button" ' +
                'aria-expanded="false">' +
                '<span style="display:flex;align-items:center;">' +
                    '<span class="wd-mobile-menu-icon">☰</span>' +
                    '<span>منوی ویکی‌داد</span>' +
                '</span>' +
                '<span class="wd-mobile-menu-arrow">▼</span>' +
            '</button>' +
            '<div class="wd-mobile-menu-content">' +
                '<div class="wd-mobile-menu-title">' +
                    'دسترسی سریع' +
                '</div>' +
                '<a href="/صفحه_اصلی">' +
                    'صفحه اصلی' +
                '</a>' +
                '<a href="/قوانین_و_مقررات">' +
                    'قوانین و مقررات' +
                '</a>' +
                '<a href="/آراء_قضایی">' +
                    'آراء قضایی' +
                '</a>' +
                '<a href="/نظریات_مشورتی">' +
                    'نظریات مشورتی' +
                '</a>' +
                '<a href="/اصطلاحات_حقوقی">' +
                    'اصطلاحات حقوقی' +
                '</a>' +
                '<a href="/آزمون‌های_حقوقی">' +
                    'آزمون‌های حقوقی' +
                '</a>' +
                '<div class="wd-mobile-menu-divider"></div>' +
                '<div class="wd-mobile-menu-title">' +
                    'قوانین پرکاربرد' +
                '</div>' +
                '<a href="/قانون_کار">' +
                    'قانون کار' +
                '</a>' +
                '<a href="/قانون_مدنی">' +
                    'قانون مدنی' +
                '</a>' +
                '<a href="/قانون_تأمین_اجتماعی">' +
                    'قانون تأمین اجتماعی' +
                '</a>' +
                '<a href="/قانون_مدیریت_خدمات_کشوری">' +
                    'قانون مدیریت خدمات کشوری' +
                '</a>' +
            '</div>' +
        '</div>'
    );
    /*
    * -----------------------------------------------------
    * محل قرارگیری منو
    *
    * بعد از Header و قبل از محتوای صفحه
    * -----------------------------------------------------
    */
    var target =
        $( '#content' ).first();
    if ( target.length ) {
        target.prepend( menu );
    } else {
        $( '.mw-body' )
            .first()
            .prepend( menu );
    }
    /*
    * -----------------------------------------------------
    * باز و بسته کردن منو
    * -----------------------------------------------------
    */
    $( document ).on(
        'click',
        '.wd-mobile-menu-button',
        function () {
            var button = $( this );
            var container =
                button.closest(
                    '.wd-mobile-menu'
                );
            var isOpen =
                container.hasClass(
                    'is-open'
                );
            if ( isOpen ) {
                container.removeClass(
                    'is-open'
                );
                button.attr(
                    'aria-expanded',
                    'false'
                );
            } else {
                container.addClass(
                    'is-open'
                );
                button.attr(
                    'aria-expanded',
                    'true'
                );
            }
        }
    );
    /*
    * -----------------------------------------------------
    * بعد از انتخاب لینک، منو بسته شود
    * -----------------------------------------------------
    */
    $( document ).on(
        'click',
        '.wd-mobile-menu-content a',
        function () {
            $( this )
                .closest(
                    '.wd-mobile-menu'
                )
                .removeClass(
                    'is-open'
                );
        }
    );


} );
} );

نسخهٔ کنونی تا ۱۰ سپتامبر ۲۰۲۶، ساعت ۱۵:۰۶

$( function () {

    /*
     * =====================================================
     * ویکی‌داد — تست‌های تعاملی
     * =====================================================
     */


    /*
     * -----------------------------------------------------
     * تبدیل گزینه‌های لیست به گزینه‌های قابل کلیک
     * -----------------------------------------------------
     */

    $( '.wd-test-options' ).each( function () {

        var container = $( this );

        container.find( 'li' ).each( function () {

            $( this ).addClass( 'wd-test-option' );

        } );

    });


    /*
     * -----------------------------------------------------
     * انتخاب گزینه
     * -----------------------------------------------------
     */

    $( document ).on( 'click', '.wd-test-option', function () {

        var option = $( this );

        var box = option.closest( '.wd-test' );


        /*
         * اگر پاسخ صحیح قبلاً انتخاب شده،
         * تست تمام شده است.
         */

        if ( box.hasClass( 'wd-test-finished' ) ) {
            return;
        }


        /*
         * دریافت پاسخ صحیح
         */

        var answer = $.trim(
            box.attr( 'data-answer' )
        );


        /*
         * متن گزینه انتخاب‌شده
         */

        var selectedText = $.trim(
            option.text()
        );


        /*
         * عناصر نتیجه
         */

        var result = box.find(
            '.wd-test-result'
        );

        var message = box.find(
            '.wd-test-result-message'
        );

        var answerBox = box.find(
            '.wd-test-answer'
        );


        /*
         * تشخیص حرف گزینه
         */

        var selectedLetter = '';


        if (
            selectedText.indexOf( 'الف' ) === 0
        ) {

            selectedLetter = 'الف';

        } else if (
            selectedText.indexOf( 'ب' ) === 0
        ) {

            selectedLetter = 'ب';

        } else if (
            selectedText.indexOf( 'ج' ) === 0
        ) {

            selectedLetter = 'ج';

        } else if (
            selectedText.indexOf( 'د' ) === 0
        ) {

            selectedLetter = 'د';

        }


        /*
         * تبدیل:
         *
         * گزینه ب
         *
         * به:
         *
         * ب
         */

        var correctLetter = answer
            .replace( 'گزینه', '' )
            .replace( ':', '' )
            .trim();


        /*
         * ثبت انتخاب کاربر
         */

        option.addClass(
            'wd-selected'
        );


        /*
         * نمایش پیام نتیجه
         */

        result.show();


        /*
         * =================================================
         * پاسخ صحیح
         * =================================================
         */

        if (
            selectedLetter === correctLetter
        ) {

            option.addClass(
                'wd-correct'
            );


            message
                .removeClass(
                    'wd-result-wrong'
                )
                .addClass(
                    'wd-result-correct'
                )
                .text(
                    '✓ پاسخ شما صحیح است.'
                );


            /*
             * نمایش پاسخ و تحلیل
             */

            answerBox
                .stop(
                    true,
                    true
                )
                .slideDown(
                    250
                );


            /*
             * پایان تست
             */

            box.addClass(
                'wd-test-finished'
            );

        }


        /*
         * =================================================
         * پاسخ غلط
         * =================================================
         */

        else {

            option.addClass(
                'wd-wrong'
            );


            message
                .removeClass(
                    'wd-result-correct'
                )
                .addClass(
                    'wd-result-wrong'
                )
                .text(
                    '✕ پاسخ شما نادرست است.'
                );


            /*
             * عمداً پاسخ صحیح را نمایش نمی‌دهیم.
             *
             * کاربر می‌تواند گزینه دیگری را انتخاب کند.
             */

        }

    });

} );