مدیاویکی: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' | |||
); | |||
/* | |||
* اگر پاسخ صحیح قبلاً انتخاب شده، | |||
* تست تمام شده است. | |||
*/ | |||
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' | |||
.addClass( | |||
'wd- | |||
); | ); | ||
} | |||
/* | /* | ||
* | * ================================================= | ||
* پاسخ غلط | |||
* ================================================= | |||
*/ | */ | ||
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- | '.wd-version-toggle-label' | ||
); | ); | ||
/* | |||
. | * بستن متن | ||
' | */ | ||
if ( | |||
text.is( | |||
':visible' | |||
) | ) | ||
. | ) { | ||
' | |||
) | 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-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' | |||
); | ); | ||
icon.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(
'بستن سوابق'
);
}
}
);
} );