प्रयोगकर्ता:Odisha1/cs.js

विकिपिडिया, एक स्वतन्त्र विश्वकोशबाट
सूचना: सम्पादनहरू प्रकाशित गरेपछि, परिवर्तनहरू हेर्नको लागि तपाईंले आफ्नो ब्राउजरको क्यासलाई बाइपास गर्नुपर्छ। गुगल क्रोम, फायरफक्स, माइक्रोसफ्ट एजसफारी: Shift कुञ्जी थिचिराखेर रिलोड उपकरणपट्टी बटनमा थिच्नुहोस्।
//<nowiki>
(function($,mw) {
	mw.chatsabha = {
		'questionform' : ' \
		<div class="wp-chatsabha-question-form"> \
			<p>You can put your question in the textbox below.</p>\
			<p><label for="wp-cs-question-title">Short summary of your question: </label> \
			<input id="wp-cs-question-title" type="text" size="90" /></p>\
			<textarea rows="10" cols="20" id="wp-cs-question-text"></textarea> \
			<p>\
			<span class="wp-cs-sign-hint"></span> \
			<a href="#" id="wp-cs-question-ask">Ask my question</a> \
			</p> \
		</div> \
		',

		addQuestion : function( title, text ) {
			var wikitext = '==' + title + "==\n" + text +'~~~~' + "\n";

			$('.wp-chatsabha-question-form');

			$('.wp-chatsabha-ask')
				.find('.selflink')
				.empty()
				.addClass('mw-ajax-loader');

			var api = new mw.Api();

			api.get( {
				'action' : 'query',
				'titles' : 'प्रयोगकर्ता:Subha_WMF/Q/Qn',
				'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' : 'प्रयोगकर्ता:Subha_WMF/Q/Qn',
							'text' : newText,
							'summary' : 'New question: '+title,
							'token' : page.edittoken
						},
						{
							'ok' : function() {window.location.reload();}
						}
					);
				}
			});
		}
	};

	$(function() {
		mw.loader.using( ['jquery.ui', 'mediawiki.api'], function() {
			if ( !$('.wp-chatsabha-ask').length ) {
				return;
			}

			var $form = $(mw.chatsabha.questionform);
			$('.wp-chatsabha-ask').after($form);

			// Prevent flash
			$form.css( 'left', '-10000px' );
 
			// Set up position
			setTimeout( function() {
				var $trigger = $('.wp-chatsabha-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' );
			}, 0);
 
			$form.find('#wp-cs-question-ask')
				.button({
					disabled : true
				})
				.click( function(e) {
					e.preventDefault();
 
					var title = $form.find('#wp-cs-question-title').val();
					var text = $form.find('#wp-cs-question-text').val();
 
					if ( title && / \s*$/.test(text) ) {
						mw.chatsabha.addQuestion( title, text );
					}
				})
				.end()
				.find('#wp-cs-question-text')
					.keypress( function(e) {
						var $textbox = $(this);
						setTimeout( function() {
							if ( (/ \s*$/).test($textbox.val()) ) {
								$form.find('#wp-cs-question-ask')
									.button( 'option','disabled', false );
							} else {
								$form.find('#wp-cs-question-ask')
									.button( 'option','disabled', true );
							}
						}, 0 );
					} );
 
			$('.wp-chatsabha-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-chatsabha-question-form *') &&
					! $target.is('.wp-chatsabha-ask *')
				) {
					$('.wp-chatsabha-question-form');
				}
			} );
 
			$(document).keydown( function(e) {
				if ( e.keyCode == 27 ) {// ESC
					$('.wp-chatsabha-question-form');
				}
			});
		} );
	} );
} )(jQuery,mediaWiki);
//</nowiki>