پرش به محتوا

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

از ویکی داد
بدون خلاصۀ ویرایش
برچسب: واگردانی دستی
بدون خلاصۀ ویرایش
خط ۲۳۹: خط ۲۳۹:


} );
} );
/* ================================
  سابقه تقنینی ماده
  باز و بسته کردن متن
================================ */
$( document ).on(
    'click',
    '.wd-version-toggle',
    function () {
        var button = $( this );
        var card = button.closest(
            '.wd-version-history-card'
        );
        var text = card.find(
            '.wd-version-text'
        );
        var icon = button.find(
            '.wd-version-toggle-icon'
        );
        var label = button.find(
            '.wd-version-toggle-label'
        );
        if ( text.is( ':visible' ) ) {
            text.stop(
                true,
                true
            ).slideUp(
                180
            );
            icon.text( '+' );
            label.text( 'مشاهده متن' );
        } else {
            text.stop(
                true,
                true
            ).slideDown(
                220
            );
            icon.text( '−' );
            label.text( 'بستن متن' );
        }
    }
);

نسخهٔ ۱۱ سپتامبر ۲۰۲۶، ساعت ۲۱:۲۳

$( 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(
                    '✕ پاسخ شما نادرست است.'
                );


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

        }

    });

} );

/* ================================
   سابقه تقنینی ماده
   باز و بسته کردن متن
================================ */

$( document ).on(
    'click',
    '.wd-version-toggle',
    function () {

        var button = $( this );
        var card = button.closest(
            '.wd-version-history-card'
        );

        var text = card.find(
            '.wd-version-text'
        );

        var icon = button.find(
            '.wd-version-toggle-icon'
        );

        var label = button.find(
            '.wd-version-toggle-label'
        );

        if ( text.is( ':visible' ) ) {

            text.stop(
                true,
                true
            ).slideUp(
                180
            );

            icon.text( '+' );
            label.text( 'مشاهده متن' );

        } else {

            text.stop(
                true,
                true
            ).slideDown(
                220
            );

            icon.text( '−' );
            label.text( 'بستن متن' );

        }

    }
);