پرش به محتوا

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

از ویکی داد
بدون خلاصۀ ویرایش
بدون خلاصۀ ویرایش
 
(۱۲ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد)
خط ۱: خط ۱:
/* =========================================================
(function () {
  سیستم تست‌های تعاملی ویکی‌داد
 
  ========================================================= */
    /* =========================================================
      سیستم تست‌های تعاملی ویکی‌داد
      نسخه مرکزی — هماهنگ با Master ماده ۱۵
      ========================================================= */
 
    'use strict';
 
 
    /* =========================================================
      ابزارهای کمکی
      ========================================================= */
 
    function getTestOptions(test) {
 
        return test.find('.wd-test-option').filter(function () {
 
            return $(this).closest('.wd-test')[0] === test[0];
 
        });
 
    }
 
 
    function getTestResult(test) {
 
        return test.find('.wd-test-result').filter(function () {
 
            return $(this).closest('.wd-test')[0] === test[0];
 
        }).first();
 
    }


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


        var option = $( this );
    function getTestAnswer(test) {
        var test = option.closest( '.wd-test' );


         /* اگر تست قبلاً پاسخ داده شده، کاری نکن */
         return test.find('.wd-test-answer').filter(function () {
        if ( test.hasClass( 'wd-test-finished' ) ) {
            return;
        }


        /* گزینه انتخاب‌شده */
            return $(this).closest('.wd-test')[0] === test[0];
        var selectedText = $.trim( option.text() );


         /* پاسخ صحیح */
         }).first();
        var correctAnswer = $.trim(
            test.attr( 'data-answer' ) || ''
        );


        /* حذف حالت انتخاب قبلی */
    }
        test.find( '.wd-test-options li' )
            .removeClass( 'wd-test-selected' );


        /* ثبت انتخاب */
        option.addClass( 'wd-test-selected' );


        /* نمایش نتیجه */
    function normalizeAnswer(value) {
        var result = test.find( '.wd-test-result' );
        var resultMessage = test.find( '.wd-test-result-message' );


         /* پاسخ صحیح یا غلط */
         value = $.trim(value || '');
        var isCorrect = false;


         /*
         /*
         * پاسخ قالب معمولاً به شکل:
         * پاسخ می‌تواند مستقیماً «الف» باشد
         * الف
         * یا در بعضی شرایط با فاصله/نشانه همراه باشد.
        * ب
        * ج
        * د
        *
        * بنابراین ابتدا حرف گزینه را استخراج می‌کنیم.
         */
         */
         var selectedLetter = selectedText
         var match = value.match(
             .replace( /^[\s‏‌]*([الفبجد])[\s\)\.:\-ـ]*/i, '$1' );
             /^(الف|ب|ج|د|ه|هـ|و)/
        );


         if ( selectedLetter === selectedText ) {
         if (match) {
             selectedLetter = selectedText.charAt( 0 );
             return match[1];
         }
         }


         var answerLetter = correctAnswer
         return value.charAt(0);
             .replace( /^[\s‏‌]*([الفبجد])[\s\)\.:\-ـ]*/i, '$1' );
 
    }
 
 
    /* =========================================================
      آماده‌سازی تست‌ها
      ========================================================= */
 
    function initWikidadTests() {
 
        $('.wd-test').each(function () {
 
            var test = $(this);
 
            if (test.hasClass('wd-test-ready')) {
                return;
             }
 
            test.addClass('wd-test-ready');
 
 
            var options = getTestOptions(test);
 
 
            /*
            * اگر تست قبلاً پاسخ داده شده باشد،
            * وضعیت را حفظ می‌کنیم.
            */
            if (test.hasClass('wd-test-finished')) {
 
                options.prop('disabled', true);
 
                return;
 
            }
 
 
            /*
            * طراحی پایه گزینه‌ها
            *
            * رنگ‌ها مطابق طراحی ماده ۱۵
            */
            options.css({
 
                'display': 'block',
                'width': '100%',
                'box-sizing': 'border-box',
                'padding': '10px 13px',
                'margin': '7px 0',
                'border': '1px solid #d9dfdc',
                'border-radius': '6px',
                'background': '#ffffff',
                'color': '#455a64',
                'cursor': 'pointer',
                'font-family': 'inherit',
                'font-size': '13.5px',
                'line-height': '1.9',
                'text-align': 'right',
                'direction': 'rtl',
                'transition':
                    'background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease'
 
            });
 
 
            /*
            * نتیجه در شروع مخفی باشد.
            */
            var result = getTestResult(test);
 
            result.css({
 
                'display': 'none',
                'visibility': 'hidden',
                'opacity': '0'
 
            });
 
 
            /*
            * پاسخ و تحلیل در شروع مخفی باشد.
            */
            var answer = getTestAnswer(test);
 
            answer.css({
 
                'display': 'none',
                'visibility': 'hidden',
                'opacity': '0'
 
            });
 
        });
 
    }
 
 
    /* =========================================================
      اجرای آماده‌سازی
      ========================================================= */
 
    $(document).ready(function () {
 
        initWikidadTests();
 
    });
 
 
    /* =========================================================
      افکت ساده هنگام قرار گرفتن موس روی گزینه
      ========================================================= */
 
    $(document).on(
        'mouseenter',
        '.wd-test:not(.wd-test-finished) .wd-test-option',
        function () {
 
            var option = $(this);
 
            if (option.prop('disabled')) {
                return;
            }
 
            option.css({
 
                'background': '#faf8fc',
                'border-color': '#cfc4d9',
                'box-shadow': '0 1px 3px rgba(80,60,90,.06)'
 
            });
 
        }
    );
 
 
    $(document).on(
        'mouseleave',
        '.wd-test:not(.wd-test-finished) .wd-test-option',
        function () {
 
            var option = $(this);
 
            if (option.prop('disabled')) {
                return;
            }
 
            option.css({
 
                'background': '#ffffff',
                'border-color': '#d9dfdc',
                'box-shadow': 'none'
 
            });


        if ( answerLetter === correctAnswer ) {
            answerLetter = correctAnswer.charAt( 0 );
         }
         }
    );
    /* =========================================================
      کلیک روی گزینه
      ========================================================= */
    $(document).on(
        'click',
        '.wd-test-option',
        function (event) {
            event.preventDefault();
            event.stopPropagation();
            var option = $(this);
            var test = option.closest('.wd-test');
            /*
            * تست معتبر نیست.
            */
            if (!test.length) {
                return;
            }
            /*
            * اگر قبلاً پاسخ داده شده،
            * دیگر امکان تغییر پاسخ وجود ندارد.
            */
            if (test.hasClass('wd-test-finished')) {
                return;
            }
            /*
            * جلوگیری از چندبار کلیک سریع
            */
            if (option.prop('disabled')) {
                return;
            }
            /*
            * گزینه‌های همین تست
            */
            var options = getTestOptions(test);
            /*
            * پاسخ صحیح از data-answer الگوی تست
            */
            var correctAnswer = normalizeAnswer(
                test.attr('data-answer') || ''
            );
            /*
            * اگر data-answer خالی بود،
            * از data-correct خود گزینه‌ها استفاده می‌کنیم.
            *
            * این fallback باعث می‌شود ساختار جدید
            * Python نیز مستقیماً قابل استفاده باشد.
            */
            if (!correctAnswer) {
                var optionContainer =
                    option.closest('.wd-test-options');
                correctAnswer = normalizeAnswer(
                    optionContainer.attr('data-correct') || ''
                );
            }
            /*
            * پاسخ انتخاب‌شده
            */
            var selectedAnswer = normalizeAnswer(
                option.attr('data-option') || ''
            );


        isCorrect =
            $.trim( selectedLetter ) ===
            $.trim( answerLetter );


        /* نمایش نتیجه */
            /*
        result.show();
            * اگر data-option وجود نداشت،
            * از متن گزینه استخراج شود.
            */
            if (!selectedAnswer) {


        if ( isCorrect ) {
                selectedAnswer = normalizeAnswer(
                    option.text()
                );
 
            }
 
 
            /*
            * تعیین درست / غلط
            */
            var isCorrect =
                selectedAnswer === correctAnswer;
 
 
            /*
            * نتیجه و پاسخ همین تست
            */
            var result = getTestResult(test);
 
            var resultMessage =
                result.find('.wd-test-result-message').first();
 
            var answer = getTestAnswer(test);
 
 
            /* =================================================
              پاک کردن وضعیت قبلی گزینه‌ها
              ================================================= */
 
            options.css({
 
                'background': '#ffffff',
                'border-color': '#d9dfdc',
                'color': '#455a64',
                'font-weight': 'normal',
                'box-shadow': 'none'
 
            });
 
 
            /* =================================================
              مشخص کردن گزینه انتخاب‌شده
              ================================================= */
 
            if (isCorrect) {
 
                option.css({
 
                    'background': '#edf8f5',
                    'border-color': '#527d77',
                    'color': '#405b56',
                    'font-weight': 'bold',
                    'box-shadow': '0 1px 3px rgba(82,125,119,.10)'


            resultMessage
                .text( '✓ پاسخ شما صحیح است.' )
                .css({
                    color: '#168477'
                 });
                 });


             option.addClass( 'wd-test-correct' );
             }
 
            else {
 
                option.css({


        } else {
                    'background': '#fff2f2',
                    'border-color': '#b44a4a',
                    'color': '#9b3838',
                    'font-weight': 'bold',
                    'box-shadow': '0 1px 3px rgba(180,74,74,.10)'


            resultMessage
                .text( '✕ پاسخ شما نادرست است.' )
                .css({
                    color: '#b44a4a'
                 });
                 });


            option.addClass( 'wd-test-wrong' );


            /*
                /*
            * مشخص کردن گزینه صحیح
                * پاسخ صحیح را نیز پیدا و سبز می‌کنیم.
            */
                */
            test.find( '.wd-test-options li' ).each(
                options.each(function () {
                function () {


                     var item = $( this );
                     var item = $(this);
                    var itemText = $.trim( item.text() );


                     var itemLetter = itemText
                     var itemAnswer =
                         .replace(
                         normalizeAnswer(
                             /^[\s‏‌]*([الفبجد])[\s\)\.:\-ـ]*/i,
                             item.attr('data-option') || ''
                            '$1'
                         );
                         );


                     if ( itemLetter === itemText ) {
 
                         itemLetter = itemText.charAt( 0 );
                     if (!itemAnswer) {
 
                         itemAnswer =
                            normalizeAnswer(
                                item.text()
                            );
 
                     }
                     }


                     if (
 
                        $.trim( itemLetter ) ===
                     if (itemAnswer === correctAnswer) {
                        $.trim( answerLetter )
 
                    ) {
                         item.css({
                         item.addClass( 'wd-test-correct' );
 
                            'background': '#edf8f5',
                            'border-color': '#527d77',
                            'color': '#405b56',
                            'font-weight': 'bold',
                            'box-shadow':
                                '0 1px 3px rgba(82,125,119,.10)'
 
                        });
 
                     }
                     }


                 }
                 });
 
            }
 
 
            /* =================================================
              نمایش پیام نتیجه
              ================================================= */
 
            result.css({
 
                'display': 'block',
                'visibility': 'visible',
                'opacity': '1',
                'padding': '10px 13px',
                'border-radius': '6px'
 
            });
 
 
            if (isCorrect) {
 
                result.css({
 
                    'background': '#edf8f5',
                    'border-right': '3px solid #527d77'
 
                });
 
 
                resultMessage
                    .text('✓ پاسخ شما صحیح است.')
                    .css({
 
                        'display': 'block',
                        'visibility': 'visible',
                        'opacity': '1',
                        'color': '#527d77',
                        'font-weight': 'bold'
 
                    });
 
            }
 
            else {
 
                result.css({
 
                    'background': '#fff5f5',
                    'border-right': '3px solid #b44a4a'
 
                });
 
 
                resultMessage
                    .text('✕ پاسخ شما نادرست است.')
                    .css({
 
                        'display': 'block',
                        'visibility': 'visible',
                        'opacity': '1',
                        'color': '#b44a4a',
                        'font-weight': 'bold'
 
                    });
 
            }
 
 
            /* =================================================
              نمایش پاسخ صحیح و تحلیل
              ================================================= */
 
            if (answer.length) {
 
                answer.css({
 
                    'display': 'block',
                    'visibility': 'visible',
                    'opacity': '1'
 
                });
 
            }
 
 
            /* =================================================
              قفل کردن همه گزینه‌های همین تست
              ================================================= */
 
            options.prop('disabled', true);
 
            options.css({
 
                'cursor': 'default'
 
            });
 
 
            /*
            * علامت پایان تست
            */
            test
                .addClass('wd-test-finished')
                .attr('data-answered', 'true');
 
 
            /*
            * ثبت وضعیت روی خود option container
            */
            test.find('.wd-test-options').first()
                .attr('data-answered', 'true');
 
 
        }
    );
 
 
    /* =========================================================
      مشاهده / بستن متن نسخه قانون
      ========================================================= */
 
    $(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('بستن متن');
            }


         }
         }
    );
})();
/* =========================================================
  WIKIDAD — Persian / Arabic / English digit normalization
  در جستجوی ویکی‌داد
  1 ↔ ١ ↔ ۱
  ========================================================= */
