پرش به محتوا

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

از ویکی داد
بدون خلاصۀ ویرایش
برچسب: برگردانده‌شده
بدون خلاصۀ ویرایش
 
(۱۷ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد)
خط ۱: خط ۱:
$( function () {
(function () {


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


    'use strict';


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


     $( '.wd-test-options' ).each( function () {
     /* =========================================================
      ابزارهای کمکی
      ========================================================= */


        var container = $( this );
    function getTestOptions(test) {


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


             $( this ).addClass( 'wd-test-option' );
             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 () {
    * -----------------------------------------------------
    * انتخاب گزینه
    * -----------------------------------------------------
    */


    $( document ).on( 'click', '.wd-test-option', function () {
            return $(this).closest('.wd-test')[0] === test[0];


         var option = $( this );
         }).first();


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


    function normalizeAnswer(value) {
        value = $.trim(value || '');


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


         if ( box.hasClass( 'wd-test-finished' ) ) {
         if (match) {
             return;
             return match[1];
         }
         }


        return value.charAt(0);


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


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


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


        /*
    function initWikidadTests() {
        * متن گزینه انتخاب‌شده
        */


         var selectedText = $.trim(
         $('.wd-test').each(function () {
            option.text()
        );


            var test = $(this);


        /*
            if (test.hasClass('wd-test-ready')) {
        * عناصر نتیجه
                return;
        */
            }


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


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


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




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


        var selectedLetter = '';
                options.prop('disabled', true);


                return;


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


            selectedLetter = 'الف';


        } else if (
            /*
             selectedText.indexOf( 'ب' ) === 0
            * طراحی پایه گزینه‌ها
        ) {
            *
            * رنگ‌ها مطابق طراحی ماده ۱۵
            */
             options.css({


            selectedLetter = 'ب';
                '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'


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


            selectedLetter = 'ج';


        } else if (
            /*
             selectedText.indexOf( 'د' ) === 0
            * نتیجه در شروع مخفی باشد.
        ) {
            */
             var result = getTestResult(test);


             selectedLetter = 'د';
             result.css({


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


            });


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


        var correctLetter = answer
            /*
            .replace( 'گزینه', '' )
            * پاسخ و تحلیل در شروع مخفی باشد.
            .replace( ':', '' )
            */
             .trim();
             var answer = getTestAnswer(test);


            answer.css({


        /*
                'display': 'none',
        * ثبت انتخاب کاربر
                'visibility': 'hidden',
        */
                'opacity': '0'


        option.addClass(
             });
             'wd-selected'
        );


        });


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


        result.show();


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


        /*
    $(document).ready(function () {
        * =================================================
        * پاسخ صحیح
        * =================================================
        */


         if (
         initWikidadTests();
            selectedLetter === correctLetter
        ) {


            option.addClass(
    });
                'wd-correct'
            );




            message
    /* =========================================================
                .removeClass(
      افکت ساده هنگام قرار گرفتن موس روی گزینه
                    'wd-result-wrong'
      ========================================================= */
                )
                .addClass(
                    'wd-result-correct'
                )
                .text(
                    '✓ پاسخ شما صحیح است.'
                );


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


             /*
             var option = $(this);
            * نمایش پاسخ و تحلیل
            */


             answerBox
             if (option.prop('disabled')) {
                .stop(
                 return;
                    true,
            }
                    true
                )
                 .slideDown(
                    250
                );


            option.css({


            /*
                'background': '#faf8fc',
            * پایان تست
                'border-color': '#cfc4d9',
            */
                'box-shadow': '0 1px 3px rgba(80,60,90,.06)'


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


         }
         }
    );




         /*
    $(document).on(
        * =================================================
         'mouseleave',
        * پاسخ غلط
        '.wd-test:not(.wd-test-finished) .wd-test-option',
        * =================================================
        function () {
        */


        else {
             var option = $(this);
 
             option.addClass(
                'wd-wrong'
            );


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


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


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


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


         }
         }
    );


    });


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


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


/* =========================================================
            event.preventDefault();
  ویکی‌داد — منوی موبایل
            event.stopPropagation();
  ========================================================= */




/* ---------------------------------------------------------
            var option = $(this);
  منوی موبایل در حالت عادی مخفی است
  --------------------------------------------------------- */


.wd-mobile-menu {
            var test = option.closest('.wd-test');
    display: none;
}




/* =========================================================
            /*
  فقط موبایل
            * تست معتبر نیست.
  ========================================================= */
            */
            if (!test.length) {
                return;
            }


@media screen and (max-width: 767px) {


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


    .wd-mobile-menu {
        display: block;


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


        margin: 0 0 18px 0;


        direction: rtl;
            /*
        text-align: right;
            * گزینه‌های همین تست
            */
            var options = getTestOptions(test);


        font-family:
            "Vazirmatn",
            "IRANSans",
            Tahoma,
            Arial,
            sans-serif;
    }


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


    /* -----------------------------------------------------
      دکمه منو
      ----------------------------------------------------- */


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


        align-items: center;
                var optionContainer =
        justify-content: space-between;
                    option.closest('.wd-test-options');


        width: 100%;
                correctAnswer = normalizeAnswer(
                    optionContainer.attr('data-correct') || ''
                );


        min-height: 48px;
            }


        padding: 10px 15px;


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


        border: 1px solid #dfe7e5;
        border-right: 4px solid #168477;


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


        color: #11695f;
                selectedAnswer = normalizeAnswer(
                    option.text()
                );


        font-size: 15px;
            }
        font-weight: bold;


        line-height: 1.8;


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


        box-shadow:
            0 2px 10px rgba(20,60,55,0.05);


        transition:
            /*
            background 0.15s ease,
            * نتیجه و پاسخ همین تست
             border-color 0.15s ease;
            */
    }
             var result = getTestResult(test);


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


    .wd-mobile-menu-button:hover,
            var answer = getTestAnswer(test);
    .wd-mobile-menu-button:focus {
        background: #f5faf8;
        border-color: #168477;
        outline: none;
    }




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


    .wd-mobile-menu-icon {
            options.css({
        display: inline-flex;


        align-items: center;
                'background': '#ffffff',
        justify-content: center;
                'border-color': '#d9dfdc',
                'color': '#455a64',
                'font-weight': 'normal',
                'box-shadow': 'none'


        width: 32px;
            });
        height: 32px;


        margin-left: 8px;


        background: #edf7f4;
            /* =================================================
              مشخص کردن گزینه انتخاب‌شده
              ================================================= */


        border-radius: 7px;
            if (isCorrect) {


        color: #168477;
                option.css({


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


                });


    /* فلش */
            }


    .wd-mobile-menu-arrow {
            else {
        font-size: 15px;


        color: #78909c;
                option.css({


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


                });


    .wd-mobile-menu.is-open
    .wd-mobile-menu-arrow {
        transform: rotate(180deg);
    }


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


    /* -----------------------------------------------------
                    var item = $(this);
      محتوای منو
      ----------------------------------------------------- */


    .wd-mobile-menu-content {
                    var itemAnswer =
        display: none;
                        normalizeAnswer(
                            item.attr('data-option') || ''
                        );


        margin-top: 7px;


        padding: 7px;
                    if (!itemAnswer) {


        background: #ffffff;
                        itemAnswer =
                            normalizeAnswer(
                                item.text()
                            );


        border: 1px solid #dfe7e5;
                    }


        border-radius: 9px;


        box-shadow:
                    if (itemAnswer === correctAnswer) {
            0 4px 16px rgba(20,60,55,0.07);
    }


                        item.css({


    .wd-mobile-menu.is-open
                            'background': '#edf8f5',
    .wd-mobile-menu-content {
                            'border-color': '#527d77',
        display: block;
                            'color': '#405b56',
    }
                            'font-weight': 'bold',
                            'box-shadow':
                                '0 1px 3px rgba(82,125,119,.10)'


                        });


    /* -----------------------------------------------------
                    }
      لینک‌های منو
      ----------------------------------------------------- */


    .wd-mobile-menu-content a {
                });
        display: block;


        width: 100%;
            }


        padding: 11px 13px;


        margin: 2px 0;
            /* =================================================
              نمایش پیام نتیجه
              ================================================= */


        border-radius: 7px;
            result.css({


        color: #37474f !important;
                'display': 'block',
                'visibility': 'visible',
                'opacity': '1',
                'padding': '10px 13px',
                'border-radius': '6px'


        font-size: 15px;
            });


        font-weight: normal;


        line-height: 1.8;
            if (isCorrect) {


        text-decoration: none !important;
                result.css({


        transition:
                    'background': '#edf8f5',
            background 0.15s ease,
                    'border-right': '3px solid #527d77'
            color 0.15s ease;
    }


                });


    .wd-mobile-menu-content a:hover,
    .wd-mobile-menu-content a:focus {
        background: #f1f8f6;


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


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


    /* -----------------------------------------------------
                    });
      لینک فعال
      ----------------------------------------------------- */


    .wd-mobile-menu-content a.wd-mobile-active {
            }
        background: #edf7f4;


        color: #11695f !important;
            else {


        font-weight: bold;
                result.css({
    }


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


    /* -----------------------------------------------------
                });
      جداکننده
      ----------------------------------------------------- */


    .wd-mobile-menu-divider {
        height: 1px;


        margin: 7px 10px;
                resultMessage
                    .text('✕ پاسخ شما نادرست است.')
                    .css({


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


                    });


    /* -----------------------------------------------------
            }
      گروه اصلی
      ----------------------------------------------------- */


    .wd-mobile-menu-title {
        padding: 7px 13px 5px;


        color: #78909c;
            /* =================================================
              نمایش پاسخ صحیح و تحلیل
              ================================================= */


        font-size: 11px;
            if (answer.length) {


        font-weight: bold;
                answer.css({


        line-height: 1.8;
                    'display': 'block',
    }
                    'visibility': 'visible',
                    'opacity': '1'


}
                });


/* =========================================================
            }
  ویکی‌داد — منوی موبایل
  ========================================================= */


$( function () {


    /*
            /* =================================================
    * -----------------------------------------------------
              قفل کردن همه گزینه‌های همین تست
    * فقط در موبایل منو ساخته می‌شود
              ================================================= */
    * -----------------------------------------------------
    */


    if ( window.innerWidth > 767 ) {
            options.prop('disabled', true);
        return;
    }


            options.css({


    /*
                'cursor': 'default'
    * اگر منو قبلاً ساخته شده، دوباره نساز
    */


    if ( $( '.wd-mobile-menu' ).length ) {
            });
        return;
    }




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


    var menu = $(
        '<div class="wd-mobile-menu">' +


             '<button type="button" ' +
             /*
                'class="wd-mobile-menu-button" ' +
            * ثبت وضعیت روی خود option container
                 'aria-expanded="false">' +
            */
            test.find('.wd-test-options').first()
                 .attr('data-answered', 'true');


                '<span style="display:flex;align-items:center;">' +


                    '<span class="wd-mobile-menu-icon">☰</span>' +
        }
    );


                    '<span>منوی ویکی‌داد</span>' +


                '</span>' +
    /* =========================================================
      مشاهده / بستن متن نسخه قانون
      ========================================================= */


                '<span class="wd-mobile-menu-arrow">▼</span>' +
    $(document).on(
        'click',
        '.wd-version-toggle',
        function () {


             '</button>' +
             var button = $(this);


             '<div class="wd-mobile-menu-content">' +
             var card = button.closest(
                '.wd-version-history-card'
            );


                 '<div class="wd-mobile-menu-title">' +
            var text = card.find(
                    'دسترسی سریع' +
                 '.wd-version-text'
                '</div>' +
            );


                '<a href="/صفحه_اصلی">' +
            var icon = button.find(
                    'صفحه اصلی' +
                '.wd-version-toggle-icon'
                '</a>' +
            );


                '<a href="/قوانین_و_مقررات">' +
            var label = button.find(
                    'قوانین و مقررات' +
                '.wd-version-toggle-label'
                '</a>' +
            );


                '<a href="/آراء_قضایی">' +
                    'آراء قضایی' +
                '</a>' +


                '<a href="/نظریات_مشورتی">' +
            if (text.is(':visible')) {
                    'نظریات مشورتی' +
                '</a>' +


                 '<a href="/اصطلاحات_حقوقی">' +
                 text.stop(true, true)
                     'اصطلاحات حقوقی' +
                     .slideUp(180);
                '</a>' +


                 '<a href="/آزمون‌های_حقوقی">' +
                 icon.text('+');
                    'آزمون‌های حقوقی' +
                '</a>' +


                 '<div class="wd-mobile-menu-divider"></div>' +
                 label.text('مشاهده متن');


                '<div class="wd-mobile-menu-title">' +
            }
                    'قوانین پرکاربرد' +
                '</div>' +


                '<a href="/قانون_کار">' +
            else {
                    'قانون کار' +
                '</a>' +


                 '<a href="/قانون_مدنی">' +
                 text.stop(true, true)
                     'قانون مدنی' +
                     .slideDown(220);
                '</a>' +


                 '<a href="/قانون_تأمین_اجتماعی">' +
                 icon.text('−');
                    'قانون تأمین اجتماعی' +
                '</a>' +


                 '<a href="/قانون_مدیریت_خدمات_کشوری">' +
                 label.text('بستن متن');
                    'قانون مدیریت خدمات کشوری' +
                '</a>' +


             '</div>' +
             }


         '</div>'
         }
     );
     );




    /*
})();
    * -----------------------------------------------------
    * محل قرارگیری منو
    *
    * بعد از Header و قبل از محتوای صفحه
    * -----------------------------------------------------
    */


    var target =
/* =========================================================
        $( '#content' ).first();
  WIKIDAD — Persian / Arabic / English digit normalization
  در جستجوی ویکی‌داد
  1 ↔ ١ ↔ ۱
  ========================================================= */


    if ( target.length ) {
(function () {


         target.prepend( menu );
    function toPersianDigits(value) {
         if (!value) {
            return value;
        }


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


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




     /*
     function normalizeSearchInput(input) {
    * -----------------------------------------------------
         if (!input || typeof input.value !== 'string') {
    * باز و بسته کردن منو
            return;
    * -----------------------------------------------------
         }
    */
 
    $( document ).on(
         'click',
        '.wd-mobile-menu-button',
         function () {


            var button = $( this );
        var normalized = toPersianDigits(input.value);


            var container =
        if (normalized !== input.value) {
                button.closest(
            input.value = normalized;
                    '.wd-mobile-menu'
                );


             var isOpen =
             /* برای سیستم‌های autocomplete */
                container.hasClass(
            input.dispatchEvent(new Event('input', {
                    'is-open'
                 bubbles: true
                 );
            }));
        }
    }




            if ( isOpen ) {
    function attachSearchNormalization() {


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


                button.attr(
        inputs.forEach(function (input) {
                    'aria-expanded',
                    'false'
                );


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


                container.addClass(
            input.dataset.wikidadDigitNormalized = '1';
                    'is-open'
                );


                button.attr(
            /* هنگام تایپ یا Paste */
                    'aria-expanded',
            input.addEventListener('input', function () {
                    'true'
                normalizeSearchInput(input);
                );
            });


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


        }
    );


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


    /*
    * -----------------------------------------------------
    * بعد از انتخاب لینک، منو بسته شود
    * -----------------------------------------------------
    */


     $( document ).on(
     /* برای Vector 2022 که بعضی عناصر را بعداً می‌سازد */
        'click',
    document.addEventListener('focusin', function (event) {
        '.wd-mobile-menu-content a',
        function () {


            $( this )
        var input = event.target;
                .closest(
                    '.wd-mobile-menu'
                )
                .removeClass(
                    'is-open'
                );


        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);
        }
    });

})();