پرش به محتوا

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

از ویکی داد
بدون خلاصۀ ویرایش
بدون خلاصۀ ویرایش
خط ۳: خط ۳:
     /*
     /*
     * =====================================================
     * =====================================================
     * ویکی‌داد — تست‌های تعاملی
     * ویکی‌داد — JavaScript
    * =====================================================
    *
    * 1. تست‌های تعاملی
    * 2. سابقه تقنینی ماده
    * 3. شناسنامه ماده — نمایش سوابق
    *
    * =====================================================
    */
 
 
    /*
    * =====================================================
    * ۱. تست‌های تعاملی
     * =====================================================
     * =====================================================
     */
     */
خط ۲۰: خط ۳۳:
         container.find( 'li' ).each( function () {
         container.find( 'li' ).each( function () {


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


         } );
         } );
خط ۳۳: خط ۴۸:
     */
     */


     $( document ).on( 'click', '.wd-test-option', function () {
     $( document ).on(
        'click',
        '.wd-test-option',
        function () {
 
            var option = $( this );
 
            var box = option.closest(
                '.wd-test'
            );
 
 
            /*
            * اگر پاسخ صحیح قبلاً انتخاب شده،
            * تست تمام شده است.
            */


        var option = $( this );
            if (
                box.hasClass(
                    'wd-test-finished'
                )
            ) {


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


            }


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


        if ( box.hasClass( 'wd-test-finished' ) ) {
            /*
            return;
            * دریافت پاسخ صحیح
        }
            */


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


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


        var answer = $.trim(
            /*
            box.attr( 'data-answer' )
            * متن گزینه انتخاب‌شده
        );
            */


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


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


        var selectedText = $.trim(
            /*
            option.text()
            * عناصر نتیجه
        );
            */


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


        /*
            var message = box.find(
        * عناصر نتیجه
                '.wd-test-result-message'
        */
            );


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


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


        var answerBox = box.find(
            /*
            '.wd-test-answer'
            * تشخیص حرف گزینه
        );
            */


            var selectedLetter = '';


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


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


                selectedLetter = 'الف';


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


            selectedLetter = 'الف';
                selectedLetter = 'ب';


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


            selectedLetter = 'ب';
                selectedLetter = 'ج';


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


            selectedLetter = 'ج';
                selectedLetter = 'د';


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


            selectedLetter = 'د';


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


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


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


        var correctLetter = answer
             /*
             .replace( 'گزینه', '' )
            * ثبت انتخاب کاربر
            .replace( ':', '' )
            */
            .trim();


            option.addClass(
                'wd-selected'
            );


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


        option.addClass(
            /*
            'wd-selected'
            * نمایش پیام نتیجه
        );
            */


            result.show();


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


        result.show();
            /*
            * =================================================
            * پاسخ صحیح
            * =================================================
            */


            if (
                selectedLetter === correctLetter
            ) {


        /*
                option.addClass(
        * =================================================
                    'wd-correct'
        * پاسخ صحیح
                );
        * =================================================
        */


        if (
            selectedLetter === correctLetter
        ) {


            option.addClass(
                message
                'wd-correct'
                    .removeClass(
            );
                        'wd-result-wrong'
                    )
                    .addClass(
                        'wd-result-correct'
                    )
                    .text(
                        '✓ پاسخ شما صحیح است.'
                    );
 
 
                /*
                * نمایش پاسخ و تحلیل
                */
 
                answerBox
                    .stop(
                        true,
                        true
                    )
                    .slideDown(
                        250
                    );
 


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


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




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


             answerBox
             else {
                .stop(
 
                    true,
                 option.addClass(
                    true
                     'wd-wrong'
                )
                 .slideDown(
                     250
                 );
                 );




            /*
                message
            * پایان تست
                    .removeClass(
            */
                        'wd-result-correct'
                    )
                    .addClass(
                        'wd-result-wrong'
                    )
                    .text(
                        '✕ پاسخ شما نادرست است.'
                    );
 
 
                /*
                * عمداً پاسخ صحیح را نمایش نمی‌دهیم.
                *
                * کاربر می‌تواند گزینه دیگری را انتخاب کند.
                */


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


         }
         }
    );
    /*
    * =====================================================
    * ۲. سابقه تقنینی ماده
    * =====================================================
    *
    * دکمه:
    * «مشاهده متن»
    *
    * در کارت:
    * .wd-version-history-card
    *
    * متن:
    * .wd-version-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'
        * پاسخ غلط
            );
        * =================================================
        */


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


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




             message
             /*
                 .removeClass(
            * بستن متن
                     'wd-result-correct'
            */
 
            if (
                 text.is(
                     ':visible'
                 )
                 )
                 .addClass(
            ) {
                     'wd-result-wrong'
 
                 )
                 text
                 .text(
                    .stop(
                     '✕ پاسخ شما نادرست است.'
                        true,
                        true
                    )
                    .slideUp(
                        180
                    );
 
                icon.text(
                     '+'
                 );
 
                 label.text(
                     'مشاهده متن'
                 );
                 );
            }




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


        }
            else {
 
                text
                    .stop(
                        true,
                        true
                    )
                    .slideDown(
                        220
                    );


    });
                icon.text(
                    '−'
                );


} );
                label.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(
    $( document ).on(
            '.wd-version-toggle-label'
        'click',
         );
        '.wd-article-history-toggle',
         function () {


        if ( text.is( ':visible' ) ) {
            var button = $( this );


             text.stop(
             var box = button.closest(
                 true,
                 '.wd-article-metadata'
                true
            ).slideUp(
                180
             );
             );


             icon.text( '+' );
             var history = box.find(
             label.text( 'مشاهده متن' );
                '.wd-article-history-inline'
             );


        } else {
            var icon = button.find(
                '.wd-article-history-toggle-icon'
            );


             text.stop(
             var label = button.find(
                 true,
                 '.wd-article-history-toggle-label'
                true
            ).slideDown(
                220
             );
             );


             icon.text( '−' );
 
            label.text( 'بستن متن' );
            /*
            * بستن سوابق
            */
 
            if (
                history.is(
                    ':visible'
                )
            ) {
 
                history
                    .stop(
                        true,
                        true
                    )
                    .slideUp(
                        180
                    );
 
                icon.text(
                    '+'
                );
 
                label.text(
                    'مشاهده سوابق'
                );
 
             }
 
 
            /*
            * باز کردن سوابق
            */
 
            else {
 
                history
                    .stop(
                        true,
                        true
                    )
                    .slideDown(
                        220
                    );
 
                icon.text(
                    '−'
                );
 
                label.text(
                    'بستن سوابق'
                );
 
            }


         }
         }
    );


    }
} );
);

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