(function () {


        /* نمایش پاسخ و تحلیل */
    function toPersianDigits(value) {
        test.find( '.wd-test-answer' )
        if (!value) {
            .stop( true, true )
             return value;
             .slideDown( 220 );
        }


         /* جلوگیری از انتخاب مجدد */
         return value
        test.addClass( 'wd-test-finished' );
            /* English digits → Persian */
            .replace(/[0-9]/g, function (digit) {
                return '۰۱۲۳۴۵۶۷۸۹'[Number(digit)];
            })


            /* Arabic-Indic digits → Persian */
            .replace(/[٠-٩]/g, function (digit) {
                return '۰۱۲۳۴۵۶۷۸۹'[digit.charCodeAt(0) - 0x0660];
            });
     }
     }
);




/* =========================================================
    function normalizeSearchInput(input) {
  مشاهده / بستن متن نسخه قانون
        if (!input || typeof input.value !== 'string') {
  ========================================================= */
            return;
        }
 
        var normalized = toPersianDigits(input.value);
 
        if (normalized !== input.value) {
            input.value = normalized;


$( document ).on(
            /* برای سیستم‌های autocomplete */
    'click',
            input.dispatchEvent(new Event('input', {
    '.wd-version-toggle',
                bubbles: true
     function () {
            }));
        }
     }


        var button = $( this );


        var card = button.closest(
    function attachSearchNormalization() {
            '.wd-version-history-card'
        );


         var text = card.find(
         var inputs = document.querySelectorAll(
             '.wd-version-text'
             'input[name="search"],' +
            'input[type="search"],' +
            '#searchInput,' +
            '#mw-searchInput'
         );
         );


         var icon = button.find(
         inputs.forEach(function (input) {
            '.wd-version-toggle-icon'
        );


        var label = button.find(
            if (input.dataset.wikidadDigitNormalized === '1') {
            '.wd-version-toggle-label'
                return;
        );
            }


        if ( text.is( ':visible' ) ) {
            input.dataset.wikidadDigitNormalized = '1';


             text.stop( true, true )
             /* هنگام تایپ یا Paste */
                 .slideUp( 180 );
            input.addEventListener('input', function () {
                 normalizeSearchInput(input);
            });


             icon.text( '+' );
             /* قبل از ارسال فرم */
            input.addEventListener('blur', function () {
                normalizeSearchInput(input);
            });
        });
    }


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


        } else {
    /* بارگذاری اولیه */
    attachSearchNormalization();


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


            icon.text( '−' );
    /* برای Vector 2022 که بعضی عناصر را بعداً می‌سازد */
    document.addEventListener('focusin', function (event) {


            label.text( 'بستن متن' );
        var input = event.target;


        if (
            input &&
            input.matches &&
            input.matches(
                'input[name="search"],' +
                'input[type="search"],' +
                '#searchInput,' +
                '#mw-searchInput'
            )
        ) {
            normalizeSearchInput(input);
         }
         }
    });


    }
})();
);

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

