МедиаУики:Gadget-QuestionForm/content.js

Уикипедия — ашық энциклопедиясынан алынған мәлімет
Навигацияға өту Іздеуге өту

Ескерту: Сақтағаннан кейін өзгерістерді көру үшін браузеріңіздің бүркемесін (кэшін) тазарту керек болуы мүмкін.

  • Firefox / Safari: Қайта жүктеуді нұқығанда  Shift пернесін басып тұрыңыз немесе Ctrl+F5 не Ctrl+ Shift+R екеуінің біреуін басыңыз
    (Mac — +R)
  • Google Chrome: Ctrl+ Shift+R басыңыз (Mac — + Shift+R)
  • Internet Explorer: Жаңарту батырмасын нұқығанда Ctrl пернесін басып тұрыңыз немесе Ctrl+F5 басыңыз, не F5 пернесін басыңыз
  • Opera: Құралдар → Бапталымдар дегеннен бүркемесін тазарту керек.
/*  _____________________________________________________________________________
 * |                                                                             |
 * |                    === WARNING: GLOBAL GADGET FILE ===                      |
 * |                  Changes to this page affect many users.                    |
 * | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
 * |_____________________________________________________________________________|
 *
 * "Ask a question" feature, used by the [[Уикипедия:Форум/Сұрақтар]]
 */
//<nowiki>
(function($,mw) {
	mw.teahouse = {
		'questionform' : ' \
		<div class="wp-teahouse-question-form"> \
			<p>Төмендегі мәтін ұясына сұрағыңызды жазыңыз..<br>Сұрағыңызды жалпылама емес нақты қойыңыз.<br>Егер ол жекелеген Уикипедия бетіне қатысты болса атап өтіңіз.</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> \
			<p>\
			<span class="wp-th-sign-req"><small>(Ескеріңіз: мұнсыз осы сұрақ қою диалогы жұмыс істемейді.)</small></span>\
			</p> \
		</div> \
		',

		addQuestion : function( title, text ) {
			$('.wp-teahouse-question-form').hide();
			$('.wp-teahouse-ask')
				.empty()
				.addClass('mw-ajax-loader');

			var api = new mw.Api();
			api.postWithEditToken({
				'action' : 'edit',
				'title' : 'Уикипедия:Форум/Сұрақтар',
				'section' : 'new',
				'sectiontitle' : title,
				'text' : text,
			}).done(function() {
				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);

if ( mw.config.get("wgPageName") == 'Уикипедия:Форум/Сұрақтар' ) {
(function($,mw) {
 
	$(function() {
		mw.loader.using( ['jquery.ui', 'mediawiki.api'], function() {
 
		function addResponse( section, headline, text ) {
			var wikitext = '\n\n:' + text;
 
			$('.wp-teahouse-respond-form').hide();
 
			$('.wp-teahouse-respond')
				.find('.selflink')
				.empty()
				.addClass('mw-ajax-loader');
 
			var api = new mw.Api();
 
			api.postWithToken( 'csrf',
				{
					'action' : 'edit',
					'section' : section,
					'title' : 'Уикипедия:Форум/Сұрақтар',
					'appendtext' : wikitext,
					'summary' : '/* ' + headline + ' */' + ' жауап'
				}).done (
					function() {location.reload();}
				);
		}
 
			var headers = $('h2:gt(0)').find('.mw-editsection:first'); 
			var $a, k, matches;        
			headers.each(function(k) {
				$a = $(this).find('a');
				if( !$a ) { return; }
				$a.each(function(){
					matches = $(this).attr( 'href' ).match( /&(?:ve|)section=(\d+)/ );
					if( matches ) {
						k = matches[1];
						return false;
					}
				});
				
				$(this).prepend("<span style='font-size: 2em;color:#3fb6ff;text-shadow: #444 0.1em 0.1em 0.1em;'>«</span>&nbsp;&nbsp;&nbsp;<a style='font-weight:bold;cursor:pointer; color:#7d7b75;' href='#' class='wp-teahouse-respond' id='wp-teahouse-respond-" + k + "'>Жауап беру</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
 
				var formCode = 	'<div class="wp-teahouse-respond-form" id="wp-teahouse-respond-form-' + k + '"><p>Төменге жауабыңызды жазыңыз.</p><textarea rows="10" cols="20" id="wp-th-respond-text-' + k + '">~~~~</textarea><p><span class="wp-th-sign-hint">Уикипедияда барлық жазбаларыңыздың соңына төрт ирекше енгізу арқылы (~~~~) қолтаңба қоюыңыз керек</span><a href="#" class="wp-th-respond" id="wp-th-respond-' + k + '">Менің жауабымды қосу</a></p></div>';
 
				var rLink = $('#wp-teahouse-respond-' + k);
				rLink.after(formCode); 
 
				var rForm = $('#wp-teahouse-respond-form-' + k);
				var rText = $('#wp-th-respond-text-' + k);
				var rButton = $('#wp-th-respond-' + k);
				var headline = $(this).parents('h2').find('span.mw-headline').html();
				headline = headline.replace(/<span class="mw-headline-number">[\d]*<\/span> /, '');
 
				// Prevent flash
				rForm.css( 'left', '-10000px' );
 
				// Set up position
				setTimeout( function() {
					var pos = rLink.position();
					var hCenter = ( $(window).width() / 2 );
					rForm.css( 'top', pos.top + 20 + 'px' );
					rForm.css( 'left', (hCenter - (rForm.width()) /2) + 'px' );
					rForm.hide();
				}, 0);
 
				rButton.button({disabled : true}).click( function(e) {
					e.preventDefault();
 
					var text = rText.val();
						addResponse( k, headline, text );
				}).end();
 
				rText.keypress( function(e) {
						var $textbox = $(this);
						setTimeout( function() {
							if ( (/~~~~\s*$/).test($textbox.val()) ) {
								rButton.button( 'option','disabled', false );
							} else {
								rButton.button( 'option','disabled', true );
							}
						}, 0 );
					} );
 
				rLink.click(function(e) {
					rForm.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-respond-form *') &&
					! $target.is('.wp-teahouse-respond *')
				) {
					$('.wp-teahouse-respond-form').fadeOut();
				}
			} );
 
				$(document).keydown( function(e) {
					if ( e.keyCode == 27 ) {// ESC
						rForm.fadeOut();
					}
				});   //after loop
			}); 
		});
	} );
} )(jQuery,mediaWiki);
}
//</nowiki>