مدیاویکی:Common.js: تفاوت میان نسخهها
پرش به ناوبری
پرش به جستجو
بدون خلاصۀ ویرایش |
بدون خلاصۀ ویرایش |
||
| خط ۱: | خط ۱: | ||
$( function () { | $( function () { | ||
$( document ).on( 'click', '.wd-test- | /* | ||
* تبدیل گزینههای معمولی لیست به گزینههای قابل کلیک | |||
*/ | |||
$( '.wd-test-options' ).each( function () { | |||
var container = $( this ); | |||
container.find( 'li' ).each( function () { | |||
var option = $( this ); | |||
option.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 retry = box.find( '.wd-test-retry' ); | |||
/* | |||
* تشخیص گزینه بر اساس حرف الف / ب / ج / د | |||
*/ | |||
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( '✕ پاسخ شما نادرست است.' ); | |||
answerBox.hide(); | |||
retry.show(); | |||
} | |||
} ); | |||
/* | |||
* دوباره تلاش کن | |||
*/ | |||
$( document ).on( 'click', '.wd-test-retry-button', function () { | |||
var button = $( this ); | var button = $( this ); | ||
var box = button.closest( '.wd-test' ); | var box = button.closest( '.wd-test' ); | ||
box.removeClass( 'wd-test-finished' ); | |||
box.find( '.wd-test-option' ) | |||
.removeClass( 'wd-selected wd-correct wd-wrong' ); | |||
box.find( '.wd-test-result' ).hide(); | |||
box.find( '.wd-test-answer' ).hide(); | |||
box.find( '.wd-test-retry' ).hide(); | |||
box.find( '.wd-test-result-message' ) | |||
.removeClass( 'wd-result-correct wd-result-wrong' ) | |||
.text( '' ); | |||
} ); | } ); | ||
} ); | } ); | ||
نسخهٔ ۱۰ سپتامبر ۲۰۲۶، ساعت ۱۲:۳۸
$( function () {
/*
* تبدیل گزینههای معمولی لیست به گزینههای قابل کلیک
*/
$( '.wd-test-options' ).each( function () {
var container = $( this );
container.find( 'li' ).each( function () {
var option = $( this );
option.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 retry = box.find( '.wd-test-retry' );
/*
* تشخیص گزینه بر اساس حرف الف / ب / ج / د
*/
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( '✕ پاسخ شما نادرست است.' );
answerBox.hide();
retry.show();
}
} );
/*
* دوباره تلاش کن
*/
$( document ).on( 'click', '.wd-test-retry-button', function () {
var button = $( this );
var box = button.closest( '.wd-test' );
box.removeClass( 'wd-test-finished' );
box.find( '.wd-test-option' )
.removeClass( 'wd-selected wd-correct wd-wrong' );
box.find( '.wd-test-result' ).hide();
box.find( '.wd-test-answer' ).hide();
box.find( '.wd-test-retry' ).hide();
box.find( '.wd-test-result-message' )
.removeClass( 'wd-result-correct wd-result-wrong' )
.text( '' );
} );
} );