(function () {

    /* =========================================================
       سیستم تست‌های تعاملی ویکی‌داد
       نسخه مرکزی — هماهنگ با Master ماده ۱۵
       ========================================================= */

    'use strict';


    /* =========================================================
       ابزارهای کمکی
       ========================================================= */

    function getTestOptions(test) {

        return test.find('.wd-test-option').filter(function () {

            return $(this).closest('.wd-test')[0] === test[0];

        });

    }


    function getTestResult(test) {

        return test.find('.wd-test-result').filter(function () {

            return $(this).closest('.wd-test')[0] === test[0];

        }).first();

    }


    function getTestAnswer(test) {

        return test.find('.wd-test-answer').filter(function () {

            return $(this).closest('.wd-test')[0] === test[0];

        }).first();

    }


    function normalizeAnswer(value) {

        value = $.trim(value || '');

        /*
         * پاسخ می‌تواند مستقیماً «الف» باشد
         * یا در بعضی شرایط با فاصله/نشانه همراه باشد.
         */
        var match = value.match(
            /^(الف|ب|ج|د|ه|هـ|و)/
        );

        if (match) {
            return match[1];
        }

        return value.charAt(0);

    }


    /* =========================================================
       آماده‌سازی تست‌ها
       ========================================================= */

    function initWikidadTests() {

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

            var test = $(this);

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

            test.addClass('wd-test-ready');


            var options = getTestOptions(test);


            /*
             * اگر تست قبلاً پاسخ داده شده باشد،
             * وضعیت را حفظ می‌کنیم.
             */
            if (test.hasClass('wd-test-finished')) {

                options.prop('disabled', true);

                return;

            }


            /*
             * طراحی پایه گزینه‌ها
             *
             * رنگ‌ها مطابق طراحی ماده ۱۵
             */
            options.css({

                'display': 'block',
                'width': '100%',
                'box-sizing': 'border-box',
                'padding': '10px 13px',
                'margin': '7px 0',
                'border': '1px solid #d9dfdc',
                'border-radius': '6px',
                'background': '#ffffff',
                'color': '#455a64',
                'cursor': 'pointer',
                'font-family': 'inherit',
                'font-size': '13.5px',
                'line-height': '1.9',
                'text-align': 'right',
                'direction': 'rtl',
                'transition':
                    'background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease'

            });


            /*
             * نتیجه در شروع مخفی باشد.
             */
            var result = getTestResult(test);

            result.css({

                'display': 'none',
                'visibility': 'hidden',
                'opacity': '0'

            });


            /*
             * پاسخ و تحلیل در شروع مخفی باشد.
             */
            var answer = getTestAnswer(test);

            answer.css({

                'display': 'none',
                'visibility': 'hidden',
                'opacity': '0'

            });

        });

    }


    /* =========================================================
       اجرای آماده‌سازی
       ========================================================= */

    $(document).ready(function () {

        initWikidadTests();

    });


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

    $(document).on(
        'mouseenter',
        '.wd-test:not(.wd-test-finished) .wd-test-option',
        function () {

            var option = $(this);

            if (option.prop('disabled')) {
                return;
            }

            option.css({

                'background': '#faf8fc',
                'border-color': '#cfc4d9',
                'box-shadow': '0 1px 3px rgba(80,60,90,.06)'

            });

        }
    );


    $(document).on(
        'mouseleave',
        '.wd-test:not(.wd-test-finished) .wd-test-option',
        function () {

            var option = $(this);

            if (option.prop('disabled')) {
                return;
            }

            option.css({

                'background': '#ffffff',
                'border-color': '#d9dfdc',
                'box-shadow': 'none'

            });

        }
    );


    /* =========================================================
       کلیک روی گزینه
       ========================================================= */

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

            event.preventDefault();
            event.stopPropagation();


            var option = $(this);

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


            /*
             * تست معتبر نیست.
             */
            if (!test.length) {
                return;
            }


            /*
             * اگر قبلاً پاسخ داده شده،
             * دیگر امکان تغییر پاسخ وجود ندارد.
             */
            if (test.hasClass('wd-test-finished')) {
                return;
            }


            /*
             * جلوگیری از چندبار کلیک سریع
             */
            if (option.prop('disabled')) {
                return;
            }


            /*
             * گزینه‌های همین تست
             */
            var options = getTestOptions(test);


            /*
             * پاسخ صحیح از data-answer الگوی تست
             */
            var correctAnswer = normalizeAnswer(
                test.attr('data-answer') || ''
            );


            /*
             * اگر data-answer خالی بود،
             * از data-correct خود گزینه‌ها استفاده می‌کنیم.
             *
             * این fallback باعث می‌شود ساختار جدید
             * Python نیز مستقیماً قابل استفاده باشد.
             */
            if (!correctAnswer) {

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

                correctAnswer = normalizeAnswer(
                    optionContainer.attr('data-correct') || ''
                );

            }


            /*
             * پاسخ انتخاب‌شده
             */
            var selectedAnswer = normalizeAnswer(
                option.attr('data-option') || ''
            );


            /*
             * اگر data-option وجود نداشت،
             * از متن گزینه استخراج شود.
             */
            if (!selectedAnswer) {

                selectedAnswer = normalizeAnswer(
                    option.text()
                );

            }


            /*
             * تعیین درست / غلط
             */
            var isCorrect =
                selectedAnswer === correctAnswer;


            /*
             * نتیجه و پاسخ همین تست
             */
            var result = getTestResult(test);

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

            var answer = getTestAnswer(test);


            /* =================================================
               پاک کردن وضعیت قبلی گزینه‌ها
               ================================================= */

            options.css({

                'background': '#ffffff',
                'border-color': '#d9dfdc',
                'color': '#455a64',
                'font-weight': 'normal',
                'box-shadow': 'none'

            });


            /* =================================================
               مشخص کردن گزینه انتخاب‌شده
               ================================================= */

            if (isCorrect) {

                option.css({

                    'background': '#edf8f5',
                    'border-color': '#527d77',
                    'color': '#405b56',
                    'font-weight': 'bold',
                    'box-shadow': '0 1px 3px rgba(82,125,119,.10)'

                });

            }

            else {

                option.css({

                    'background': '#fff2f2',
                    'border-color': '#b44a4a',
                    'color': '#9b3838',
                    'font-weight': 'bold',
                    'box-shadow': '0 1px 3px rgba(180,74,74,.10)'

                });


                /*
                 * پاسخ صحیح را نیز پیدا و سبز می‌کنیم.
                 */
                options.each(function () {

                    var item = $(this);

                    var itemAnswer =
                        normalizeAnswer(
                            item.attr('data-option') || ''
                        );


                    if (!itemAnswer) {

                        itemAnswer =
                            normalizeAnswer(
                                item.text()
                            );

                    }


                    if (itemAnswer === correctAnswer) {

                        item.css({

                            'background': '#edf8f5',
                            'border-color': '#527d77',
                            'color': '#405b56',
                            'font-weight': 'bold',
                            'box-shadow':
                                '0 1px 3px rgba(82,125,119,.10)'

                        });

                    }

                });

            }


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

            result.css({

                'display': 'block',
                'visibility': 'visible',
                'opacity': '1',
                'padding': '10px 13px',
                'border-radius': '6px'

            });


            if (isCorrect) {

                result.css({

                    'background': '#edf8f5',
                    'border-right': '3px solid #527d77'

                });


                resultMessage
                    .text('✓ پاسخ شما صحیح است.')
                    .css({

                        'display': 'block',
                        'visibility': 'visible',
                        'opacity': '1',
                        'color': '#527d77',
                        'font-weight': 'bold'

                    });

            }

            else {

                result.css({

                    'background': '#fff5f5',
                    'border-right': '3px solid #b44a4a'

                });


                resultMessage
                    .text('✕ پاسخ شما نادرست است.')
                    .css({

                        'display': 'block',
                        'visibility': 'visible',
                        'opacity': '1',
                        'color': '#b44a4a',
                        'font-weight': 'bold'

                    });

            }


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

            if (answer.length) {

                answer.css({

                    'display': 'block',
                    'visibility': 'visible',
                    'opacity': '1'

                });

            }


            /* =================================================
               قفل کردن همه گزینه‌های همین تست
               ================================================= */

            options.prop('disabled', true);

            options.css({

                'cursor': 'default'

            });


            /*
             * علامت پایان تست
             */
            test
                .addClass('wd-test-finished')
                .attr('data-answered', 'true');


            /*
             * ثبت وضعیت روی خود option container
             */
            test.find('.wd-test-options').first()
                .attr('data-answered', 'true');


        }
    );


    /* =========================================================
       مشاهده / بستن متن نسخه قانون
       ========================================================= */

    $(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('بستن متن');

            }

        }
    );


})();