$( function () {

    /*
     * =====================================================
     * ویکی‌داد — JavaScript
     * =====================================================
     *
     * 1. تست‌های تعاملی
     * 2. سابقه تقنینی ماده
     * 3. شناسنامه ماده — نمایش سوابق
     *
     * =====================================================
     */


    /*
     * =====================================================
     * ۱. تست‌های تعاملی
     * =====================================================
     */


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

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


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

            }

        }
    );


    /*
     * =====================================================
     * ۲. سابقه تقنینی ماده
     * =====================================================
     *
     * دکمه:
     * «مشاهده متن»
     *
     * در کارت:
     * .wd-version-history-card
     *
     * متن:
     * .wd-version-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(
                    'بستن متن'
                );

            }

        }
    );


    /*
     * =====================================================
     * ۳. شناسنامه ماده
     * =====================================================
     *
     * دکمه:
     * «مشاهده سوابق»
     *
     * این بخش سوابق تقنینی را مستقیماً
     * داخل همان شناسنامه باز و بسته می‌کند.
     *
     * =====================================================
     */


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

            var button = $( this );

            var box = button.closest(
                '.wd-article-metadata'
            );

            var history = box.find(
                '.wd-article-history-inline'
            );

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

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


            /*
             * بستن سوابق
             */

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

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

                icon.text(
                    '+'
                );

                label.text(
                    'مشاهده سوابق'
                );

            }


            /*
             * باز کردن سوابق
             */

            else {

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

                icon.text(
                    '−'
                );

                label.text(
                    'بستن سوابق'
                );

            }

        }
    );

} );