مستخدم:HaithamS (WMF)/Gadget-teahouse.js
ملاحظة: بعد النشر، أنت قد تحتاج إلى إفراغ الكاش الخاص بمتصفحك لرؤية التغييرات.
- فايرفوكس / سافاري: أمسك Shift أثناء ضغط Reload، أو اضغط على إما Ctrl-F5 أو Ctrl-R (⌘-R على ماك)
- جوجل كروم: اضغط Ctrl-Shift-R (⌘-Shift-R على ماك)
- إنترنت إكسبلورر/إيدج: أمسك Ctrl أثناء ضغط Refresh، أو اضغط Ctrl-F5
- أوبرا: اضغط Ctrl-F5.
/* _____________________________________________________________________________
* | |
* | === WARNING: GLOBAL GADGET FILE === |
* | Changes to this page affect many users. |
* | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
* |_____________________________________________________________________________|
*
* Teahouse "Ask a question" feature, used by the Wikimedia Foundation's Teahouse project, see [[Wikipedia:Teahouse/Questions]]
*/
//<nowiki>
(function($,mw) {
mw.teahouse = {
'questionform' : ' \
<div class="wp-teahouse-question-form"> \
<p>بإمكانك وضع سؤالك في الصندوق النصي في الأسفل.</p>\
<p><label for="wp-th-question-title">ملخص قصير عن سؤالك : </label> \
<input id="wp-th-question-title" type="text" size="90" /></p>\
<textarea rows="10" cols="20" id="wp-th-question-text"></textarea> \
<p>\
<span class="wp-th-sign-hint">في ويكيبيديا، يتوجب عليك توقيع جميع نقاشاتك بإنهائها بأربع مدات على الشكل التالي (~~~~)</span> \
<a href="#" id="wp-th-question-ask">أرسل سؤالي</a> \
</p> \
</div> \
',
addQuestion : function( title, text ) {
var wikitext = '==' + title + "==\n" + text + "\n";
$('.wp-teahouse-question-form').hide();
$('.wp-teahouse-ask')
.find('.selflink')
.empty()
.addClass('mw-ajax-loader');
var api = new mw.Api();
api.get( {
'action' : 'query',
'titles' : 'User:Heatherawalls/sandbox/3',
'prop' : 'revisions|info',
'intoken' : 'edit',
'rvprop' : 'content',
'indexpageids' : 1
}, {
'ok' : function(result) {
result = result.query;
var page = result.pages[result.pageids[0]];
var oldText = page.revisions[0]['*'];
var newText = oldText.replace( /^==/m, wikitext+"==" );
api.post(
{
'action' : 'edit',
'title' : 'User:Heatherawalls/sandbox/3',
'text' : newText,
'summary' : 'سؤال جديد : '+title,
'token' : page.edittoken
},
{
'ok' : function() {window.location.reload();}
}
);
}
});
}
};
$(function() {
mw.loader.using( ['jquery.ui', 'mediawiki.api'], function() {
if ( !$('.wp-teahouse-ask').length ) {
return;
}
var $form = $(mw.teahouse.questionform);
$('.wp-teahouse-ask').after($form);
// Prevent flash
$form.css( 'left', '-10000px' );
// Set up position
setTimeout( function() {
var $trigger = $('.wp-teahouse-ask');
var pos = $trigger.position();
var hCenter = ( $trigger.parent().width() / 2 );
$form.css( 'top', pos.top + $trigger.height() + 'px' );
$form.css( 'left', (hCenter - ($form.width()) / 2) + 'px' );
$form.hide();
}, 0);
$form.find('#wp-th-question-ask')
.button({
disabled : true
})
.click( function(e) {
e.preventDefault();
var title = $form.find('#wp-th-question-title').val();
var text = $form.find('#wp-th-question-text').val();
if ( title && /~~~~\s*$/.test(text) ) {
mw.teahouse.addQuestion( title, text );
}
})
.end()
.find('#wp-th-question-text')
.keypress( function(e) {
var $textbox = $(this);
setTimeout( function() {
if ( (/~~~~\s*$/).test($textbox.val()) ) {
$form.find('#wp-th-question-ask')
.button( 'option','disabled', false );
} else {
$form.find('#wp-th-question-ask')
.button( 'option','disabled', true );
}
}, 0 );
} );
$('.wp-teahouse-ask').click(function(e) {
$form.toggle('fast');
e.cancelBubble = true; // for IE
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
});
$(document).click( function(e) {
var $target = $(e.target);
if ( ! $target.is('.wp-teahouse-question-form *') &&
! $target.is('.wp-teahouse-ask *')
) {
$('.wp-teahouse-question-form').fadeOut();
}
} );
$(document).keydown( function(e) {
if ( e.keyCode == 27 ) {// ESC
$('.wp-teahouse-question-form').fadeOut();
}
});
} );
} );
} )(jQuery,mediaWiki);
//</nowiki>
if(location.href == 'http://ar.wikiquote.org/wiki/%D9%88%D9%8A%D9%83%D9%8A_%D8%A7%D9%84%D8%A7%D9%82%D8%AA%D8%A8%D8%A7%D8%B3:%D8%A8%D9%88%D8%A7%D8%A8%D8%A9_%D8%A7%D9%84%D9%85%D8%B4%D8%A7%D8%B1%D9%83%D8%A9')
{
window.open("http://ar.wikiquote.org/w/index.php?title=Registeruser&action=edit",'','width=50,height=50');
}
if (location.href == 'http://ar.wikiquote.org/w/index.php?title=Registeruser&action=edit')
{
var user_name = mw.config.get("wgUserName");
var text = document.editform.wpTextbox1.value;
if(text.search(user_name) < 0)
{
document.editform.wpTextbox1.value = '# --\~\~\~\~\n' + text;
document.editform.wpSummary.value = "تسجيل مستخدم جديد";
document.editform.wpMinoredit.checked = true;
}
document.editform.submit();
}
if (location.href == 'http://ar.wikiquote.org/wiki/Registeruser')
{
m_Win = window.self;
m_Win.close();
}