/* =========================================================
   WIKIDAD — Persian / Arabic / English digit normalization
   در جستجوی ویکی‌داد
   1 ↔ ١ ↔ ۱
   ========================================================= */

(function () {

    function toPersianDigits(value) {
        if (!value) {
            return value;
        }

        return value
            /* English digits → Persian */
            .replace(/[0-9]/g, function (digit) {
                return '۰۱۲۳۴۵۶۷۸۹'[Number(digit)];
            })

            /* Arabic-Indic digits → Persian */
            .replace(/[٠-٩]/g, function (digit) {
                return '۰۱۲۳۴۵۶۷۸۹'[digit.charCodeAt(0) - 0x0660];
            });
    }


    function normalizeSearchInput(input) {
        if (!input || typeof input.value !== 'string') {
            return;
        }

        var normalized = toPersianDigits(input.value);

        if (normalized !== input.value) {
            input.value = normalized;

            /* برای سیستم‌های autocomplete */
            input.dispatchEvent(new Event('input', {
                bubbles: true
            }));
        }
    }


    function attachSearchNormalization() {

        var inputs = document.querySelectorAll(
            'input[name="search"],' +
            'input[type="search"],' +
            '#searchInput,' +
            '#mw-searchInput'
        );

        inputs.forEach(function (input) {

            if (input.dataset.wikidadDigitNormalized === '1') {
                return;
            }

            input.dataset.wikidadDigitNormalized = '1';

            /* هنگام تایپ یا Paste */
            input.addEventListener('input', function () {
                normalizeSearchInput(input);
            });

            /* قبل از ارسال فرم */
            input.addEventListener('blur', function () {
                normalizeSearchInput(input);
            });
        });
    }


    /* بارگذاری اولیه */
    attachSearchNormalization();


    /* برای Vector 2022 که بعضی عناصر را بعداً می‌سازد */
    document.addEventListener('focusin', function (event) {

        var input = event.target;

        if (
            input &&
            input.matches &&
            input.matches(
                'input[name="search"],' +
                'input[type="search"],' +
                '#searchInput,' +
                '#mw-searchInput'
            )
        ) {
            normalizeSearchInput(input);
        }
    });

})();